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

calling analogWrite() frequently causes the pin to spend extra time low #3

Closed
joshua-8 opened this issue Apr 27, 2021 · 5 comments
Closed

Comments

@joshua-8
Copy link

@Dlloydev First of all, thank you for making a really cool library. Making analogWrite() supported is a big step towards making programs run on both esp32s and standard Arduino boards more easily!

I was looking at the output of the Fade example with an oscilloscope and noticed the signal wasn't quite what I would expect.
oscilloscope_fade
Each time analogWrite was called to change the duty cycle on the pin, it seems the pin goes low for approximately 200 microseconds. This interrupts the otherwise good 5kHz PWM signal and means that even if the signal is set to 100% there will be intervals where the pin is LOW after each time analogWrite is called.
This issue could cause unexpected results in any program where analogWrite is called frequently.

Is ledcSetup getting called every time analogWrite is? That might be what's causing the issue because when I have used ledcSetup once then only ledcWrite later I don't get the dips.
Would it be possible to check if the channel, resolution, or frequency needs to be changed? If only the duty cycle needs to be changed then I don't think ledcSetup needs to be called.

Please let me know if I can help in any way.
Thanks,
joshua-8

@Dlloydev
Copy link
Owner

Thank you for the detailed feedback! Yes, I think you may have found the root cause ... I'll run some tests later today then hopefully prepare an update - if not today, then very soon ...
Regards,
D. Lloyd

Dlloydev added a commit that referenced this issue Apr 28, 2021
@Dlloydev
Copy link
Owner

Dlloydev commented Apr 28, 2021

The waveform is now looking good. Only update ledcSetup when necessary. All parameters are now checked if changes are made. With analogWrite running continuously in the loop, a 5kHz PWM signal looked good and consistent.

This is the waveform when the duty cycle is changed 25% to 50% repeatedly ....
image
This is the waveform when changing both duty cycle and frequency repeatedly ....
image

analogWrite is now updated to version 2.0.3.

@Dlloydev
Copy link
Owner

Still some variations to test and another update needed.
Should be ready in 1 or 2 days.

Dlloydev added a commit that referenced this issue Apr 28, 2021
@Dlloydev
Copy link
Owner

Well, I think I've ironed out the last wrinkle ... updated to version 2.0.4

@Dlloydev
Copy link
Owner

Dlloydev commented May 2, 2021

I believe this is now resolved, thanks again for the feedback!
Please re-open or start a new issue if there's any problems, suggestions etc.

@Dlloydev Dlloydev closed this as completed May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants