enable output compare preload for TIM

keep output waveform integrity
This commit is contained in:
eZio Pan 2023-12-23 19:45:56 +08:00
parent 2f75ffb233
commit dcd4e6384e

View file

@ -21,6 +21,7 @@
use embassy_executor::Spawner;
use embassy_stm32::gpio::OutputType;
use embassy_stm32::pac;
use embassy_stm32::pac::timer::vals::Ocpe;
use embassy_stm32::time::khz;
use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
use embassy_stm32::timer::{Channel, CountingMode};
@ -89,6 +90,12 @@ async fn main(_spawner: Spawner) {
let pwm_channel = Channel::Ch1;
// PAC level hacking, enable output compare preload
// keep output waveform integrity
pac::TIM3
.ccmr_output(pwm_channel.index())
.modify(|v| v.set_ocpe(0, Ocpe::ENABLED));
// make sure PWM output keep low on first start
ws2812_pwm.set_duty(pwm_channel, 0);