From 1c6f9a9b5e9f1896a6c3d1faa895af74b6c7e3e1 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 2 Sep 2010 22:29:36 -0400 Subject: Off-by-one in timer setPeriod() function Thanks CarlO! --- wirish/HardwareTimer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wirish/HardwareTimer.cpp') diff --git a/wirish/HardwareTimer.cpp b/wirish/HardwareTimer.cpp index 64fa222..f55e6b0 100644 --- a/wirish/HardwareTimer.cpp +++ b/wirish/HardwareTimer.cpp @@ -77,8 +77,8 @@ uint16 HardwareTimer::setPeriod(uint32 microseconds) { // With a prescale factor of 1, there are 72counts/ms uint16 ps = ((microseconds*72)/65536) + 1; setPrescaleFactor(ps); - // Find this overflow will always be less than 65536 - setOverflow((microseconds*72)/ps); + // Finally, this overflow will always be less than 65536 + setOverflow(((microseconds*72)/ps) - 1); return this->overflow; } void HardwareTimer::setChannel1Mode(uint8 mode) { -- cgit v1.2.3