-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Unsynced PWM causes LED flickering #7054
Comments
@s-hadinger please make sure to test with 2.6.3 or latest git. |
There was a fundamental change in the analogWrite behind this. The latest GIT may have some difference, but nothing that would change what @s-hadinger is talking about, IIRC. The 2.4/pre version guaranteed phase alignment since it took over the timer and everyone analogWrite pin had a sync'd start point (i.e. at t=0 all PWM pins went high, and then at the appropriate time individual pins were set to 0). Other stuff that needed a timer was SOL, though. The 2.5, as a shared setup, does not use the same logic and works to guarantee duty cycle, not phase relationships. Wouldn't the low frequency cause weird optical effects at low values, no matter what? Is the 800hz immutable? Can you go to 4khz? Seems like a LED driver board issue, honestly. I would have thought that having different high current sources coming on at different times, vs. sync'd, would be better for most boards. The high current power supply instantaneous delta-I will be worse with more pins changing at the same time, no? And the integral over time still has the same percent on for all channels. With all PWM phase aligned don't you also increase the harmonics noise you're injecting, too? |
you are right with delta-I being more gentle to the power source and less harmonic noise with unsynced pwm vs all start at the same time. |
I agree that having the pulses with phase differences is good for the power supply. The flickering is caused by the fact that the phase difference between channels is changing over time. I tried a simple patch that seem to keep phases locked with each others: In Before
After
Basically if the NMI arrives late and I tried with the same LED drivers, and the flickering seems gone. |
See esp8266#7054, PWM channels phases can change over time causing visible flickering on LED drivers (Tasmota). This fix makes sure the PWM pulses are kept in sync, phases constant whatever the delay of the NMI.
Just to make sure we are not confusing issues. There has been a stuttering issue when fading on Tasmota, this has been fixed. The current flickering issue is when LED are in steady state and is not linked to PWM frequency (880Hz is not visible). The flickering is due to phase change between 3 PWM channels, and power supplies deliver different currents to LEDs whether the pulses are at the same time or spread in time. To be specific, the flickering is due to continuous change in phases - no calls made to The explanation, is that when Hence I proposed PR #7057 to solve the phase issue. I also added a safeguard making sure that if the delay goes over the length of a full PWM cycle, we ignore the lost PWM cycles.
(The double minus is to avoid negative modulus issues) This patch has been tested by 4 people from Tasmota contributors, and they all confirm the flickering is gone. I hope it is clear and can be integrated in Arduino Core. |
Dear @s-hadinger, I've a PR pending that appears to pre-date your issue report and fix, plus is much more comprehensive, I would like to urge you to test the effects of my changes: #7022 |
That's also quite effective to detect phase shifts. |
Have just same problems than @s-hadinger . Over year ago other rgb strip project (with tasmota and nodemcu) and now have same problems yesterday when i try to do new RGBW strip light. Here little video to give problem more information. Problem is that when you have static color rgbw strip is flickering thats very easily to recognize. Dark room most more easier see that problem, not know is that seems ok video. Video have manual explosure etc settings and up corner see lab power supply and see how much current is changing static color setting. Try couple different power supplies and battery powered problem is same all of them. Here video: |
Here's an MCVE that I have built based on @Tech-TX's input. #if !defined(D6)
#define D6 (12)
#endif
void setup() {
analogWrite(LED_BUILTIN, 1023);
analogWrite(D6, 512);
}
uint32_t pass = 0;
void loop()
{
if (0 == pass++ % 100000)
{
analogWrite(LED_BUILTIN, 1021);
delay(500);
analogWrite(LED_BUILTIN, 1023);
}
} This sketch turns off the internal LED (analogWrite 1023), but at every 100000th iteration of loop, it dims it at 1021 for 500ms. |
Basic Infos
Platform
Settings in IDE
Problem Description
For several months, some Tasmota users reported LED flickering when set at low brightness. The flickering is subtle but noticeable. The PWM values are set with
analogWrite()
and left unchanged.The problem occurs with core 2.5.x and 2.6.x but did not occur with 2.4.x.
I finally took a scope and found the cause of the issue.
Setup:
Below are traces for PWM1 and PWM2, taken at different moments:
PWM pulses are most of the time happening almost at the same time, but regularly they get desynchronized (3rd screenshot) and get back to sync after a fraction of seconds.
Although the timing of the pulses are correct, the power supply of LED drivers are not perfect and draining current at different moments cannot be compensated by the capacitor.
For led drivers with high current, could we have PWM ensure that pulses are synced again? I will take a look at the waveform generator in between.
The text was updated successfully, but these errors were encountered: