Exactly every second the main loop becomes much longer -why?
Posted: Mon May 03, 2021 12:38 pm
I already did some research, couldn't find the answer. This may be similar to other questions posted here regarding the jitter of the main loop timings on ESP8266, but my issue is more specific. What I observe is that on average my minimal main loop timing is 4.4 us (160 MHz CPU clock rate), but exactly every second it becomes ~54 us. In other words, every second a ~50 us long event (interrupt?) happens. This messes up my algorithm (precise control of a stepper motor, for a focus stacking rail control) which I am trying to port from Arduino Nano to ESP8266. (In Arduino timings are much more consistent: the longest loop is only 30% longer than the average loop.)
To this point I tried to disable WiFi (I don't need it):
(this helped a bit - from 64 us the long loops went down to 54 us). I also tried to disable all interrupts (didn't help at all):
What can be possibly happening at exactly 1 second interval? My thinking is that it must be somehow related to WiFi, because for anything else 1 second is ginormous (in terms of CPU cycles). Perhaps the commands I used didn't completely disable WiFi and/or related interrupts?
Anything else beside WiFi could be the culprit? I am trying to figure out NMI - can it be at fault here? I don't use PWM in my code, so perhaps I can somehow disable NMI and/or PWM?
I am using Arduino IDE in my setup.
Thanks for any input.
To this point I tried to disable WiFi (I don't need it):
Code: Select all
WiFi.disconnect();
WiFi.mode( WIFI_OFF );
WiFi.forceSleepBegin();
(this helped a bit - from 64 us the long loops went down to 54 us). I also tried to disable all interrupts (didn't help at all):
Code: Select all
noInterrupts();
What can be possibly happening at exactly 1 second interval? My thinking is that it must be somehow related to WiFi, because for anything else 1 second is ginormous (in terms of CPU cycles). Perhaps the commands I used didn't completely disable WiFi and/or related interrupts?
Anything else beside WiFi could be the culprit? I am trying to figure out NMI - can it be at fault here? I don't use PWM in my code, so perhaps I can somehow disable NMI and/or PWM?
I am using Arduino IDE in my setup.
Thanks for any input.