AVRTools
A Library for the AVR ATmega328 and ATmega2560 Microcontrollers
Functions
SimpleDelays.h File Reference

This file provides simple delay functions that do not involve timers or interrupts. These functions simply execute a series of nested loops with known and precise timing. More...

#include <stdint.h>
Include dependency graph for SimpleDelays.h:

Go to the source code of this file.

Functions

void delayQuartersOfMicroSeconds (uint16_t nbrOfQuartersOfMicroSeconds)
 Delay a given number of quarter microseconds. Due to function call overhead, at 16 MHz the smallest possible delay is just under 6 quarter microseconds (~1.5 microseconds). Delays of 7 quarter microseconds or greater are reasonably accurate. At 8 MHz the smallest possible delay is just under 12 quarter microseconds (~3 microseconds). Delays of 13 quarter microseconds or greater are reasonably accurate. More...
 
void delayWholeMilliSeconds (uint8_t nbrOfMilliSeconds)
 Delay a given number of milliseconds. Despite function call overhead, this function is accurate within a few hundreds of microseconds. More...
 
void delayTenthsOfSeconds (uint8_t nbrOfTenthsOfSeconds)
 Delay a given number of tenths of a seconds. Despite function call overhead, this function is accurate within a few hundreds of microseconds. More...
 

Detailed Description

This file provides simple delay functions that do not involve timers or interrupts. These functions simply execute a series of nested loops with known and precise timing.

For precision, these functions are all implemented directly in assembler.

Note
These functions are implemented for (and automatically adjust to) either an 8 MHz, 12 MHz, or a 16 MHz clock cycle.

Function Documentation

§ delayQuartersOfMicroSeconds()

void delayQuartersOfMicroSeconds ( uint16_t  nbrOfQuartersOfMicroSeconds)

Delay a given number of quarter microseconds. Due to function call overhead, at 16 MHz the smallest possible delay is just under 6 quarter microseconds (~1.5 microseconds). Delays of 7 quarter microseconds or greater are reasonably accurate. At 8 MHz the smallest possible delay is just under 12 quarter microseconds (~3 microseconds). Delays of 13 quarter microseconds or greater are reasonably accurate.

At 16 MHz delays of less than 7 quarter microseconds produce a delay of just under 6 quarter microseconds (~1.5 microseconds). At 8 MHz delays of less than 12 quarter microseconds produce a delay of just under 12 quarter microseconds (~3 microseconds).

The maximum delay is 65535 quarter microseconds (equal to 16,383.75 microseconds, or about 16.4 milliseconds).

  • nbrOfQuartersOfMicroSeconds the number of quarter microseconds to delay. For 16 MHz clocks, arguments less than 7 quarter microseconds for 16 MHz clocks all produce delays of just under 6 quarter microseconds. For 8 MHz clocks, arguments less than 13 quarter microseconds all produce delays of about 12 quarter microseconds.
Note
This delay function is only accurate if interrupts are disabled. If interrupts are enabled, the delays will be at least as long as requested, but may actually be longer. If accurate delays are desired, disable interrupts before calling this function (remember to enable interrupts afterwards).
This function only works for CPU clocks running at either 8 MHz, 12 MHz, or 16 MHz.

For precision, this function is implemented directly in assembler.

§ delayTenthsOfSeconds()

void delayTenthsOfSeconds ( uint8_t  nbrOfTenthsOfSeconds)

Delay a given number of tenths of a seconds. Despite function call overhead, this function is accurate within a few hundreds of microseconds.

  • nbrOfTenthsOfSeconds the number of tenths of seconds to delay. The maximum delay is 256 tenths of a second or 25.6 seconds (pass 0 for a delay of 256 tenths of a second).
Note
This delay function is only accurate if interrupts are disabled. If interrupts are enabled, the delays will be at least as long as requested, but may actually be longer. If accurate delays are desired, disable interrupts before calling this function (remember to enable interrupts afterwards).
This function only works for CPU clocks running at either 8 MHz, 12 MHz, or 16 MHz.

For precision, this function is implemented directly in assembler.

§ delayWholeMilliSeconds()

void delayWholeMilliSeconds ( uint8_t  nbrOfMilliSeconds)

Delay a given number of milliseconds. Despite function call overhead, this function is accurate within a few hundreds of microseconds.

  • nbrOfMilliSeconds the number of milliseconds to delay. The maximum delay is 256 milliseconds (pass 0 for a delay of 256 milliseconds).
Note
This delay function is only accurate if interrupts are disabled. If interrupts are enabled, the delays will be at least as long as requested, but may actually be longer. If accurate delays are desired, disable interrupts before calling this function (remember to enable interrupts afterwards).
This function only works for CPU clocks running at either 8 MHz, 12 MHz, or 16 MHz.

For precision, this function is implemented directly in assembler.