100% duty cycle with ledc on ESP32-S3
Posted: Tue Apr 04, 2023 7:00 pm
I've been working with the ESP32-S3 and I noticed that when using the LEDC peripheral to generate a 100% duty cycle PWM signal (always on), if I use the maximum duty cycle value of (2^resolution - 1) as specified in the documentation (e.g 1023 for 10-bit resolution or 3 for 2-bit resolution), the result is not on all the time.
Instead, it looks as though it goes low for one cycle (period / 2^resolution) at the end of the period. I can reproduce this at all duty cycle resolution widths, but it's really obvious with a 2-bit timer since going low for one cycle results in 75% duty cycle.
I'm able to reproduce this on the ledc_basic example from the latest master on an ESP32-S3-DevKitC-1, modifying only LEDC_DUTY and LEDC_DUTY_RES (and setting the target to esp32-s3, of course), so I don't believe this is specific to my hardware or version of ESP-IDF.
If I set the duty cycle to 2^resolution (e.g 1024 for a 10-bit resolution or 4 for a 2-bit resolution), I do get a fully on 100% duty cycle, though I'm not sure if that's by accident or if that is the intended behavior. Am I misreading the documentation and I should be using 2^resolution for 100% duty cycle, or is this a hardware / software bug in the ESP32-S3 and it should be 2^resolution - 1?
Instead, it looks as though it goes low for one cycle (period / 2^resolution) at the end of the period. I can reproduce this at all duty cycle resolution widths, but it's really obvious with a 2-bit timer since going low for one cycle results in 75% duty cycle.
I'm able to reproduce this on the ledc_basic example from the latest master on an ESP32-S3-DevKitC-1, modifying only LEDC_DUTY and LEDC_DUTY_RES (and setting the target to esp32-s3, of course), so I don't believe this is specific to my hardware or version of ESP-IDF.
If I set the duty cycle to 2^resolution (e.g 1024 for a 10-bit resolution or 4 for a 2-bit resolution), I do get a fully on 100% duty cycle, though I'm not sure if that's by accident or if that is the intended behavior. Am I misreading the documentation and I should be using 2^resolution for 100% duty cycle, or is this a hardware / software bug in the ESP32-S3 and it should be 2^resolution - 1?