• 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0



Allthough "Busy Wait" is somewhat wasting CPU-Power, I sometimes find it the most efficient way for creating delays.

The include file "delay_x.h" provides four macros:

_delay_ns(double ns)
_delay_us(double us)
_delay_ms(double ms)
_delay_s(double s)
_delay_cycles(double c)

===> The generated delays:

1. are cycle accurate
2. are code size optimized (NOPs,byte loops, 16bit loops, 32bit loops)
3. can range from 1 cycle upto 536 seconds (e.g. @8MHz)

Required Environment:
1. The arguments have to be compile time constants.
2. Use of compile optimization (2,3,s)
3. F_CPU must be defined with the clock frequency


Together with "delay_x.h" comes a test program "test.c" that I used for verifying the generated delays with Timer1 of an AT90S2313.