Inconsistent loop timing

Hello All, I seem to be missing something. Not sure if this is hardware or software related. I have a very simple program to program some electronic loads between 2 different values. The issues is the loop timing is changing (not stable).

So I created a very simple program to pulse a pin, wait 10ms and repeat.

void loop() // run over and over again {

digitalWrite(ledPin, HIGH); // sets the LED on delay(10); digitalWrite(ledPin, LOW); // sets the LED off delayMicroseconds(1000);

}

The issue is the pulse to pulse timing bounces around, between 10.24 to 11.24 and sometimes to 12.24mS.

Is this normal to expected this.

Thanks for any insight into this issue. -pete

Yes, this is normal. The delay() function begins by taking a snapshot of the current millisecond timer (millis()) then waits in a loop until millis() reaches the snapshot+delay time.

So there are some potential inaccuracies here. If the millis() timer increments right before the snapshot is taken, the delay will be "long", else if it increments right after, the delay will be "short". A variance of +/-1ms is not surprising. I think this explains the 10.24ms/11.24ms issue, but I'm not so sure about the 12.24ms one.