These are chat archives for esp8266/Arduino

Feb 2018
Feb 13 2018 15:33
@me-no-dev I've tried that. it's likely that there's some other interrupt, can't figure out where and why it's on the same priority like NMI timer1. I've also tried to disable interrupts without success. I'm using your ESPAsyncWebServer, btw.
Feb 13 2018 15:50

I'm trying to create a AC mains dimmer that emulates a hue bridge for Alexa.
Hardware-wise, I have a zero-crossing interrupt at one GPIO that edge-interrupts at very half-wave, i.e. 100Hz in my case. The timer should then switch on the load after some delay which depends on the current bightness level. (0-10ms in e.g. 64 steps)

I've tried two approaches:

1) using NMI timer in single shot mode; upon a zero-crossing interrupt, first I'm setting timer by loading T1L directly, and turning the load off. The timer callback turns on the load after a time that depends on the desired brightness level.

2) using a free-running NMI timer in loop mode, with a resolution of n dimmer-levels (i.e. period time / levels, e.g. 64), and a volatile loop counter that increments every timer tick and is reset upon every zero crossing. Now, in the timer-isr, if the loop counter > desired dimmer level, the load is turned on.

Both approaches work but experience the same ~1-2ms jitter. Using the timer alone seems to work fine in either mode and is accurate, even with the web server active.
I've experimented with loading the timer in various places, tried to disable interrupts in "right" place and using compensation values for the timer to acciount for cpu cycles consumed, but I can't get it to work w/o jitter.

Me No Dev
Feb 13 2018 16:45
@0xPIT have you tried with WiFi off? maybe the radio is what is interrupting you?
1-2ms is quite the jitter...
I could expect 1-2us, but thousand times that is too much
Michael Miller
Feb 13 2018 20:30
@0xPIT There is a interrupt in the WiFi core that can't be disabled and will cause issues. I ran into it two years ago when I was writing my NeoPixel support for Esp8266. The summary of that investigation and work was, I had to use hardware and you can't disable the interrupt or else you will run into resets. So, I don't think it will get better for you.
You can put a small AVR (one of the tiny) that just does the AC management and let the esp8266 do all the high level work.
Feb 13 2018 20:49
thanks for the hint, @Makuna I can't use extra hardware, there's so space left in the enclosure :)
with wifi off it would defy it's purpose, @me-no-dev
Michael Miller
Feb 13 2018 21:06
By hardware, I mean either external or internal. I gave an external example. Internally, their is a DMA hardware that I use, so I provide a buffer that it constantly sends the output (which includes the ability to loop the buffer or trigger an interupt) that is pretty accurate and not effected by the WiFi interrupt. You might be able to set it up to control the output you want but it will takes some creative thinking.