IMDTouchKnowledge BaseShop main store

How-to

How to Send HMI RTC Time to a PCB Over Modbus

Industrial networks Published 8 min read

Short answer

Modbus never broadcasts the panel clock. Configure the HMI as a Modbus client and let it write six holding registers — year, month, day, hour, minute, second — with function code 16 about once per minute, capturing all six values as one snapshot so a rollover never mixes an old date with a new time.

On this page
  1. Does Modbus move the HMI clock by itself?
  2. Which device should be the Modbus client?
  3. Which registers carry the time on the PCB?
  4. How do you capture the clock without a rollover mix?
  5. How do you write all six registers in one request?
  6. How often should the HMI push the time?
  7. How do you commission the transfer step by step?
  8. What should the PCB do when the link goes down?
  9. Questions asked

Configure the HMI as a Modbus client and write six consecutive holding registers — 40001 through 40006 carrying year, month, day, hour, minute and second — with function code 16 (0x10) once per minute, capturing all six values as one snapshot. Modbus will not carry the panel clock anywhere by itself: the two classic failure points are the register contract, because a 16-bit number means nothing until both ends agree what it is, and the rollover, where a date captured at 23:59:59 gets paired with a time captured at 00:00:00. The procedure below fixes both: one snapshot, one write, one read-back.

Does Modbus move the HMI clock by itself? #

No — the Modbus specification defines no clock or time broadcast: nothing leaves the panel until a client device reads or writes registers, so the panel itself must act as the client and push its clock values out.

The application protocol services are reads and writes of bits and 16-bit registers. A register holding 2026 is indistinguishable from one holding a count of 2026; only the contract between your HMI application and the PCB firmware gives the number a meaning. No service on any transport announces a value as "the time."

Before any communication work, confirm the panel software exposes its runtime clock components — typically year, month, day, hour, minute, second — as readable variables, and offers a script, macro or scheduled action that copies them to external variables in the deployed runtime, not only in the editor preview. A clock drawn on a screen can format time internally without exposing a single component. If the software offers only that, stop this design: either reverse the roles so the PCB is the time source and the panel displays its registers, or replace the panel, applying the criteria in selecting a Modbus TCP HMI panel for an existing controller.

Which device should be the Modbus client? #

Make the HMI the client that writes to the PCB, because a PCB serving six writable holding registers is the arrangement almost every firmware supports and it keeps the update schedule in the panel you configure.

The alternative — the PCB polling the HMI as a Modbus server — dies at the first gate, because most panels expose only application variables in their server map, not the clock. You would end up scripting the clock into variables anyway, so the write direction costs nothing extra and removes the polling task from the PCB.

Transport settings follow the standard. On a serial link, the Modbus serial-line specification requires 11-bit characters — 8 data bits with even parity and one stop bit, or no parity and two stop bits — plus identical baud rate and station address at both ends. On Modbus TCP, reach the PCB's IP address on the registered port 502 and set the unit identifier to the value its documentation names. For a point-to-point serial cable, the pinout work is the same as building the RS-232 Modbus cable between an HMI and a controller.

Which registers carry the time on the PCB? #

Use six consecutive holding registers — year, month, day, hour, minute, second — each a 16-bit integer: for example 4x references 40001 through 40006, which travel in the request as protocol addresses 0 through 5.

4x reference Protocol address Field Range Sample at 14:07:33, 15 Jan 2026
40001 0 Year full year, 16-bit 2026
40002 1 Month 1-12 1
40003 2 Day 1-31 15
40004 3 Hour 0-23 14
40005 4 Minute 0-59 7
40006 5 Second 0-59 33

Commit to three choices and write them into the PCB protocol document: plain binary encoding rather than BCD, the full year rather than an offset (2026 fits a 16-bit register, which spans 0 to 65535), and a block that collides with nothing else in the PCB map. Watch the address labels: engineering tools number holding registers from 40001 while the request on the wire carries the zero-based address, so 40001 is address 0. Prove the convention once by writing a distinctive value such as 61 to a spare writable register and reading it back before you trust all six fields.

How do you capture the clock without a rollover mix? #

Read all six components in one instant and stage them unchanged until the write finishes, because reading components one by one across a minute or midnight rollover can merge an old date with a new time that the PCB cannot detect.

If the HMI software offers a documented snapshot function for its clock, use it. Otherwise use read-and-recheck: copy the six components into staging variables, then read the second a second time; if the two second values differ, a rollover fell inside the sample, so discard it and wait for the next cycle. Check the captured set against the calendar ranges — month 1 to 12, day 1 to 31, hour 0 to 23, minute and second 0 to 59 — before it leaves the panel. Have the PCB repeat the same validation on arrival and apply the set only when all six fields are present and valid.

How do you write all six registers in one request? #

Use function code 16 (0x10), Write Multiple Holding Registers: one transaction carries all six registers as twelve data bytes, so the PCB applies the whole set or none of it.

The specification allows 1 to 123 registers per function-16 request, so six sits far inside the limit. For the staged sample 14:07:33 on 15 January 2026 at 40001, the request is: function 0x10, start address 0x0000, quantity 0x0006, byte count 0x0C (6 registers × 2 bytes per register = 12), then the data words 0x07EA (2026), 0x0001 (month 1), 0x000F (day 15), 0x000E (hour 14), 0x0007 (minute 7), 0x0021 (second 33). The PCB answers with the function code, start address and quantity, and applies the clock only after that response is sent.

If the PCB map forbids multi-register writes, fall back to function code 06, one register per write, with a commit trigger: write year through second into 40001 to 40006, then write a 1 into a seventh register as a commit flag, and have the PCB apply the six values on that flag and clear it. Never let the PCB apply a partially written set.

