Hi,
I have been trying a while ago to use the most precise timer in microseconds you can use with an atmega328P running at 14.7456MHz programmed with C.
But I haven't succeed yet...
I got this code, but it is not working at all, it is not taking the time I need. Does someone knows what is going on?
volatile double timer; volatile double time; void realtimeclock_setup() { TCCR0A |= (1<<WGM00); TCCR0B |= (1<<CS00); //No prescaling // set TOP to 9 // because it counts 0, 1, 2, ... 8..9 OCR0A = 9; // enable interrupt on compare event // (14745600 / 10 = 1474560 per second) TIMSK0 |= (1<<OCIE0A); } ISR(TIMER0_COMPA_vect) { timer++; time = timer / 1474560 * 1000000; //Change 1474560 counts per sec to microsecodns }
What am I missing here?
Thanks in advance.