From 0822a93466de4cf2654542335070709ef14d6702 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Sat, 3 Dec 2011 21:54:57 +0100 Subject: [PATCH] Fix read access for 16bit timer counter registers. To get meaningful reading, we must read the low byte first, so the MCU saves the correct high byte value in the counter's temporary register (see eg. section 14.2 of the 32u4 datasheet). --- framework/cores/AVR8Bit/WHardwareTimer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/cores/AVR8Bit/WHardwareTimer.cpp b/framework/cores/AVR8Bit/WHardwareTimer.cpp index 441bae4..c3f15ba 100644 --- a/framework/cores/AVR8Bit/WHardwareTimer.cpp +++ b/framework/cores/AVR8Bit/WHardwareTimer.cpp @@ -781,9 +781,9 @@ uint16_t HardwareTimer::getCounter(void) uint16_t value = 0; uint8_t oldSREG = SREG; cli(); + value += *_tcntnl; if (_tcntnh != NULL) value = *_tcntnh << 8; - value += *_tcntnl; SREG = oldSREG; return value;