Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

jonschz
Copy link

@jonschz jonschz commented May 26, 2023

As discussed e.g. here, the maximum value for duty in ledc_set_duty_with_hpoint is 2**duty_resolution, not 2**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): Suppose DUTY_RESOLUTION = 10 and HPOINT = 0. If DUTY = 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 of DUTY=1023 corresponds to an output that is high 99.90 % of the time. To get an output that is high permanently, we need to set DUTY=1024.

@CLAassistant
Copy link

CLAassistant commented May 26, 2023

CLA assistant check
All committers have signed the CLA.

@espressif-bot espressif-bot added the Status: Opened Issue is new label May 26, 2023
@github-actions github-actions bot changed the title docs: correct ledc duty value range docs: correct ledc duty value range (IDFGH-10254) May 26, 2023
@songruo
Copy link
Collaborator

songruo commented Jun 3, 2023

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!

@jonschz
Copy link
Author

jonschz commented Jun 6, 2023

Just for reference: The implementation of analogWrite() is aware of this issue and maps an input of 2**duty_resolution - 1 to 2**duty_resolution:

https://github.com/espressif/arduino-esp32/blob/72c41d09538663ebef80d29eb986cd5bc3395c2d/cores/esp32/esp32-hal-ledc.c#L89-L94C1

Maybe this is another reason for the confusion.

@songruo
Copy link
Collaborator

songruo commented Sep 28, 2023

Hi forks,

Sorry for the long wait. I have confirmed that 2**duty_resolution (i.e. 100% duty cycle) is a feasible duty in most circumstances. The case where this duty value would cause problem is when the binded timer is selecting its maximum duty resolution.

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 (2**14). Otherwise, the duty calculation in the hardware will be messed up.

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.

@jonschz
Copy link
Author

jonschz commented Sep 28, 2023

Thank you for checking. Will this PR be obsolete then?

@songruo
Copy link
Collaborator

songruo commented Oct 7, 2023

@jonschz This PR will be automatically closed when the changes are synced to Github. Still, thanks for raising the discussion and submitting the PR!

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: Opened Issue is new labels Oct 7, 2023
@jonschz jonschz deleted the docs_ledc_duty_range branch November 1, 2023 21:33
espressif-bot pushed a commit that referenced this pull request Nov 21, 2023
Update ledc duty cycle value range in doxygen.
Fix duty configuration error at 100% duty cycle for ESP32.
Improve LEDC API doxygen.

Closes #11516
Closes #12593
Closes #12083
espressif-bot pushed a commit that referenced this pull request Nov 22, 2023
Update ledc duty cycle value range in doxygen.
Fix duty configuration error at 100% duty cycle for ESP32.
Improve LEDC API doxygen.

Closes #11516
Closes #12593
Closes #12083
movsb pushed a commit to movsb/esp-idf that referenced this pull request Dec 1, 2023
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
espressif-bot pushed a commit that referenced this pull request Dec 13, 2023
Update ledc duty cycle value range in doxygen.
Fix duty configuration error at 100% duty cycle for ESP32.
Improve LEDC API doxygen.

Closes #11516
Closes #12593
Closes #12083
hathach pushed a commit to adafruit/esp-idf that referenced this pull request Mar 27, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants