\hypertarget{group__util__delay__basic}{}\doxysubsection{$<$util/delay\+\_\+basic.h$>$\+: Basic busy-\/wait delay loops}
\label{group__util__delay__basic}\index{$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops@{$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops}}
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \mbox{\hyperlink{group__util__delay__basic_ga4e3957917c4c447d0f9166dac881b4e3}{\+\_\+delay\+\_\+loop\+\_\+1}} (\mbox{\hyperlink{group__avr__stdint_gaba7bc1797add20fe3efdf37ced1182c5}{uint8\+\_\+t}} \+\_\+\+\_\+count)
\item 
void \mbox{\hyperlink{group__util__delay__basic_ga74a94fec42bac9f1ff31fd443d419a6a}{\+\_\+delay\+\_\+loop\+\_\+2}} (\mbox{\hyperlink{group__avr__stdint_ga1f1825b69244eb3ad2c7165ddc99c956}{uint16\+\_\+t}} \+\_\+\+\_\+count)
\end{DoxyCompactItemize}


\doxysubsubsection{Detailed Description}

\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <\mbox{\hyperlink{delay__basic_8h}{util/delay\_basic.h}}>}}
\end{DoxyCode}


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 C\+PU 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.

In general, for long delays, the use of hardware timers is much preferrable, as they free the C\+PU, 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.

Two inline functions are provided for the actual delay algorithms. 

\doxysubsubsection{Function Documentation}
\mbox{\Hypertarget{group__util__delay__basic_ga4e3957917c4c447d0f9166dac881b4e3}\label{group__util__delay__basic_ga4e3957917c4c447d0f9166dac881b4e3}} 
\index{$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops@{$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops}!\_delay\_loop\_1@{\_delay\_loop\_1}}
\index{\_delay\_loop\_1@{\_delay\_loop\_1}!$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops@{$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops}}
\doxyparagraph{\texorpdfstring{\_delay\_loop\_1()}{\_delay\_loop\_1()}}
{\footnotesize\ttfamily void \+\_\+delay\+\_\+loop\+\_\+1 (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__avr__stdint_gaba7bc1797add20fe3efdf37ced1182c5}{uint8\+\_\+t}}}]{\+\_\+\+\_\+count }\end{DoxyParamCaption})}

Delay loop using an 8-\/bit counter {\ttfamily \+\_\+\+\_\+count}, so up to 256 iterations are possible. (The value 256 would have to be passed as 0.) The loop executes three C\+PU cycles per iteration, not including the overhead the compiler needs to setup the counter register.

Thus, at a C\+PU speed of 1 M\+Hz, delays of up to 768 microseconds can be achieved. \mbox{\Hypertarget{group__util__delay__basic_ga74a94fec42bac9f1ff31fd443d419a6a}\label{group__util__delay__basic_ga74a94fec42bac9f1ff31fd443d419a6a}} 
\index{$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops@{$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops}!\_delay\_loop\_2@{\_delay\_loop\_2}}
\index{\_delay\_loop\_2@{\_delay\_loop\_2}!$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops@{$<$util/delay\_basic.h$>$: Basic busy-\/wait delay loops}}
\doxyparagraph{\texorpdfstring{\_delay\_loop\_2()}{\_delay\_loop\_2()}}
{\footnotesize\ttfamily void \+\_\+delay\+\_\+loop\+\_\+2 (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__avr__stdint_ga1f1825b69244eb3ad2c7165ddc99c956}{uint16\+\_\+t}}}]{\+\_\+\+\_\+count }\end{DoxyParamCaption})}

Delay loop using a 16-\/bit counter {\ttfamily \+\_\+\+\_\+count}, so up to 65536 iterations are possible. (The value 65536 would have to be passed as 0.) The loop executes four C\+PU cycles per iteration, not including the overhead the compiler requires to setup the counter register pair.

Thus, at a C\+PU speed of 1 M\+Hz, delays of up to about 262.\+1 milliseconds can be achieved. 