mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 15:08:10 +01:00
PWM Output on RP2040 for high frequencies (#5204)
This commit is contained in:
parent
dfffa67c0f
commit
0ae3fcb0b7
1 changed files with 4 additions and 0 deletions
|
@ -27,8 +27,12 @@ void RP2040PWM::setup_pwm_() {
|
|||
|
||||
uint32_t clock = clock_get_hz(clk_sys);
|
||||
float divider = ceil(clock / (4096 * this->frequency_)) / 16.0f;
|
||||
if (divider < 1.0f) {
|
||||
divider = 1.0f;
|
||||
}
|
||||
uint16_t wrap = clock / divider / this->frequency_ - 1;
|
||||
this->wrap_ = wrap;
|
||||
ESP_LOGD(TAG, "divider=%.5f, wrap=%d, clock=%d", divider, wrap, clock);
|
||||
|
||||
pwm_config_set_clkdiv(&config, divider);
|
||||
pwm_config_set_wrap(&config, wrap);
|
||||
|
|
Loading…
Reference in a new issue