diff options
| author | Grant Miller <[email protected]> | 2024-09-06 13:53:49 -0500 |
|---|---|---|
| committer | Grant Miller <[email protected]> | 2024-09-06 13:53:49 -0500 |
| commit | 1a8977db7837a5635d3c5e0ae8213d1b3181ffb7 (patch) | |
| tree | 5bceb855c421f6572aa1909d997bd6d9dda3b895 /examples/stm32g4 | |
| parent | cfc76cec711447300e2d957439a32d6ad418a58c (diff) | |
Update examples
Diffstat (limited to 'examples/stm32g4')
| -rw-r--r-- | examples/stm32g4/src/bin/pwm.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs index d4809a481..3833be58f 100644 --- a/examples/stm32g4/src/bin/pwm.rs +++ b/examples/stm32g4/src/bin/pwm.rs | |||
| @@ -15,22 +15,22 @@ async fn main(_spawner: Spawner) { | |||
| 15 | let p = embassy_stm32::init(Default::default()); | 15 | let p = embassy_stm32::init(Default::default()); |
| 16 | info!("Hello World!"); | 16 | info!("Hello World!"); |
| 17 | 17 | ||
| 18 | let ch1 = PwmPin::new_ch1(p.PC0, OutputType::PushPull); | 18 | let ch1_pin = PwmPin::new_ch1(p.PC0, OutputType::PushPull); |
| 19 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10), Default::default()); | 19 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(10), Default::default()); |
| 20 | let max = pwm.get_max_duty(); | 20 | let mut ch1 = pwm.ch1(); |
| 21 | pwm.enable(Channel::Ch1); | 21 | ch1.enable(); |
| 22 | 22 | ||
| 23 | info!("PWM initialized"); | 23 | info!("PWM initialized"); |
| 24 | info!("PWM max duty {}", max); | 24 | info!("PWM max duty {}", ch1.max_duty_cycle()); |
| 25 | 25 | ||
| 26 | loop { | 26 | loop { |
| 27 | pwm.set_duty(Channel::Ch1, 0); | 27 | ch1.set_duty_cycle_fully_off(); |
| 28 | Timer::after_millis(300).await; | 28 | Timer::after_millis(300).await; |
| 29 | pwm.set_duty(Channel::Ch1, max / 4); | 29 | ch1.set_duty_cycle_fraction(1, 4); |
| 30 | Timer::after_millis(300).await; | 30 | Timer::after_millis(300).await; |
| 31 | pwm.set_duty(Channel::Ch1, max / 2); | 31 | ch1.set_dutycycle_fraction(1, 2); |
| 32 | Timer::after_millis(300).await; | 32 | Timer::after_millis(300).await; |
| 33 | pwm.set_duty(Channel::Ch1, max - 1); | 33 | ch1.set_duty_cycle(ch1.max_duty_cycle() - 1); |
| 34 | Timer::after_millis(300).await; | 34 | Timer::after_millis(300).await; |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
