External interrupt is delaying after a while
- Dominant language
- C++
- Stars
- 16.7k
- Forks
- 13.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Basic Infos
- [x] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [x] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [ ] I have tested that the issue is present in current master branch (aka latest git).
- [x] I have searched the issue tracker for a similar issue.
- [x] If there is a stack dump, I have decoded it.
- [x] I have filled out all fields below.
#### Platform
- Hardware: [ESP-12]
- Core Version: [2.6.3]
- Development Env: [PlatformIO]
- Operating System: [Linux Mint]
### Settings in IDE
- Module: [Generic ESP8266 Module]
- Flash Mode: [dio]
- Flash Size: [4MB]
- lwip Variant: [Higher Bandwidth]
- Reset Method: [nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz]
- Upload Using: [OTA]
### Problem Description
I'm having a trouble with external interrupt measuring zero cross in AC 60 Hz. In high level, my trouble is that my lamp after a while turn off per 2 seconds and turn on again. The frequency for this problem to occur is variable, so 3 times per day, twice/day, sometimes working two days consecutive without problem. I am monitoring the problem over osciloscope and I captured the image below:

Line yellow: hardware zero cross
Line green: LED inverting each zero crossing (60 Hz - frequency, 16,666 ms - period)
It seems that my ISR keeps accumulating and after a while releases a bunch of execution at once. I already got this same problem with software timer. I think this problem is because some task in wifi is harding and the priority wifi is high over external interrupt. Someone has any idea about the solution to this problem? I tried include noInterrupts() and interrupts() inside my ISR but it isn't successfull.
Thanks folks
### [MCVE](https://stackoverflow.com/help/mcve) Sketch
```cpp
#include
bool flagInvert{false};
static void ICACHE_RAM_ATTR ZeroCrossISR(void)
{
noInterrupts();
digitalWrite(2, flagInvert);
flagInvert ^= 1;
// some logical that isn't relevant to problem
interrupts();
}
void setup() {
pinMode(5, INPUT);
pinMode(2, OUTPUT);
attachInterrupt(5, ZeroCrossISR, FALLING);
WiFi.setSleepMode(WIFI_NONE_SLEEP);
WiFi.begin("MY_SSID", "MY_PASS");
}
void loop() {
}
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.