A controller uses a 32-bit unsigned millisecond timestamp that wraps modulo 232=42949672962^{32}=4294967296232=4294967296. A scheduled action uses this test, with all three variables declared as the same 32-bit unsigned type:
if (now - previous >= interval) { // Perform the action. }
The saved timestamp is previous = 4294967271, the current timestamp is now = 39, and interval = 60. The true elapsed time since the saved timestamp is less than one full wrap. Which conclusion is correct?
The elapsed time is 64 ms, so the action is due.
The elapsed time is 63 ms, so the action is due.
The elapsed time is negative, so the action is not due.
The elapsed time is 39 ms, so the action is not due.
Unlock full course notes by signing up
Selecting the timer compare value
A 16-bit hardware timer receives an ideal 20.0 MHz clock through a prescaler that divides the clock frequency by 8. Its configured cycle contains one tick at each count from 0 through compare value CCC, inclusive, and then repeats. What compare value produces a 0.800 ms event period?
Clock readings versus physical waiting time
In a microcontroller simulation, a clock has a timing resolution of 4 μs: its reported time changes only in 4 μs steps. The reading is 0 μs at real time 0 μs, becomes 4 μs at real time 4 μs, becomes 8 μs at real time 8 μs, and continues in this pattern. Between updates, the reading remains unchanged.
Let C(t)C(t)C(t) be the clock reading at real time ttt. A custom delay routine saves C(tstart)C(t_{\text{start}})C(tstart) when called. It then checks the clock at the start time and every 1 μs afterward, returning at the first check satisfying
Scheduled references and late execution
Two controllers each initialize previous = 0 and use a 50 ms interval. Both check the following condition only at timestamps 50, 110, 150, and 200 ms:
Policy A updates previous = now. Policy B updates previous += 50UL. All timestamp arithmetic is unsigned, no rollover occurs, each check executes the condition once, and the update and action take negligible time.
Which pair of action histories is correct, and which policy preserves the original 50 ms scheduling grid?
Budgeting completion lateness
An embedded controller must complete a one-time action shortly after a requested deadline. Its completion lateness is the elapsed time from that deadline until the action finishes.
The design uses these timing bounds:
Hardware sets an expiry flag on the first 1.00 ms clock tick at or after the requested deadline. Use 1.00 ms as an inclusive upper bound on this tick wait.