# Handling overflow in micros() [duplicate]

Returns the number of microseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 70 minutes.

How do I handle the cases where the measured interval is:

1. Less than 70 minutes (but may experience an overflow)
• Is there a way to zero the register that `micros()` reads from before the measurment?
2. More than 70 minutes, and may experience multiple overflows
• use in conjunction with `millis` - millis reset after 50 days Feb 8 '19 at 5:29
• @jsotola - how would that handle "multiple overflows" :p - I think OP wants to count the overflows, not just handle them :p Feb 8 '19 at 5:44
• I want to close this question. The answer is: do not try to “handle” the millis rollover (which also applies to micros). That is the answer in the link by @jsotola. Tom Hale is answering his own question but that answer has no solution.
– Jot
Feb 8 '19 at 9:04
• @Jot, given answering one's own questions is encouraged in SE, what do you mean by the answer having no solution, given I've addressed each of the two parts? Perhaps your comment would be better suited under the answer itself? Feb 8 '19 at 13:11

1. For less than 70 minute intervals, this forum post says:

[N]ever compare values you get from millis() or micros() or add delays to those values, because that will fail at the overflow.

Always substract the current time from the starting time and compare the difference against the expected period so that the subtraction will take care of the overflow for you.

Zeroing `micros()` is probably a bad idea as unknown library functions rely on it, but here's how to do it for testing purposes.

2. Use `micros64()` with 64-bit precision (`micros()` is 32-bit), see here.

`micros64()` must called at least once every 70min time period.

• The answer is given twice: arduino.stackexchange.com/questions/12587/… "do not try to “handle” the millis rollover". Zeroing causes even more problems. The micros64() is good in some situations, but it needs to be updated and the second part of your question is when it is more than 70 minutes (you didn't tell if micros was called during that time). If you want micro-second accuracy during a few hours, that makes no sense, the crystal or resonator is not that accurate. What is your project? Is this a XY-problem? xyproblem.info
– Jot
Feb 8 '19 at 18:49
• @Jot: While the answer may be given twice in the link you show, I don't see the relevance to my answer. Thanks: I've updated the 2nd part say that `micros64()` must be called at least every 70 minutes. Feb 11 '19 at 2:53