-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: correct ledc duty value range (IDFGH-10254) #11516
Conversation
Thanks for the contribution. I am aware of the issue, it might take some time to confirm the hardware behavior on all chips, and to check whether anything need to be changed in the driver. I will come back to this PR once I confirm! |
Just for reference: The implementation of Maybe this is another reason for the confusion. |
Hi forks, Sorry for the long wait. I have confirmed that For example, on ESP32C3, the maximum duty resolution for the LEDC timer is 14 bits. Therefore, you won't be enable to set duty to This is caused by a hardware bug which exists on all existing chips. The bug is planned to be fixed for the new chips. So please be aware of this restriction while setting duty values. Fix and modification to the IDF is on the way, it should be merged to master shortly. |
Thank you for checking. Will this PR be obsolete then? |
@jonschz This PR will be automatically closed when the changes are synced to Github. Still, thanks for raising the discussion and submitting the PR! |
Update ledc duty cycle value range in doxygen. Fix duty configuration error at 100% duty cycle for ESP32. Improve LEDC API doxygen. Closes espressif#11516 Closes espressif#12083
Update ledc duty cycle value range in doxygen. Fix duty configuration error at 100% duty cycle for ESP32. Improve LEDC API doxygen. Closes espressif#11516 Closes espressif#12593 Closes espressif#12083
As discussed e.g. here, the maximum value for
duty
inledc_set_duty_with_hpoint
is2**duty_resolution
, not2**duty_resolution - 1
. At the moment, the documentation is inconsistent; some places have the correct range, others do not.The fact that
2**duty_resolution
is correct can also be seen in the data sheet of the ESP32 (see pages 383-384): SupposeDUTY_RESOLUTION = 10
andHPOINT = 0
. IfDUTY = 1023
, the PWM output goes high when the counter starts at 0, then it goes low when the counter reaches 1023, and goes back up high one tick later when the counter rolls back to 0. Therefore, a value ofDUTY=1023
corresponds to an output that is high 99.90 % of the time. To get an output that is high permanently, we need to setDUTY=1024
.