Skip to content

Commit 8d967e3

Browse files
committed
fix stopwatch
1 parent 9af1fa0 commit 8d967e3

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

examples/stopwatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() -> ! {
3131
#[cfg(feature = "stm32g0x0")]
3232
let mut stopwatch = dp.TIM3.stopwatch(&mut rcc);
3333

34-
stopwatch.set_prescaler(1);
34+
stopwatch.set_prescaler(0);
3535

3636
let elapsed_us = stopwatch.trace(|| {
3737
delay.delay(100.us());

src/timer/stopwatch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ macro_rules! stopwatches {
7171
pub fn elapsed(&self, ts: Instant) -> MicroSecond {
7272
let now = self.now().0;
7373
let cycles = now.wrapping_sub(ts.0);
74-
self.clk.duration(cycles << self.tim.psc.read().bits())
74+
self.clk.duration(cycles * (1 + self.tim.psc.read().bits()))
7575
}
7676

7777
pub fn trace<F>(&self, mut closure: F) -> MicroSecond
@@ -81,7 +81,7 @@ macro_rules! stopwatches {
8181
let started = self.now().0;
8282
closure();
8383
let now = self.now().0;
84-
self.clk.duration(now.wrapping_sub(started) << self.tim.psc.read().bits())
84+
self.clk.duration(now.wrapping_sub(started) * (1 + self.tim.psc.read().bits()))
8585
}
8686
}
8787

0 commit comments

Comments
 (0)