Skip to Content
Circuitera

Choose whether Arduino timers skip missed periods

A task is due at 100, 200, and 300 ms.

0 of 3 complete · Progress saved on this device

Work out the example

A task is due at 100, 200, and 300 ms. If loop next runs at 350 ms, setting the saved timestamp to now deliberately drops missed work. Advancing it by the interval preserves phase and can expose a backlog.

With previous=0 and now=350, how many 100 ms deadlines have passed?

Decide what to check next

For a display refresh, one updated frame is often enough. For logging, a catch-up loop cannot reconstruct samples that never happened. Bound catch-up iterations if another task also needs CPU time.

Compare with the serial result

The bounded example prints 3 and leaves the saved deadline at 300.

Open the exact Uno example

The bounded example prints 3 and leaves the saved deadline at 300.

void setup() {
  Serial.begin(9600);
  uint32_t last=0;
  const uint32_t now=350;
  byte due=0;
  while (now-last>=100 && due<4) {last+=100; ++due;}
  Serial.println(due);
}
void loop() {}

Verified with [email protected] on Uno R3 (2026-12-05 UTC). This check did not use physical hardware.

Continue learning

Sources