Elapsed Time Goes Negative After Clock Sync? Use the Right Clock
- PLC Play Ground
- 0
- Posted on
Wall-clock corrections can break duration calculations that subtract calendar timestamps. Use a supported monotonic timing mechanism for elapsed intervals.
Original clock example; select the equivalent supported facility in the PLC runtime.
What is happening?
Calendar time answers when an event occurred; monotonic time supports elapsed-time measurement without backward wall-clock adjustments. Availability, resolution, rollover, and persistence depend on the runtime. Values from unrelated clock domains should not be subtracted.
Check these five things
-
Identify the clock source used by the duration calculation.
-
Check whether synchronization can step that clock.
-
Review supported timer or monotonic facilities.
-
Define behavior across restart and rollover.
-
Test clock adjustments in an offline environment.
Worked example
A teaching operation starts at wall time 10:00:10. The clock is corrected backward to 10:00:05 before completion at 10:00:07. Calendar subtraction gives minus three seconds even though time elapsed normally. A monotonic interval avoids that wall-clock discontinuity.
Quick diagnostic reference
| Need | Clock concept |
|---|---|
| Event date | Calendar timestamp |
| Elapsed duration | Monotonic interval |
| Cross-device sequence | Synchronized time with quality |
The mistake to avoid
Do not replace event timestamps with opaque monotonic values in historical records. Store the appropriate time representation for each purpose.
How to verify the fix
Verify normal intervals, clock corrections, restart behavior, and maximum duration using the runtime documentation and test model.
Field-work boundary: These are educational diagnostic guides. Use the exact equipment manuals and approved site procedures. Electrical testing and machinery changes belong to qualified, authorized personnel; control hazardous energy and validate affected functions before release.
Technical reference
Python documentation: Wall and monotonic clocks. The examples and diagnostic tables above are original teaching material; they do not replace the product manual.
