Closed GoogleCodeExporter closed 9 years ago
unsigned long micros() {
unsigned long m;
uint8_t oldSREG = SREG, t;
cli();
m = timer0_overflow_count;
t = TCNT0;
#ifdef TIFR0
if ((TIFR0 & _BV(TOV0)) && (t < 255))
m++;
#else
if ((TIFR & _BV(TOV0)) && (t < 255))
m++;
#endif
SREG = oldSREG;
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
}
Original comment by dmel...@gmail.com
on 15 Aug 2009 at 8:51
I've hit this bug in my code when calling micros from an ISR. Since interrupts
have
been disabled awhile inside the ISR, it is possible that TOV0 is set and TCNT0
has
been incremented past 0 (since interrupts have been disabled for far longer
than the
cli() call within micros). In this case, the micros call returns a value that
is
~1msec less than the previous call; confusing timings from one call to the next.
I had made a similar fix that solved the problem for me.
I encourage the powers to be to include this fix in the next release.
Original comment by dangyogi@gmail.com
on 18 Sep 2009 at 1:33
Original comment by dmel...@gmail.com
on 18 Dec 2009 at 5:44
Original issue reported on code.google.com by
dmel...@gmail.com
on 14 Jul 2009 at 9:25