Open andycarle opened 3 years ago
Thank you Andy for reporting this bug! Although it seems you never got a response, your report helped me to get my signal generator behave bug free. (I just dialed down the cpu-freq to 160 MHZ, and it works flawlessly now!)
But looking closer at your code, you don't want
ledc_channel_config(&ledc_channel);
in the while-loop. Better to configure the channel once (ie before the while loop)
and only change duty repeatedly.
And as for the slight delay, the cpu runs @240MHz, the LEDC_HIGH_SPEED_MODE is 80MHz, so you need to give it a few clock-cycles to execute the instructions, and apparently 1ms (240cycles) is enough. Have you tried less?
Anyway, thanks again, regards Hermen
@HermenB hi HermenB I have a similar requirement. I need to constantly change the input and output modes of io. When io is output, I need to configure it as pwm output, but when changing the io output mode, I do not see the deinitialization of the LEDC peripheral. Interfaces, LEDC timers and channels do not need to be de-initialized. You only need to stop LEDC and then you can directly initialize other peripherals connected to this IO?
Environment
Problem Description
The LEDC PWM module produces unreliable output when quickly calling
ledc_stop
,ledc_channel_config
,ledc_set_duty
, andledc_update_duty
in sequence. When these ESP-IDF functions are called quickly in this order, the LEDC PWM module sometimes outputs a single short low pulse followed by a steady logical 1 instead of the duty cycle set byledc_set_duty
. If a brief delay is introducted betweenledc_stop
and the remaining LEDC API calls, it works as expected.Note: this issue only seems to occur with the ESP32 configured for 240 MHz
Consider this example, modified from
ledc_example.main.c
.If
TEST_DELAY
is defined totrue
this example works as expected and this correct signal is output on GPIO27:If
TEST_DELAY
is defined tofalse
this incorrect signal is output on GPIO27:Are there known restrictions around how quickly you can stop and re-start the LEDC module on a pin? Or perhaps restrictions on how long to wait between a call to
ledc_channel_config
andledc_set_duty
? If so, where can I find that guidance?Expected Behavior
GPIO27 outputs a nearly constant PWM signal at 10 kHz that cycles between three PWM duties (25%, 50%, 75%) with small gaps between each duty cycle phase.
Actual Behavior
GPIO27 outputs the correct PWM signal for 100 ms and then starts putting out one low pulse and then solid logic level 1 on each subsequent PWM configuration when quickly stopped and restarted. It works as expected if an artificial delay is introduced with
vTaskDelay
.Steps to reproduce
ledc_example.main.c
with the code snippet above.idf.py menuconfig
and configure the ESP32 for 240 MHz (Component config -> ESP32-Specific -> CPU Frequency -> 240 MHz and save.idf.py build flash monitor
Other items if possible
sdkconfig and elf.zip
Thank you for your assistance, - Andy