larsimmisch/arduino-- — Issue #1: micros() problems
Author: larsimmisch
Created: 2011-12-29 19:50:52+00:00
State: open

I'm beginning to suspect that the Arduino::micros function (which is pretty much the original) isn't behaving vey well.

Simplified:

```c
static uint32_t micros()
{
uint32_t m;
uint16_t t;
uint8_t oldSREG = SREG;

cli();
t = TCNT0;

if ((TIFR & _BV(TOV0)) && (t == 0))
t = 256;

m = timer0_overflow_count;
SREG = oldSREG;

return ((m << 8) + t) * (64 / (F_CPU / 1000000L));
}
```

Once m reaches 2**24, the value wraps around to t * 4 (assuming a 16MHz clock).

And timer0_overflow_count itself wraps around at 2**32, so the function resets twice over the value range 2**32