-
Notifications
You must be signed in to change notification settings - Fork 7.6k
ESP32 ledc 1bit PWM Configuration is impossible #7067
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
Comments
1-bit PWM means the duty cycle is fixed at 50%. https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#supported-range-of-frequency-and-duty-resolutions |
Yes, but i can not manage to configure it to get output on the pin. Removing the
the example above works as expected and i get a PWM Signal. |
Hi @mhuttner, this part of code was added, because of a simple reason. If all bits from given resolution are set, then LEDC should be full on. Quick example is on 8-bit resolution. The value is between 0-255, thats 8 bits. But without this piece of code the 255 won't be 100% on, you need to write 256 to be fully on, but it makes no sense. If you need to be able to set these, select 2 bits resolution. With this change, we loose the value 1 for all resolutions, but for most use cases, it affordable price. |
@mhuttner Can you please test your code with this change:
Thanks! |
@P-R-O-C-H-Y Thanks for the response. The change works with my code. |
Board
ESP32
Device Description
ESP32-WROOM
Hardware Configuration
GPIO19 is LED PWM Pin
Version
v2.0.4
IDE Name
arduino-cli
Operating System
macOS 12.4
Flash frequency
40MHz
PSRAM enabled
no
Upload speed
921600
Description
ledcWrite makes it impossible to set the duty cycle to 50% for 1bit PWM because of this:
arduino-esp32/cores/esp32/esp32-hal-ledc.c
Lines 89 to 96 in 9432163
when
channels_resolution[chan]
is 1 the possible duty cycles should be 0 (0%), 1 (50%) and 2(100%).But for a duty of 1
max_duty
will be 1 (1<<1 - 1
) and sinceduty == max_duty
the duty will be set to2
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: