Fix wrong max_duty (#431)

the max duty cycle is 2^N, only when using the maximum timer resolution is must be 2^N-1 to prevent overflow
This commit is contained in:
Lorenz 2024-06-11 18:43:55 +02:00 committed by GitHub
parent e4e608908e
commit d290357bba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -470,7 +470,12 @@ mod chip {
}
pub const fn max_duty(&self) -> u32 {
(1 << self.bits()) - 1
// when using the maximum resultion, the duty cycle must not exceed 2^N - 1 to avoid timer overflow
if cfg!(esp32) && self.bits() == 20 || cfg!(not(esp32)) && self.bits() == 14 {
(1 << self.bits()) - 1
} else {
1 << self.bits()
}
}
pub(crate) const fn timer_bits(&self) -> ledc_timer_bit_t {