-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add option to shift the phase of multiple PWM outputs #7850
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
This was suggested briefly in #7057 by @s-hadinger as well |
Check the Phase-locked PWM generator described in the docs/headers. You can so manual startWaveform()s with shifted alignment to handle what you're talking about that way.
Be sure to add the |
The Arduino reference does not allow phase locking. One of our two implementations does, but as @earlephilhower says, you have to go below the "normal" Arduino api and implement things on your own according to what you need. |
thanks for your feedback, |
This is the place, but the point is that the feature is already implemented. All you have to do, as you said, is make it work to fit your needs, which should be trivial if you look at the implementation of the Arduino functions that wrap the lower level waveform generator, e. g. AnalogWrite(), AnalogFrequency(). I implemented a 4ch variable frequency pulse generator for stepper motors with the waveform gen by looking at that, and it took about 10 minutes to get the proof of concept working. |
Thanks for your replies. However I am overwhelmed. :( |
@GagoX You are just opening a big can of worms. You gave simple examples with 2 PWM that fit nicely. However what about 3,4,5 PWMs? What if the sum of duty cycle exceeds 100%? There are so many cases to consider that the code will become quickly bloated. Did you actually see a problem with PWM being phase locked? |
Hi @s-hadinger,now that you mention it, I agree that the case of 2 channels is more straightforward to define. My problem is only that I am a newbi and do not know how to proceed with the advice given by earlephilhower. cheers |
Hi, What am I missing? |
Basic Infos
Platform
Settings in IDE
Problem Description
In the current version of Tasmota, when using two PWM outputs to control a CCT light, both PWMs have 0° phase shift, i.e., both go up or down in sync at the start of a cycle.
In some cases it would be better to spread out the PWM, so that at 100% brightness, the total power is distributed over the whole PWM cycle. This is relevant for tunable white COBs LEDs which usually are rated for a maximum combined constant current for both cold and warm channels.
E.g., For brightness slider at 100%, if the CCT slider is at 80%:
Currently: PWM1 is high between 0 and 80% of the cycle, PWM2 is high between 0 and 20% of the cycle. The power profile over time is 120% during 0-20% of the cycle, 80% during 20-80% of the cycle and 0% during 80-100% of the cycle.
This effectively halves the max current that a tunable white LED can be driven with. As in the case where the CCT slider is 50%, the LED would get 200% of the driving current in half the cycle and zero on the other half.
Alternatively, an option could be implemented so that - for the same example (for brightness slider at 100%, if the CCT slider is at 80%): PWM1 is high between 0 and 80% of the cycle, the PWM2 should be high between 80 and 100% of the cycle.
I this case the power profile is constantly 100% over the entire cycle.
The text was updated successfully, but these errors were encountered: