From c274dfafc202134e791de1468ba2cf0c9137621e Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Sat, 2 Jun 2012 22:01:29 -0400 Subject: HardwareTimer::setPeriod(): Don't use floating point. I can't believe we've been shipping this for so long. Signed-off-by: Marti Bolivar --- wirish/HardwareTimer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'wirish') diff --git a/wirish/HardwareTimer.cpp b/wirish/HardwareTimer.cpp index c35804c..ef720ce 100644 --- a/wirish/HardwareTimer.cpp +++ b/wirish/HardwareTimer.cpp @@ -26,10 +26,10 @@ #include -#include // for rcc_clk_id -#include // for CYCLES_PER_MICROSECOND +#include #include // for noInterrupts(), interrupts() #include +#include // for CYCLES_PER_MICROSECOND // TODO [0.1.0] Remove deprecated pieces @@ -112,7 +112,7 @@ uint16 HardwareTimer::setPeriod(uint32 microseconds) { uint32 period_cyc = microseconds * CYCLES_PER_MICROSECOND; uint16 prescaler = (uint16)(period_cyc / MAX_RELOAD + 1); - uint16 overflow = (uint16)round(period_cyc / prescaler); + uint16 overflow = (uint16)((period_cyc + (prescaler / 2)) / prescaler); this->setPrescaleFactor(prescaler); this->setOverflow(overflow); return overflow; -- cgit v1.2.3