Change Duty Cycle
AnselPeng2019 opened this issue · 7 comments
when I use this lib, after setup the PWM paras, the PWM works well. But I need to change the duty cycle in working, for example, the breathing led.
I have tried to use disable or delete function, but it looks not work, the PWM duty cycle do not change.
So, it would be great if there is a duty cycle set up function.
Hi,
I just add an example ISR_Changing_PWM to show you how to change PWM freq and duty-cycle on-the-fly.
Anyway, I'll add option to make it easier to change the PWM freqs and duty-cycles, without having to delete and reinit the PWM channels in next release.
The new ESP8266_PWM releases v1.1.0 has just been published
Your contribution has been noted in Contributions and Thanks
Check the new
The library is definitely better and more useful now. Looking forward to receiving more enhancement requests from you.
Best Regards,
KH
Changelog
Releases v1.1.0
- Add functions to modify PWM settings on-the-fly
- Fix bug
- Add example to demo how to modify PWM settings on-the-fly
I'm similarly trying to change the duty cycle with a fixed frequency. Since PWM_DutyCycle is a uint32_t , this can only be done in 100 steps. I suggest to have an alternative function where you can specify Period/OnTime to be able to get the full duty cycle resolution. Or change PWM_DutyCycle to a float (I think 0. to 1. would be easier to use than 0-100 if you do this).
Good idea. I'll rewrite the library to use float / double for PWM freqs, period and duty-cycles to have much better accuracy.
Regards,
Hi @ggmichael
The new ESP8266_PWM releases v1.2.0 has just been published. Your contribution is noted in Contributions and Thanks
Best Regards,
Releases v1.2.0
- Fix
multiple-definitionslinker error. Dropsrc_cppandsrc_hdirectories - Add feature to select among highest, medium or lowest accuracy for Timers for shortest, medium or longest time
- Fix reattachInterrupt() bug. Check bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19
- Add example multiFileProject to demo for multiple-file project
- Improve accuracy by using
double, instead ofuint32_tfordutycycle,period. Check Change Duty Cycle #1 - Update examples accordingly
Thanks for this! Your library has fixed a problem I was having with inconsistent calibration, which I now think arose from the changing timing of the analogWrite pwm.
One more feature that would be nice would be to be able to command a duty cycle update to occur at the end of the next full period instead of immediately (as I think happens now). If you're trying to create a continuously variable mean output voltage, resetting the channel at a frequency that approaches the PWM frequency causes a bias towards whichever part of the duty cycle comes first. This wouldn't happen if the update occurred at the end of the cycle. It may be that there are other applications (long cycles) where you would prefer the update straight away. So perhaps a flag to set either mode.
Hi @ggmichael
One more feature that would be nice would be to be able to command a duty cycle update to occur at the end of the next full period instead of immediately (as I think happens now)
It's nice-to-have and a little bit harder, but totally possible to address this issue, if there are many more users requesting the similar feature.
Can you start by creating a new enhancement request / issue, and also specify the use-case and how it'll be beneficial to have the new feature.
IMO, a short glitch can't affect anything (such as light, motor control, etc.). I also don't think analogWrite pwm has taken care of this issue.
Thanks,