I am implementing a time counter on my atmega 328p. I looked on the implementation of arduino millis function and I am bit confused, why they use Timer Overflow Interrupt which is executed every 1.024 ms (freg = 16MHz, 64 prescaling), when they could use Output Compare Match Interrupt which can be set up to trigger exactly every 1ms (OCR0A = 249). Is there any advantage to use Timer Overflow Interupt and do some corrections to counted ms over Output Compare Match interupt that is executed exactly every 1ms? Or why they are using it?
Asked
Active
Viewed 738 times
1 Answers
1
The counter value TCNT is used for calculation of microseconds beyond interrupt. Using compare match for defining TOP value would generate exact interrupt but complicates finer micros calculation as TCNT is reset. Using compare match for non TOP value (for PWM generation) does not generate periodic 1ms interrupt.
I'm personally using as second timer for sampling TOP value defined by OCRxA register.

TMa
- 723
- 1
- 5
- 14