Disabling interrupts?
Posted: Thu May 18, 2017 11:06 am
To simulate the trigger sequence of some equipment I tried using a sketch that is essentially the basic Blink example only with microsecond timing. The problem I did encounter was that the time it took for my loop to run through did vary. Mostly it finished after the expected 6687 us, but often it took longer. The additional time varied between 16 and 102 us. I suspected that I need to disable some interrupts and posted a request for some help here. By the time my post was approved I had figured out the solution, which requires 3 steps:
1. Disabling interrupts with noInterrupts(); in the loop() { }.
2. Avoiding to loop through the main loop() {} by using a while(1) { } for endless looping.
3. Feeding the watchdog in the endless loop with ESP.wdtFeed(); which requires loading the corresponding Esp.h file with:
Without it the ESP rebooted every 8.5 seconds.
Now my signal timing is stable with jitter of less than 100 ns.
1. Disabling interrupts with noInterrupts(); in the loop() { }.
2. Avoiding to loop through the main loop() {} by using a while(1) { } for endless looping.
3. Feeding the watchdog in the endless loop with ESP.wdtFeed(); which requires loading the corresponding Esp.h file with:
Code: Select all
extern "C" {
#include "Esp.h"
}
Without it the ESP rebooted every 8.5 seconds.
Now my signal timing is stable with jitter of less than 100 ns.