Skip to content

[PWM] Fix led flickering#5503

Open
chromoxdor wants to merge 3 commits intoletscontrolit:megafrom
chromoxdor:fix-pwm-flickering-led
Open

[PWM] Fix led flickering#5503
chromoxdor wants to merge 3 commits intoletscontrolit:megafrom
chromoxdor:fix-pwm-flickering-led

Conversation

@chromoxdor
Copy link
Contributor

I use the PWM command to fade LED stripes. After updating to a recent build, I realised that when calling the PWM command, it causes the PWM-pin to reinitialise every time, which leads to a flicker of the LEDs even when issuing the command with the same duty cycle.

Not sure if my changes are perfect, but they solve the problem for me.

Comment on lines +190 to +193
value = adapt_ledc_frequency_resolution_duty(frequency, resolution, value);
ledChannel = attachLedChannel(pin, frequency, resolution);
lastPin = pin;
lastFreq = frequency;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the formatting is off here 🤔

return ledChannelFreq[ledChannel];
# else // if ESP_IDF_VERSION_MAJOR < 5
ledcWrite(pin, value);
ledcWrite(pin, value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why that space was added, formatter generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question and i have no answer to that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like I forgot to do a last format...

value = adapt_ledc_frequency_resolution_duty(frequency, resolution, value);
int8_t ledChannel = attachLedChannel(pin, frequency, resolution);
// Only update frequency & attach channel if pin/freq changed
if ((lastPin != pin) || (lastFreq != frequency)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there were also functions in the ledC class to query the actual used frequency.
So this way you don't need to rely on locally kept states as the ledC class can also be used outside of our ESPEasy wrapper functions.

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

Successfully merging this pull request may close these issues.

3 participants