This code implements arduino-like millis() functions, written in clear C and tested on atmega328.
Sets up 8bit timer0 to CTC mode, 1ms interval and turns it on.
Turn on/off timer via setting prescaler.
Set elapsed time to 0
Returns time in millisecounds since init or reset call. Also callable by alias millis()
.
Returns time in microsecounds since init or reset call. Also callable by alias micros()
.
This function uses timer register TIFRx to get relatively high accouracy without spamming with interrupts.
Lowest accouracy is something like 8us, will depend on F_CPU like this: 1/((F_CPU/1000/64)-1)
Copied from arduino source.
Returns time in secounds since init or reset call.