How often should the HMI push the time? #

Once per minute, which holds the PCB clock within about two milliseconds of the panel between writes on a ±20 ppm crystal and stays far below traffic that would burden a serial link.

Run the numbers with an illustrative ±20 ppm crystal: free-running drift is 86,400 s × 20 ÷ 1,000,000 = 1.73 s per day. Between once-a-minute writes the accumulated error is 60 s × 20 ÷ 1,000,000 = 1.2 ms. Even an hourly write accumulates only 1.73 ÷ 24 = 0.072 s, so once per minute is generous; drop to hourly only when the link is shared and loaded, never to once per second. Skip the write whenever the staged sample equals the last applied one, so a settled link stays quiet.

One safety rule: never trigger machine actions from equality against the transferred time registers. A missed write or a rollover mix can skip or double the comparison, so scheduled motion belongs in the controller's own program, with the transferred time used for stamping only.

How do you commission the transfer step by step? #

Read one known register from the PCB before touching any time logic, because a failed first transaction is a connection or configuration problem and time conversion layered on top of it only hides the fault.

  1. Set the panel clock against a reference and correct it first; the panel's error becomes the PCB's error.
  2. Match the transport exactly as the PCB documentation states: baud, parity, stop bits and station address on serial, addressing on TCP.
  3. Read a known diagnostic register from the PCB with function code 03 and verify the value; if nothing comes back, clear the physical layer using fixing HMI Modbus device no response over RS-485 before going further.
  4. Map the six HMI external variables to 40001 through 40006 and confirm the address convention with the scratch-register write and read-back.
  5. Put the six clock components on a temporary panel screen and watch the seconds advance.
  6. Enable the snapshot logic and force a rollover test: set the panel to one minute before midnight and confirm the PCB accepts one coherent set, not a mix.
  7. Enable the one-minute update cycle, then read the PCB's applied time back and compare it against the panel.
  8. Pull the link, confirm the PCB flags its time as stale and keeps running, then restore the link and confirm the next complete sample is applied.

Keep its own clock running and mark the time as stale, applying the last accepted sample, free-running on the local crystal, and recording how long ago the last write succeeded so logs can tell synchronized time from free-running time.

The clean mechanism is a status word the PCB maintains itself — one bit for clock valid, one for synchronized within the last hour, for instance — that the HMI can read like any other register. Decision: give the PCB a battery-backed clock and treat every transfer as a correction. The panel then never owns the PCB's time base, a rebooted or wrong-set panel cannot stamp a bad time into event logs unnoticed, and the staleness flag tells every downstream consumer what the timestamps are worth.

Questions asked

Should the six registers carry local time or UTC?

Local civil time, for a single-site machine: the PCB applies the value directly, operators read logs that match the wall clock, and no device converts anything. Choose UTC only when a second system consumes the timestamps and does its own conversion; then both ends must document the offset. If the site observes daylight saving, the panel clock follows it and the PCB follows the panel, so the change arrives as an ordinary one-hour correction.

Can I send one Unix timestamp instead of six registers?

You can, but a 32-bit epoch count (seconds since 1970-01-01) spans two holding registers, and both ends must agree on word order — high word first or low word first. A mismatch produces a date far in the past or future with no error anywhere. Stay with six component registers unless the PCB firmware is already fixed to epoch format; components need no arithmetic and decode at a glance.

Why does the year arrive as 26 instead of 2026?

The panel published year minus 2000 while the PCB decoded a full year — 26 instead of 2026 is exactly that offset. The Modbus request carries only the number; nothing in it marks the base. Fix the contract so exactly one side changes: send the full year from the panel, or have the PCB add 2000 to the received value, and record the choice in the register map document.

Does the PCB still need its own battery-backed clock?

Yes. Treat the Modbus transfer as a correction, not as the clock itself: the PCB free-runs between writes, survives a panel or link failure, and reports how old its last accepted sample is. Without a local clock the PCB is blind whenever the link is down, and events logged during that gap carry no trustworthy time at all.

How do I stop the PCB clock from stepping backward?

Have the PCB accept a new sample only when it differs from its running clock by at least two seconds. Second-to-second jitter and rounding then never reset the clock, while genuine corrections — drift, a daylight-saving change, an operator setting the panel clock — always pass the gate. Record the guard band alongside the register contract so both behaviors stay predictable.

Keep reading

  • Troubleshooting

    Fixing HMI Modbus Device No Response Over RS-485

    Device no Response means the slave never returned a valid frame to that request. When a PC polling tool reads the same scanner, the bus is probably carrying two masters: run one master at a time, then copy the known-good read's serial settings, station address, and register offset into the HMI.

    HMI and touchscreens

  • Troubleshooting

    Why HMI Indicators Stay Off Over Modbus RTU Polling

    Indicators on internal tags animate from HMI memory with no serial traffic; an indicator bound to a PLC tag needs a completed Modbus RTU read of the right address in the right data area. Confirm the PLC bit changes, then read the request and response, then fix the address at one known point.

    HMI and touchscreens

  • How-to

    Connecting an XBTGT HMI to an M241 PLC over Modbus TCP

    Delete the Generic Modbus TCP slave from the M241 device tree and activate the Modbus server on the controller's Ethernet interface instead — that slave makes the M241 a client, so both devices poll and neither answers. Then map Vijeo Designer driver address 40001 to PLC word %MW0, keep TCP port 502 open between panel and controller, and shift the address map by one word if a test read lands one register off.

    HMI and touchscreens