-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closed
Labels
Description
Something seems to be wrong with the way how interrupts are handled.
I'm trying to record pulses of length 250-2000 micros. Example sketch:
volatile int lastTime = 0;
void setup()
{
Serial.begin(115200);
attachInterrupt(2, pinChanged, CHANGE);
}
void loop()
{
}
void pinChanged()
{
int time = micros();
int duration = time - lastTime;
Serial.print(duration);
Serial.print("\r\n");
lastTime = time;
}
But this outputs something like:
76131
3683
76143
3752
76146
3667
76128
3768
76141
3741
76148
3661
76114
3785
76130
3683
...
I exprected numbers around 250-2000. It's stange that its almost all time a longer dealy and then a shorter. I double checked the wiring and the interrupts only occure with connected sensor.
I did the same using nodemcu (using gpio.trig
) and got ver accurate timings.
Any ideas what is going wrong here?