-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
ledcWrite doesn't change duty cycle if duty cycle was changed less than one period ago and if using HS LEDC (channels 0-7) #5306
Comments
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
same Problem |
Hello @joshua-8, this problem was fixed in ESP-IDF side, changes will take effect in upcoming Arduino core release 2.0.3. |
Hi @joshua-8, can you test your issue with the 2.0.3-RC1 release? So we can close this ;) |
@joshua-8 Perfect, thank you for testing and contribution! |
I tried to search for an issue about this didn't find anything, but if this is a known issue, I apologize.
Hardware:
Board: ESP32 Dev Module (WROOM)
Core Installation version: 1.0.6
IDE name: Arduino IDE 1.8.13
Flash Frequency: 80MHz
PSRAM enabled: Disabled
Upload Speed: 921600
Computer OS: Windows 10
no additional hardware needed.
Description:
I found this issue when using LEDC to control a servo. Sometimes, seemingly randomly, the servo wouldn't go to the position I was telling it to.
ledcWrite was not always changing the duty cycle of the signal.
ledcWrite doesn't change the duty cycle if ledcWrite is used soon after it was just used (with a shorter delay than the period of the PWM wave) and if using an HS LEDC channel(0-7) (channels 8-15 work perfectly, with the duty cycle always changing)
I was able to make a sketch that could consistently reproduce the issue for me.
Sketch:
This image shows that the PWM output keeps its duty cycle of 800/1023 instead of changing to 200/1023 as set later.
Adding a delay to allow the first pulse to go by makes the duty cycle change on the next pulse. This is what I would expect to always happen
The issue doesn't just appear when the "first pulse" is the first pulse since the program started. ledcWrite was used three times here, the first duty cycle runs for a while, then a second duty cycle is successfully set, and where the top blue line goes up, a third frequency was set, but doesn't appear.
Debug Messages:
none
Solutions:
Unfortunately, I don't know enough about ledc and esp32s to be able to fix this issue.
I did find a workaround that's good enough for my servo project: if I continuously use ledcWrite from within a loop, if one call of ledcWrite doesn't work, the next one (or how ever many it takes to wait for a new cycle) will.
I know I could just use channels 8-15 since they don't have the issue, but I have a project that uses 9 pwm signals
I was hoping that I could call ledcWrite only when I need to change the duty cycle, to optimize the speed of my program.
As a related note, ledcRead returns the value that was most recently set even if the duty cycle didn't change to the new value, so I can't use that to detect if ledcWrite needs to be used.
If anyone has an idea for a better workaround, or knows why this issue happens, I would be very interested in hearing it.
I would be happy to help with any testing, or provide more information if needed.
Thank you, esp32 community, for all your work!
The text was updated successfully, but these errors were encountered: