Delays

The package AVR.Wait provides two functions allowing delays in the order of a few cycles.

procedure Wait_3_Cycles (Count : Unsigned_8);  -- can wait up to 2^8 x 3 cycles
procedure Wait_4_Cycles (Count : Unsigned_16); -- can wait up to 2^16 x 4 cycles

If you set some processor speed you can also use

delay 0.1;

on the primary processors. In order to obtain accurate timing the compiler has to know at what speed the processor works. That is possible if you provide that information to the procedure that calculates the timing.

The generic function AVR.Wait.Generic_Wait_USecs takes the processor speed in Hertz and the microseconds (10E-6 seconds) to be delayed as generic parameters. It internally calculates at compile time the number of cycles to wait. It leads to only a few instructions at assembler level.

Example of generic instantiation from the 1-Wire package:

procedure Wait_70us is
  new Generic_Wait_Usecs (Crystal_Hertz => 8_000_000,
                          Micro_Seconds => 70);
pragma Inline_Always (Wait_70us);

Related

Wiki: Examples
Wiki: Home