ESP32/ledc: div_param zero depending on init routine location
Posted: Sat Apr 16, 2022 8:59 pm
Hi,
while tracking down another bug concerning single inverted ports between an old compiled image and a brand new one, I stumbled across this. Maybe (hopefully?) this is extremely simple, but the subroutine version worked with the old image (compiled using esp32 v1.9.x in Arduino 1.8.13), while the current 2.0.2 in 1.8.19 throws me this error:
I'm clearly not exceeding any hardware limits at 5kHz and 8 bit, and the previous version worked fine at 15kHz and 10 bit.
ESP-WROOM32 on a random AliExpress dev board.
Working code for 2.x:
Code producing the above error:
Everything is the same except for the fact that it is put in a function that is called from setup(). Originally, this is even a separate .ino file since there are seven channels and a couple of fading routines used across the project. I'd really like to have this separated from setup(), but I cannot figure out why it doesn't work anymore.
while tracking down another bug concerning single inverted ports between an old compiled image and a brand new one, I stumbled across this. Maybe (hopefully?) this is extremely simple, but the subroutine version worked with the old image (compiled using esp32 v1.9.x in Arduino 1.8.13), while the current 2.0.2 in 1.8.19 throws me this error:
- 22:31:49.793 -> a
- 22:31:49.793 -> E (1099) ledc: requested frequency and duty resolution can not be achieved, try reducing freq_hz or duty_resolution. div_param=0
- 22:31:49.793 -> b
ESP-WROOM32 on a random AliExpress dev board.
Working code for 2.x:
- #include <driver/ledc.h>
- void setup()
- {
- Serial.begin(115200);
- delay(1000); // give me time to bring up serial monitor
- ledc_timer_config_t ledc_timer;
- ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
- ledc_timer.timer_num = LEDC_TIMER_1;
- ledc_timer.duty_resolution = LEDC_TIMER_8_BIT;
- ledc_timer.freq_hz = 5000;
- ledc_channel_config_t ledc_channel0;
- ledc_channel0.channel = LEDC_CHANNEL_0;
- ledc_channel0.gpio_num = 2;
- ledc_channel0.speed_mode = LEDC_HIGH_SPEED_MODE;
- ledc_channel0.intr_type = LEDC_INTR_FADE_END;
- ledc_channel0.timer_sel = LEDC_TIMER_1;
- ledc_channel0.hpoint = 0;
- ledc_channel0.duty = 255;
- Serial.println("a");
- ledc_timer_config(&ledc_timer);
- Serial.println("b");
- ledc_channel_config(&ledc_channel0); //onboard
- ledc_fade_func_install(ESP_INTR_FLAG_SHARED);
- }
- void loop(){}
- #include <driver/ledc.h>
- void setup()
- {
- Serial.begin(115200);
- delay(1000); // give me time to bring up serial monitor
- setupLEDs();
- }
- void setupLEDs() {
- ledc_timer_config_t ledc_timer;
- ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
- ledc_timer.timer_num = LEDC_TIMER_1;
- ledc_timer.duty_resolution = LEDC_TIMER_8_BIT;
- ledc_timer.freq_hz = 5000;
- ledc_channel_config_t ledc_channel0;
- ledc_channel0.channel = LEDC_CHANNEL_0;
- ledc_channel0.gpio_num = 2;
- ledc_channel0.speed_mode = LEDC_HIGH_SPEED_MODE;
- ledc_channel0.intr_type = LEDC_INTR_FADE_END;
- ledc_channel0.timer_sel = LEDC_TIMER_1;
- ledc_channel0.hpoint = 0;
- ledc_channel0.duty = 255;
- Serial.println("a");
- ledc_timer_config(&ledc_timer);
- Serial.println("b");
- ledc_channel_config(&ledc_channel0); //onboard
- ledc_fade_func_install(ESP_INTR_FLAG_SHARED);
- }
- void loop(){}