Skip to content

Commit 5b6c61f

Browse files
author
Stephen D
committed
Reset timer CNT register when PWM period is changed. This prevents the PWM from appearing to stop randomly
1 parent 057751d commit 5b6c61f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/timer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ mod sealed {
254254
fn start_one_pulse(&mut self);
255255
fn start_no_update(&mut self);
256256
fn cr1_reset(&mut self);
257+
fn cnt_reset(&mut self);
257258
}
258259

259260
pub trait WithPwm: General {
@@ -381,6 +382,10 @@ macro_rules! hal {
381382
fn cr1_reset(&mut self) {
382383
self.cr1.reset();
383384
}
385+
#[inline(always)]
386+
fn cnt_reset(&mut self) {
387+
self.cnt.reset();
388+
}
384389
}
385390

386391
$(with_dmar!($TIM, $memsize);)?

src/timer/pwm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ where
310310
let (psc, arr) = compute_arr_presc(period.raw(), clk.raw());
311311
self.tim.set_prescaler(psc);
312312
self.tim.set_auto_reload(arr).unwrap();
313+
self.tim.cnt_reset();
313314
}
314315
}
315316

0 commit comments

Comments
 (0)