diff options
| author | Aurélien Jacobs <[email protected]> | 2023-08-18 16:10:49 +0200 |
|---|---|---|
| committer | Aurélien Jacobs <[email protected]> | 2023-08-18 16:10:49 +0200 |
| commit | 78bb261246559e0447dc472f89480564e8b7a3fc (patch) | |
| tree | 11a14f4ebb640f1ff52a6c680e097e959d05531b | |
| parent | 5329f234ba950fdde6f04c239f8f9f172e4a3afa (diff) | |
stm32: allow setting PWM duty cycle to 100%
Setting the compare_value to max_compare_value make the PWM output
go low when the timer reach the max_compare_value and go high again
on the next timer clock, when the value roll back to 0.
So to allow a 100% PWM that never goes low, the compare_value must
be set to max_compare_value + 1.
| -rw-r--r-- | embassy-stm32/src/timer/complementary_pwm.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/simple_pwm.rs | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index acd67048d..533267cf7 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs | |||
| @@ -100,11 +100,11 @@ impl<'d, T: ComplementaryCaptureCompare16bitInstance> ComplementaryPwm<'d, T> { | |||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | pub fn get_max_duty(&self) -> u16 { | 102 | pub fn get_max_duty(&self) -> u16 { |
| 103 | self.inner.get_max_compare_value() | 103 | self.inner.get_max_compare_value() + 1 |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | pub fn set_duty(&mut self, channel: Channel, duty: u16) { | 106 | pub fn set_duty(&mut self, channel: Channel, duty: u16) { |
| 107 | assert!(duty < self.get_max_duty()); | 107 | assert!(duty <= self.get_max_duty()); |
| 108 | self.inner.set_compare_value(channel, duty) | 108 | self.inner.set_compare_value(channel, duty) |
| 109 | } | 109 | } |
| 110 | 110 | ||
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index e0a817929..40e3dd1bd 100644 --- a/embassy-stm32/src/timer/simple_pwm.rs +++ b/embassy-stm32/src/timer/simple_pwm.rs | |||
| @@ -97,11 +97,11 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | pub fn get_max_duty(&self) -> u16 { | 99 | pub fn get_max_duty(&self) -> u16 { |
| 100 | self.inner.get_max_compare_value() | 100 | self.inner.get_max_compare_value() + 1 |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | pub fn set_duty(&mut self, channel: Channel, duty: u16) { | 103 | pub fn set_duty(&mut self, channel: Channel, duty: u16) { |
| 104 | assert!(duty < self.get_max_duty()); | 104 | assert!(duty <= self.get_max_duty()); |
| 105 | self.inner.set_compare_value(channel, duty) | 105 | self.inner.set_compare_value(channel, duty) |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
