From 7ea4cb39bd8b4bf57c43acc50310bcb7402e3552 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 18 Dec 2009 17:44:08 +0000 Subject: Fixing bug in calling micros() from interrupts: http://code.google.com/p/arduino/issues/detail?id=55 --- cores/arduino/wiring.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'cores') 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()); -- cgit v1.2.3-18-g5258