Specialist Supplier of Crystals & Frequency Control Componentssales@mecxtal.com.cn0755-26500570
MERLIN home / Rednote / Passive Crystals and Oscillator Circuits

An industrial PC's log goes backward after network time sync. Should you replace the battery and RTC crystal?

A warehouse computer boots displaying 9:00 a.m. Once connected to the network it shows 8:57, and the log lists "operation completed" before "operation started." Before marking the backup battery or watch crystal as faulty, ask two questions. Did the machine keep an approximately correct date while powered off? Which clock did the running program use for event order and timeouts? The two answers lead to quite different work.

An RTC with backup power can keep the date and time when the system is off. Linux can use it to initialize wall-clock time, the human-readable date and time on the display. The system may later correct that time against a network source. A program can also read a clock suited to duration measurement, such as a monotonic clock. Using the appropriate timebase for elapsed intervals avoids many problems caused by wall-clock corrections. Put boot-time accuracy and runtime timing on different lines of the acceptance requirement.

Log wall time, elapsed time and the hardware RTC side by side

Suppose the program records 9:00:00 after the machine has been running for 30 seconds. Twenty seconds later, network sync moves wall time back by 3 minutes, to 8:57:20. Subtracting the two wall-clock values gives minus 160 seconds. An elapsed-time measurement can still show that about 20 seconds passed. Replacing a working battery will leave the software fault intact. An application that uses wall time for a timeout may only show the fault the next time the network comes back.

Choose the elapsed-time clock deliberately. Linux's CLOCK_MONOTONIC suits many intervals after boot and normally excludes time spent suspended. If a timeout should include suspend, check the semantics of CLOCK_BOOTTIME against the application's state machine. The monotonic origin is established again after reboot, so values from different boots cannot simply be subtracted. Add a boot identifier to logs, use monotonic time for ordering within one boot, and retain calendar timestamps and their time source for audit.

Before network sync, capture the RTC reading, the system's wall time at boot, and the independent reference recorded before shutdown. Repeat using a controlled power-off duration. If the RTC resets to a default date, reports invalid time or shows a sudden large change after hours without power, check backup voltage, contacts and the chip's status. If it keeps reasonable time and the change occurs only after network connection, inspect time-sync policy, time zone, log forwarding and the clock used by the program. The open-circuit voltage of a removed battery is only one clue. Check its capacity, voltage drop under load and the board's switchover requirements before qualifying a substitute.

When it makes sense to investigate crystal frequency

If the saved date stays valid but the RTC loses a similar amount each day, run a longer offline check against an independent reference. A hypothetical loss of 2.16 seconds in 86,400 seconds corresponds to about −25 ppm. The estimate is the time difference divided by elapsed time. Display rounding, manual timing and synchronization services can distort a short measurement. Extend the run, retain original readings, record temperature and verify that nothing wrote to the RTC during the window. A new battery does not remove a stable frequency offset. Check whether the RTC provides a calibration mechanism when assessing the allowable frequency error.

The Linux RTC documentation notes that some configurations write the time back to the hardware clock after synchronization. An apparently corrected RTC reading while online could therefore be a recent software write. If the production machine must stay connected, reproduce the configuration on a bench unit. Avoid manually making a large time correction on the production host. Document allowed boot-time sources, when time is considered trustworthy and how events are marked when the network is unavailable.

Ask the supplier to identify the RTC or module part number, temperature range, valid backup-supply range and retention conditions. Ask the system vendor which synchronization policy is used and which clock drives timeouts. The test record should specify the duration without power, allowable accumulated error and whether a wall-time correction is permitted after reconnecting. Those fields help identify whether the next action concerns backup power, frequency accuracy or software.

If the display is always off by a fixed whole number of hours, separately check stored time and display time zone. If the error grows with power-off duration, estimate frequency error from the offline data. Use the same time representation at both ends so daylight saving, regional settings or export conversion do not look like hardware drift.

References

WeChat

MERLIN · TIMING COMPONENTS

Scan with WeChat to contact Sales

Add our WeCom contacts from your usual WeChat app.

On desktop, scan with your phone. On mobile, save the QR image and select it from your album in WeChat Scan.