diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2009-12-18 17:44:08 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2009-12-18 17:44:08 +0000 |
commit | 7ea4cb39bd8b4bf57c43acc50310bcb7402e3552 (patch) | |
tree | 6cca76f9aa6596de6ba7e06008020d30e0fe743b /cores | |
parent | 78a3d76f6cd1a70652f31904009f06c5038270de (diff) |
Fixing bug in calling micros() from interrupts: http://code.google.com/p/arduino/issues/detail?id=55
Diffstat (limited to 'cores')
-rwxr-xr-x | cores/arduino/wiring.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/cores/arduino/wiring.c b/cores/arduino/wiring.c index 7d3e611..858ab72 100755 --- a/cores/arduino/wiring.c +++ b/cores/arduino/wiring.c @@ -75,21 +75,21 @@ unsigned long millis() } unsigned long micros() { - unsigned long m, t; - uint8_t oldSREG = SREG; + unsigned long m; + uint8_t oldSREG = SREG, t; - cli(); + cli(); + m = timer0_overflow_count; t = TCNT0; #ifdef TIFR0 - if ((TIFR0 & _BV(TOV0)) && (t == 0)) - t = 256; + if ((TIFR0 & _BV(TOV0)) && (t < 255)) + m++; #else - if ((TIFR & _BV(TOV0)) && (t == 0)) - t = 256; + if ((TIFR & _BV(TOV0)) && (t < 255)) + m++; #endif - m = timer0_overflow_count; SREG = oldSREG; return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); |