Skip to content
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

LED flickering when saving settings to flash #191

Closed
xoseperez opened this issue Aug 27, 2017 · 15 comments
Closed

LED flickering when saving settings to flash #191

xoseperez opened this issue Aug 27, 2017 · 15 comments

Comments

@xoseperez
Copy link
Owner

Originally reported by: GaelZorro1980 (Bitbucket: GaelZorro1980, GitHub: Unknown)


Hi, I successfully flashed the last version 1.9.0 of the firmware to my Magic Home Led Controller (RGBW version) by setting esptool to DOUT mode. QIO, DIO or QOUT did not work.
When the light turns on, I can see flickering and flashes, right after it turns on and about every minute afterwards. Upon more investigation, I noticed it happens when the settings are saved to the flash. In the terminal it says "[SETTINGS] Saving".
I guess writing to the flash causes disruption with the PWM output.
Have you already seen this, is there an adjustment to make to prevent it?

@xoseperez
Copy link
Owner Author

Original comment by GaelZorro1980 (Bitbucket: GaelZorro1980, GitHub: Unknown):


Update after comparing to version 1.8.3:
In version 1.8.3, writing to the EEPROM happens at the same time as when the light is switched ON (or OFF), which results (on the 4 controllers I have tested at least) in an unpredictable bright flash just when the light is switched ON.
In version 1.9.0, writing to the EEPROM happens about half a second after the light is switched ON (or OFF), and then the settings are saved a few seconds later, each time the light flickers.

Would reducing the PWM frequency help with this issue at all?

@xoseperez
Copy link
Owner Author

it's a known issue. Will investigate further.

@xoseperez
Copy link
Owner Author

Reducing the frequency helps but does not removes the problem completely and only when close high values on one or two channels at most...

@xoseperez
Copy link
Owner Author

Original comment by GaelZorro1980 (Bitbucket: GaelZorro1980, GitHub: Unknown):


I've noticed that at the maximum value (255) the issue is almost gone. However my oscilloscope says the duty cycle is about 90-95% at most.
Maybe there's some clues on how to make it work better in this library, but I guess it would involve some heavy rewriting: https://github.com/StefanBruens/ESP8266_new_pwm

@xoseperez
Copy link
Owner Author

Original comment by GaelZorro1980 (Bitbucket: GaelZorro1980, GitHub: Unknown):


Upon more investigation here is what is happening:
Whenever there is any write to the flash (as when saving settings), the interrupt timer used for the PWMs is stopped for safety because the CPU does not have access to the flash for instructions. The PWM outputs are then stuck onto their current state (OFF, or fully ON). To solve this my understanding is that any functions called from the interrupt handler have to be stored in RAM, once that's done, the interrupt timer can be restored in its normal function.
That's something very specific to the ESP8266 which uses an external flash chip!
From what I've seen the PWM handler from the original SDK has been updated way back in 2015 (esp8266/Arduino@0c703b3), so maybe it's just a matter of enabling the interrupt timer.
Changing this is well out of my programming expertise unfortunately.

@xoseperez
Copy link
Owner Author

Original comment by GaelZorro1980 (Bitbucket: GaelZorro1980, GitHub: Unknown):


Espurna is great, and I'm currently running this firmware on more and more appliances!
But for lights the flickering hinders the WAF greatly.
I'm currently writing up a small firmware for the ESP8266 for controlling lights (waaaay less features, just an MQTT subscription to turn the LED ON/OFF remotely) and I have been adapting the LEDFader library (https://github.com/jgillick/arduino-LEDFader) which is great for adding animations.
If there's no way to get rid of the flickering when writing to flash, maybe a way to do it elegantly would involve either writing the settings before the light turns on, or once it is off, or just fading down for about 200ms then fading it back up.

@xoseperez
Copy link
Owner Author

Original comment by Haaland (Bitbucket: Haaland, GitHub: Haaland):


I solved this by removing persistence function, no more flickering when i set a new value.
it does not save the values anymore so this might not be a solution for everybody, but in my case i dont need persistence.
Persistance.png

@xoseperez
Copy link
Owner Author

Original comment by GaelZorro1980 (Bitbucket: GaelZorro1980, GitHub: Unknown):


Very nice! But it's too bad to lose the brightness memory. What I've done is I have made a new firmware which receives commands only from MQTT and uses a PCA9685 in combination with the LEDFader library for nice and smooth animations. If I suceed to integrate it in Espurna I'll post it here.

@xoseperez
Copy link
Owner Author

With version 1.9.6 you will be able to disable light color continuous saving by setting LIGHT_SAVE_ENABLED to 0. This will prevent flickering in most cases at expense of loosing the current color, unless you click the UPDATE button in the web interface.

@xoseperez
Copy link
Owner Author

LIGHT_SAVE_ENABLED (defaults to 1) available with 1.9.6

@xoseperez
Copy link
Owner Author

Current development version uses https://github.com/StefanBruens/ESP8266_new_pwm with NMI timer and flickering disappears. Will release it as 1.9.8 soon.

@xoseperez
Copy link
Owner Author

Original comment by GaelZorro1980 (Bitbucket: GaelZorro1980, GitHub: Unknown):


Wow, now that's great !

@xoseperez
Copy link
Owner Author

Released with 1.9.8

@xoseperez
Copy link
Owner Author

Removing milestone: 1.9.8 (automated comment)

@Emmegiemme
Copy link

Emmegiemme commented Feb 28, 2018

Hello,
sorry but I'm still having this issue (flickering leds) with the latest FW 1.12.3 on the MagicHome controller (I flashed the version 2.0); what am i doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants