Skip to content

Just like the millis() function in Arduino, this function returns the time in milliseconds since the program has started.

License

Notifications You must be signed in to change notification settings

monoclecat/avr-millis-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

avr-millis-function

Just like the millis() function in Arduino, this function returns the time in milliseconds since the program started.

This function has only been tested on the atmega328p, but may work on many other AVRs as well.

Implementing this function is easy - take a look at the example:

  1. First you must initiate the clock with init_millis()

  2. After calling init_millis(), call sei() to enable global interrupts

  3. Use millis() whenever you like to get the time in milliseconds since the program started

Complications that may arise: A problem I faced was that I got this error messsage when compiling:

/usr/local/CrossPack-AVR-20131216/avr/include/millis.c: In function 'millis':
/usr/local/CrossPack-AVR-20131216/avr/include/millis.c:49:3: error: 'for' loop initial declarations are only allowed in C99 mode
ATOMIC_BLOCK(ATOMIC_FORCEON) {
    ^
/usr/local/CrossPack-AVR-20131216/avr/include/millis.c:49:3: note: use option -std=c99 or -std=gnu99 to compile your code
make: *** [main.o] Error 1

The error is nicely explained here and can be fixed by adding -std=c99 or -std=gnu99 to the command avr-gcc when compiling your code.

For any questions write me an email at: [email protected]

About

Just like the millis() function in Arduino, this function returns the time in milliseconds since the program has started.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages