Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By maxhack
#43082 Am using Arduino IDE to write programs for ESP-01 module, latest application was supposed to be an AC light dimmer using zero detect circuit, AC frequency is 50 Hz thus zero cross is detected every 10 mS (2 crosses in each cycle)

light is dimmed correctly but keeps flickering every few seconds, when I checked with oscilloscope I found out that interrupt does not occur after same exact time after zero cross detection, it has a noticeable error of around 120 uS (I also used function micros() to check each time interrupt occurs, it gave same result as digital oscilloscope)

I think that this instability causes light flickering, any ideas how to solve?

I send commands to light via normal webserver where ESP reads URL and extracts needed dimming level from it, the interrupt code I use is written below:

void zero_crosss_int(){
dimtime = (75*light_val); // For 60Hz =>65
delayMicroseconds(dimtime); // Wait till firing the TRIAC
digitalWrite(L1, HIGH); // Fire the TRIAC
delayMicroseconds(10); // triac On propogation delay
// (for 60Hz use 8.33) Some Triacs need a longer period
digitalWrite(L1, LOW); // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

In setup function I use this code:

pinMode(zero_pin, INPUT_PULLUP);
attachInterrupt(zero_pin, zero_crosss_int, FALLING);

Thanks in advance.
User avatar
By RDHeiliger
#43116 Don't have an answer for you, another example of problems with interrupts. May be a good place to begin a discussion.
I am trying to use an interrupt to count pulses from a flow sensor. At 1Hz pulse rate the code works fine. At 400 Hz the ESP resets with the below output. Looks to be a wdt (watch dog timer) in the system code. Don't know enough about the error message that is output to diagnose the actual problem. Have tried other pins for inputs with same result. Have also run program without the serial output lines, with same result.

My simplified code:
Code: Select allvolatile unsigned int flowOneCounts = 0;
volatile unsigned int flowTwoCounts = 0;
const int ioPower = 14;
//function definitions
void flowOneInterupt();
void flowTwoInterupt();

void setup()
{
  Serial.begin(115200);
  pinMode(ioPower,OUTPUT);
  digitalWrite(ioPower,HIGH); //turn on power to IO

  attachInterrupt(digitalPinToInterrupt(12),flowOneInterupt,RISING);  //count pulses on collector A0 pin flow 1 on board
  attachInterrupt(digitalPinToInterrupt(13),flowTwoInterupt,RISING); //count pulses on  house A1 pin flow 2 on board
}

void loop()
{
       for(int x = 0; x <1000;x++){
         Serial.print("flow2 counts  "); Serial.println(flowTwoCounts);
         yield();
         if(flowTwoCounts > 1000) flowTwoCounts = 0;
         delay(10); //sending flow and analog counts to sprinkler control
       }
}

 /*************************************************************************/
  //-----accumulate counts from flow sensor one, on pin2, interupt 0
  void flowOneInterupt()
    {
    flowOneCounts++;  //counter rolling over is corrected on main board
   
    }

  /*************************************************************************/
  //-----accumulate counts from flow sensor two, on pin3, interupt 1
  void flowTwoInterupt()
    {
    flowTwoCounts++;  //counter rolling over is corrected on main board
   
    }


The error message output after about 10 seconds running with 400 Hz input frequency:
Code: Select allException (0):
epc1=0x402023f8 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: sys
sp: 3ffffc30 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffdd0:  40106ec4 80af1999 3ffe8dbc 00000030 
3ffffde0:  ffffffff 00000020 40240000 ffffff1a 
3ffffdf0:  40106f28 00000006 42d60000 00000022 
3ffffe00:  3fffc200 40106e8c 3fffc258 4000050c 
3ffffe10:  4000437d 00000030 00000019 ffffffff 
3ffffe20:  60000200 00000008 7c037c02 80000000 
3ffffe30:  20000000 3fff0678 80000000 2007c180 
3ffffe40:  80000000 3fffc6fc 00000001 3fff067c 
3ffffe50:  00000174 0007c180 60000600 00000030 
3ffffe60:  ffffffff 3fffc6fc 00000001 00007a12 
3ffffe70:  40106f28 04111e70 60000600 00000030 
3ffffe80:  ffffffff 00000020 ffffffd1 3ffe9c1c 
3ffffe90:  00000000 00000000 0000001f 401016d1 
3ffffea0:  4000050c 40106e8c 3fffc258 4000050c 
3ffffeb0:  40000f68 00000030 00000014 ffffffff 
3ffffec0:  40000f58 00000000 00000020 00000000 
3ffffed0:  feefeffe 3ffe9164 00000000 fffffffe 
3ffffee0:  ffffffff 3fffc6fc 00000001 3fffdab0 
3ffffef0:  00000000 3fffdad0 3ffeeb30 00000030 
3fffff00:  00000000 400042db 3ffe9c57 60000600 
3fffff10:  40004b31 3fff04fc 000002f4 0007c000 
3fffff20:  4010234e 3ffe8870 3ffe9010 4010724c 
3fffff30:  40211bc1 3ffe9010 3ffe8870 04127520 
3fffff40:  3fff04fc 00001000 4021205a 00000008 
3fffff50:  00000000 00000000 40212107 3ffe90c4 
3fffff60:  3ffe8870 4020502d 3ffe8cdc 40201018 
3fffff70:  4020502d 60000600 3ffe9468 4020502d 
3fffff80:  40205072 3fffdab0 00000000 3fffdcb0 
3fffff90:  3ffe8880 3fffdad0 3ffeeb30 40202713 
3fffffa0:  40000f49 0004a564 3fffdab0 40000f49 
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)


 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset
User avatar
By maxhack
#43175 Dear RDHeiliger,

I do have that issue appear sometimes also, you are right we do need a good discussion here, for me am currently focused on finding a method to make high priority interrupts or a better way to make AC dimming with ESP standalone, and for you it is finding a solution for WDT reset
User avatar
By Vermut
#43616 I'm facing similar issues. In a test setup with 8MHz clock generator connected to GPIO pin it seems only able to process ~400k interrupts per second (very rough value but obviously less than 8M). Dies from WDT as well because there is no CPU time to execute anything else.

Interrupt function is:
Code: Select allvoid blink() {
  i++;
}