folpindo / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

millis() and micros() return rollover state #959

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When millis() and micros() roll over, there is currently no way to let your 
program notice, other than storing it in a variable and comparing every loop, 
which uses up precious clock cycles.  You could simply have a hardware variable 
that increments every time millis() rolls over, and another one that increments 
every time micros() rolls over.

Original issue reported on code.google.com by xolr...@gmail.com on 17 Jun 2012 at 6:50

GoogleCodeExporter commented 9 years ago
This is often discussed in the forums.  "correct" code should not need to 
detect when these counters overflow, because unsigned math still gives correct 
results for time differences.  Also, tracking overflows would add significant 
complexity to the timer ISR (essentially the same overhead you complain about 
adding to loop, except that it would happen every clock tick, for all sketches, 
whether needed or not (and you'd still need to check the result in loop() as 
well.))

Original comment by wes...@gmail.com on 6 Aug 2012 at 9:06

GoogleCodeExporter commented 9 years ago
For the reasons that westfw discusses.

Original comment by dmel...@gmail.com on 7 Aug 2012 at 8:36

GoogleCodeExporter commented 9 years ago
Understood.  I wasn't sure if there was a simpler hardware way to do this or 
not.

Original comment by nrb...@crimson.ua.edu on 7 Aug 2012 at 9:37