diff options
| author | xoviat <[email protected]> | 2023-05-01 16:42:03 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-05-01 16:42:03 -0500 |
| commit | cd88e39f5fed0ed128f57d2e166f68a488e37698 (patch) | |
| tree | 607de896698647b7a2e903adc37cc2a81da9a73b /examples/stm32f4/src/bin/pwm_complementary.rs | |
| parent | 7646f18836166e4d16c6a3b5e63db128b08f56db (diff) | |
stm32/pwm: improve dead-time api
Diffstat (limited to 'examples/stm32f4/src/bin/pwm_complementary.rs')
| -rw-r--r-- | examples/stm32f4/src/bin/pwm_complementary.rs | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/examples/stm32f4/src/bin/pwm_complementary.rs b/examples/stm32f4/src/bin/pwm_complementary.rs index 6e17f3fd3..a8a68ed6e 100644 --- a/examples/stm32f4/src/bin/pwm_complementary.rs +++ b/examples/stm32f4/src/bin/pwm_complementary.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::pwm::complementary_pwm::{Ckd, ComplementaryPwm, ComplementaryPwmPin}; | 7 | use embassy_stm32::pwm::complementary_pwm::{ComplementaryPwm, ComplementaryPwmPin}; |
| 8 | use embassy_stm32::pwm::simple_pwm::PwmPin; | 8 | use embassy_stm32::pwm::simple_pwm::PwmPin; |
| 9 | use embassy_stm32::pwm::Channel; | 9 | use embassy_stm32::pwm::Channel; |
| 10 | use embassy_stm32::time::khz; | 10 | use embassy_stm32::time::khz; |
| @@ -31,34 +31,9 @@ async fn main(_spawner: Spawner) { | |||
| 31 | khz(10), | 31 | khz(10), |
| 32 | ); | 32 | ); |
| 33 | 33 | ||
| 34 | /* | ||
| 35 | Dead-time = T_clk * T_dts * T_dtg | ||
| 36 | |||
| 37 | T_dts: | ||
| 38 | This bit-field indicates the division ratio between the timer clock (CK_INT) frequency and the | ||
| 39 | dead-time and sampling clock (tDTS)used by the dead-time generators and the digital filters | ||
| 40 | (ETR, TIx), | ||
| 41 | 00: tDTS=tCK_INT | ||
| 42 | 01: tDTS=2*tCK_INT | ||
| 43 | 10: tDTS=4*tCK_INT | ||
| 44 | |||
| 45 | T_dtg: | ||
| 46 | This bit-field defines the duration of the dead-time inserted between the complementary | ||
| 47 | outputs. DT correspond to this duration. | ||
| 48 | DTG[7:5]=0xx => DT=DTG[7:0]x tdtg with tdtg=tDTS. | ||
| 49 | DTG[7:5]=10x => DT=(64+DTG[5:0])xtdtg with Tdtg=2xtDTS. | ||
| 50 | DTG[7:5]=110 => DT=(32+DTG[4:0])xtdtg with Tdtg=8xtDTS. | ||
| 51 | DTG[7:5]=111 => DT=(32+DTG[4:0])xtdtg with Tdtg=16xtDTS. | ||
| 52 | Example if TDTS=125ns (8MHz), dead-time possible values are: | ||
| 53 | 0 to 15875 ns by 125 ns steps, | ||
| 54 | 16 us to 31750 ns by 250 ns steps, | ||
| 55 | 32 us to 63us by 1 us steps, | ||
| 56 | 64 us to 126 us by 2 us steps | ||
| 57 | */ | ||
| 58 | pwm.set_dead_time_clock_division(Ckd::DIV1); | ||
| 59 | pwm.set_dead_time_value(0); | ||
| 60 | |||
| 61 | let max = pwm.get_max_duty(); | 34 | let max = pwm.get_max_duty(); |
| 35 | pwm.set_dead_time(max / 1024); | ||
| 36 | |||
| 62 | pwm.enable(Channel::Ch1); | 37 | pwm.enable(Channel::Ch1); |
| 63 | 38 | ||
| 64 | info!("PWM initialized"); | 39 | info!("PWM initialized"); |
