.TH ": Basic busy-wait delay loops" 3avr "Wed Jun 4 2014" "Version 1.8.0svn" "avr-libc" \" -*- nroff -*- .ad l .nh .SH NAME : Basic busy-wait delay loops \- .SS "Functions" .in +1c .ti -1c .RI "void \fB_delay_loop_1\fP (\fBuint8_t\fP __count)" .br .ti -1c .RI "void \fB_delay_loop_2\fP (\fBuint16_t\fP __count)" .br .in -1c .SH "Detailed Description" .PP .PP .nf #include .fi .PP .PP The functions in this header file implement simple delay loops that perform a busy-waiting\&. They are typically used to facilitate short delays in the program execution\&. They are implemented as count-down loops with a well-known CPU cycle count per loop iteration\&. As such, no other processing can occur simultaneously\&. It should be kept in mind that the functions described here do not disable interrupts\&. .PP In general, for long delays, the use of hardware timers is much preferrable, as they free the CPU, and allow for concurrent processing of other events while the timer is running\&. However, in particular for very short delays, the overhead of setting up a hardware timer is too much compared to the overall delay time\&. .PP Two inline functions are provided for the actual delay algorithms\&. .SH "Function Documentation" .PP .SS "void _delay_loop_1 (\fBuint8_t\fP__count)" Delay loop using an 8-bit counter \fC__count\fP, so up to 256 iterations are possible\&. (The value 256 would have to be passed as 0\&.) The loop executes three CPU cycles per iteration, not including the overhead the compiler needs to setup the counter register\&. .PP Thus, at a CPU speed of 1 MHz, delays of up to 768 microseconds can be achieved\&. .SS "void _delay_loop_2 (\fBuint16_t\fP__count)" Delay loop using a 16-bit counter \fC__count\fP, so up to 65536 iterations are possible\&. (The value 65536 would have to be passed as 0\&.) The loop executes four CPU cycles per iteration, not including the overhead the compiler requires to setup the counter register pair\&. .PP Thus, at a CPU speed of 1 MHz, delays of up to about 262\&.1 milliseconds can be achieved\&. .SH "Author" .PP Generated automatically by Doxygen for avr-libc from the source code\&.