Merge pull request #4302 from Jacke-debug/get_max_duty_off_by_one

Get max duty off by one for Center-aligned mode
This commit is contained in:
Dario Nieuwenhuis 2025-07-24 21:53:10 +00:00 committed by GitHub
commit 7d657ac16b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -111,7 +111,11 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
///
/// This value depends on the configured frequency and the timer's clock rate from RCC.
pub fn get_max_duty(&self) -> u16 {
self.inner.get_max_compare_value() as u16 + 1
if self.inner.get_counting_mode().is_center_aligned() {
self.inner.get_max_compare_value() as u16
} else {
self.inner.get_max_compare_value() as u16 + 1
}
}
/// Set the duty for a given channel.
@ -161,7 +165,11 @@ impl<'d, T: AdvancedInstance4Channel> embedded_hal_02::Pwm for ComplementaryPwm<
}
fn get_max_duty(&self) -> Self::Duty {
self.inner.get_max_compare_value() as u16 + 1
if self.inner.get_counting_mode().is_center_aligned() {
self.inner.get_max_compare_value() as u16
} else {
self.inner.get_max_compare_value() as u16 + 1
}
}
fn set_duty(&mut self, channel: Self::Channel, duty: Self::Duty) {