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

Include this file to use the functions that instantiate and access a system clock that counts elapsed milliseconds. More...

Go to the source code of this file.

Functions

void initSystemClock ()
 This function initializes a system clock that tracks elapsed milliseconds. More...
 
void delayMicroseconds (unsigned int us)
 Delay a certain number of microseconds. More...
 
void delayMilliseconds (unsigned long ms)
 Delay a certain number of milliseconds. More...
 
void delay (unsigned long ms)
 Delay a certain number of milliseconds. More...
 
unsigned long micros ()
 Return the number of elasped microseconds since the system clock was turned on. More...
 
unsigned long millis ()
 Return the number of elasped milliseconds since the system clock was turned on. More...
 

Detailed Description

Include this file to use the functions that instantiate and access a system clock that counts elapsed milliseconds.

To use these functions, include SystemClock.h in your source code and link against SystemClock.cpp.

Note
Linking against SystemClock.cpp installs a interrupt function on timer0. This interrupt routine is installed regardless of whether the system clock is actually initialized or not. If you have other uses for timer0, do not use SystemClock functions and do not link against SystemClock.cpp.

Function Documentation

§ delay()

void delay ( unsigned long  ms)
inline

Delay a certain number of milliseconds.

This inline function is a synonym for delayMilliseconds(); it is provided for compatibility with the standard Arduino library.

  • m the number of milliseconds to delay.

§ delayMicroseconds()

void delayMicroseconds ( unsigned int  us)

Delay a certain number of microseconds.

  • us the number of microseconds to delay.
Note
This function only works for CPU clocks running at either 8 MHz, 12 MHz, or 16 MHz.

§ delayMilliseconds()

void delayMilliseconds ( unsigned long  ms)

Delay a certain number of milliseconds.

  • m the number of milliseconds to delay.

§ initSystemClock()

void initSystemClock ( )

This function initializes a system clock that tracks elapsed milliseconds.

The system clock uses timer0, so you cannot use timer0 for other functions if you use the system clock functionality.

Note
Linking against SystemClock.cpp installs a interrupt function on timer0. This interrupt routine is installed regardless of whether the system clock is actually initialized or not. If you have other uses for timer0, do not use SystemClock functions and do not link against SystemClock.cpp.

§ micros()

unsigned long micros ( )

Return the number of elasped microseconds since the system clock was turned on.

The microsecond count will overflow back to zero in approximately 70 minutes.

Returns
the number of elapsed microseconds.

§ millis()

unsigned long millis ( )

Return the number of elasped milliseconds since the system clock was turned on.

Returns
the number of elapsed milliseconds.