mirror of
https://github.com/esp-rs/esp-idf-hal.git
synced 2025-10-01 14:20:50 +00:00
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:
parent
e4e608908e
commit
d290357bba
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user