Why does the Arduino use an interrupt every 1.024 ms in a millisecond function?

I am using a time counter on my atmega 328p. I looked at the implementation of the arduino millis function, and I'm a little confused why they use a timer overflow interrupt that runs every 1,024 ms (freg = 16MHz, 64 prescaling), when they can use the Output Match Match Interrupt, which can be set to trigger exactly every 1 ms (OCR0A = 249). Is there any advantage to using the Overflow Interupt timer and some corrections for the counted ms compared to the Output Match Match transition, which is executed exactly every 1 ms? Or why do they use it?

+4
source share
1 answer

The TCNT counter value is used to calculate microseconds outside the interrupt. Using a comparison match to determine the TOP value will lead to an exact interrupt, but complicates the calculation of thinner micros, since TCNT reset. Using comparison comparisons for non-TOP values ​​(for generating PWMs) does not generate a 1 ms periodic interrupt.

I personally use as the second timer to select the TOP value defined by the OCRxA register.

+1
source

Source: https://habr.com/ru/post/1545360/


All Articles