millis() and micros() rollover limits for elapsed-time measurement on AVR boards
0 reputation · 09 Apr 2026, 12:58 UTC
Goal is to measure the execution time of a periodic workload on a continuously running Arduino sketch and use the measurement to decide whether optimization is warranted.
The timing base is millis() as an unsigned 32-bit counter with ~49.7 day rollover, and micros() with ~71.6 minute rollover. Elapsed time is intended to be computed with unsigned subtraction to remain correct across overflow. On classic AVR cores the counters are driven by Timer0 overflow interrupts, so periods with interrupts disabled cause the counters to lose time. Resolution and timer source differ across AVR, SAMD and third-party cores, and storing the values in signed types changes overflow behavior.
With those limits, the choice of measurement base for short intervals on a long-running device is unclear.
Which documented limits apply to measuring sub-millisecond intervals with micros() on 16 MHz AVR boards? Does the unsigned subtraction idiom remain correct if the measurement window spans a micros() rollover? How does a bounded period with interrupts disabled affect reported elapsed time from millis() versus micros()?