millis() function for Atmega8

Thread Starter

aditya369007

Joined Jul 24, 2014
15
Hi
I wanted to know if there was any code for ATmega8 that performs the same function as millis() in arduino ?
i.e lines of code that will enable me to know the time in milliseconds since the controller was turned on.
 

Shagas

Joined May 13, 2013
804
Perhaps you can look into how it's implemented in the arduino code.
Perhaps if you don't need the 16bit timer then you could set it up with a prescalar and make it interrupt on overflow and increment a *volatile* variable. Then you could just calculate the time that passed by
seeing how many ticks you have. I think arduino does something similar. Also , if you are using arduino functions that use timers then your millis() function will be slightly imprecise which you might or might not mind.

So if you are clocking at 1Mhz , you could set up your timer with no prescalar to interrupt at OCRXY = 1000; And in the interrupt routine you can increment a *volatile counter
which means that your interrupt will increment a variable every millisecond
 
Last edited:
Top