-->
Page 1 of 2

ESP8266 TIMER INTERRUPT

PostPosted: Wed Apr 08, 2020 2:45 am
by SolomonShawn
Hey there...
I've been struggling with a timing problem and was hoping to maybe find some help here.
Essentially I've built an AC phase angle dimmer using an ESP8266. I've done this before using an ATmega328P and it works fine.
Essentially a pin change interrupt is triggered at the zero cross of the sine wave and I need the the ESP to pulse a pin high for half a millisecond or so a specific time after that. For example if the phase angle is set to 50 % the ESP would have to pulse a pin high 5000 microseconds later. On the ATmega I did this using one of the hardware timer without any issues. And I tried doing this using an ESP also with the hardware timer. Which does work, but the timing isn't stable. There is too much jitter. I've tried many different things. But so far the ONLY thing that has worked reliably (without jitter) is to delay the whole 5000 microseconds. The problem with that is that, if the phase angle is set to 10 % the ESP will jitter 9000 microseconds every 10000 microseconds so 90 % of the time. And will occasionally even crash due to watchdog resets.
Obviously delaying is a terrible solution. And I've been looking for a solution for a long time but I just can't find any way to do this. I even tried setting the hardware timer to earlier than necessary and then going into a while loop and waiting the last 1000 microseconds to ensure accurate timing. I tried doing it in the main loop and delaying the last X microseconds in a while loop to ensure accurate timing. But for some reason the jitters always persists. It seems as if micros() itself loses accuracy as soon as the processor does anything else in the meantime.

Re: ESP8266 TIMER INTERRUPT

PostPosted: Thu Apr 09, 2020 3:04 am
by schufti
not possible due to nmi in binary blob.
use boardsearch for x similar threads.

Re: ESP8266 TIMER INTERRUPT

PostPosted: Sat Apr 11, 2020 11:01 am
by AcmeUK
As I said in my reply to the same question posted on 5th March:-
You could use an Attiny85 as a slave interrupt generator, sending control commands over I2C.

You say:-
I've done this before using an ATmega328P

Then transferring the code to a Attiny85 should be easy.

Re: ESP8266 TIMER INTERRUPT

PostPosted: Sat Apr 11, 2020 9:54 pm
by rudy