diff options
| author | rafael <[email protected]> | 2024-11-09 17:37:24 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-12-02 23:52:03 +0100 |
| commit | ccf2e0c528a85518e9d64456d9dfde9e951ef613 (patch) | |
| tree | 82af6687199f6fd9e93ae2036000f2c30d4dbbe0 /examples/rp/src/bin | |
| parent | 75382336164c8284196eb1fad057050ba735a72d (diff) | |
formatting
Diffstat (limited to 'examples/rp/src/bin')
| -rw-r--r-- | examples/rp/src/bin/pwm.rs | 8 |
1 files changed, 4 insertions, 4 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 { |
