diff options
| -rw-r--r-- | examples/rp/src/bin/pwm.rs | 8 | ||||
| -rw-r--r-- | examples/rp23/src/bin/pwm.rs | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/examples/rp/src/bin/pwm.rs b/examples/rp/src/bin/pwm.rs index 06b9313f2..cf6531994 100644 --- a/examples/rp/src/bin/pwm.rs +++ b/examples/rp/src/bin/pwm.rs | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | use defmt::*; | 10 | use defmt::*; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_rp::peripherals::{PIN_25, PIN_4, PWM_SLICE2, PWM_SLICE4}; | 12 | use embassy_rp::peripherals::{PIN_4, PIN_25, PWM_SLICE2, PWM_SLICE4}; |
| 13 | use embassy_rp::pwm::{Config, Pwm, SetDutyCycle}; | 13 | use embassy_rp::pwm::{Config, Pwm, SetDutyCycle}; |
| 14 | use embassy_time::Timer; | 14 | use embassy_time::Timer; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -48,15 +48,15 @@ async fn pwm_set_dutycycle(slice2: PWM_SLICE2, pin4: PIN_4) { | |||
| 48 | // If we aim for a specific frequency, here is how we can calculate the top value. | 48 | // If we aim for a specific frequency, here is how we can calculate the top value. |
| 49 | // The top value sets the period of the PWM cycle, so a counter goes from 0 to top and then wraps around to 0. | 49 | // The top value sets the period of the PWM cycle, so a counter goes from 0 to top and then wraps around to 0. |
| 50 | // Every such wraparound is one PWM cycle. So here is how we get 25KHz: | 50 | // Every such wraparound is one PWM cycle. So here is how we get 25KHz: |
| 51 | let desired_freq_hz = 25_000; | 51 | let desired_freq_hz = 25_000; |
| 52 | let clock_freq_hz = embassy_rp::clocks::clk_sys_freq(); | 52 | let clock_freq_hz = embassy_rp::clocks::clk_sys_freq(); |
| 53 | let divider = 16u8; | 53 | let divider = 16u8; |
| 54 | let period = (clock_freq_hz / (desired_freq_hz * divider as u32)) as u16 - 1; | 54 | let period = (clock_freq_hz / (desired_freq_hz * divider as u32)) as u16 - 1; |
| 55 | 55 | ||
| 56 | let mut c = Config::default(); | 56 | let mut c = Config::default(); |
| 57 | c.top = period; | 57 | c.top = period; |
| 58 | c.divider = divider.into(); | 58 | c.divider = divider.into(); |
| 59 | 59 | ||
| 60 | let mut pwm = Pwm::new_output_a(slice2, pin4, c.clone()); | 60 | let mut pwm = Pwm::new_output_a(slice2, pin4, c.clone()); |
| 61 | 61 | ||
| 62 | loop { | 62 | loop { |
diff --git a/examples/rp23/src/bin/pwm.rs b/examples/rp23/src/bin/pwm.rs index ed3c94f15..bd3c287ad 100644 --- a/examples/rp23/src/bin/pwm.rs +++ b/examples/rp23/src/bin/pwm.rs | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | use defmt::*; | 10 | use defmt::*; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_rp::block::ImageDef; | 12 | use embassy_rp::block::ImageDef; |
| 13 | use embassy_rp::peripherals::{PIN_25, PIN_4, PWM_SLICE2, PWM_SLICE4}; | 13 | use embassy_rp::peripherals::{PIN_4, PIN_25, PWM_SLICE2, PWM_SLICE4}; |
| 14 | use embassy_rp::pwm::{Config, Pwm, SetDutyCycle}; | 14 | use embassy_rp::pwm::{Config, Pwm, SetDutyCycle}; |
| 15 | use embassy_time::Timer; | 15 | use embassy_time::Timer; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
