-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Added method to change the ledc PWM frequency programmatically #5003
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
Conversation
How about adding a boolean to ledcSetup that determines whether to reset the duty cycle instead? |
But you could not change the frequency during runtime. |
You would just call the setup a second time to change the frequency. Your code is almost identical to what ledcSetup calls, it just doesn't set the duty to 0. If that is not clear enough, you could then have your setFrequency function, but it would just be an alias to ledcSetup. |
Ah okay. Now I understand what you meant. But of couse. It could be solved by adding another parameter to the setup method. |
any development here? :) |
All development done in commits ;) |
I will accept this if you return the frequency as done in |
- Returning frequency from ledcChangeFrequency
Done. |
Currently there is no real option to change the pwm frequency programmatically. The only "hack" solution is to use the
ledcWriteTone(uint8_t chan, double freq)
method.But there is problem with this hack. Inside this method the bit resolution value is hard coded to 10. Which means if you had a different bit resolution inside your setup it would be overrided here.
So I added a simple method to change the pwm frequency programmatically. This method takes three parameters:
uint8_t chan, double freq, uint8_t bit_num