IMDTouchKnowledge BaseShop main store

How-to

Magelis STU clock synchronization from a Modicon M241 PLC

HMI and touchscreens Published 7 min read

Short answer

Reading the M241 SYSTIMEDATE values on a numeric display proves the Modbus link, not the clock write. Each SYSTIMEDATE field is a 32-bit DINT spread over two holding registers, while the terminal clock dialogue table wants separate integer calendar fields in a fixed order. Publish a PLC snapshot buffer that converts each field to that integer width and apply it once on a sequence value.

On this page
  1. What the M241 publishes and what the STU clock needs
  2. Example: forcing the year field to 2024 to prove the register layout
  3. Choose where the conversion runs
  4. Synchronization procedure
  5. When the terminal clock still will not take the write
  6. Questions asked

Synchronizing a Magelis STU clock from a Modicon M241 is a two-layer job, and the layer that fails is the conversion. The M241 exposes date and time through its SYSTIMEDATE block, where every field is a DINT spread across two Modbus registers, while the terminal's clock dialogue table consumes separate plain integers. A numeric display that shows the correct time proves the Modbus path, not the clock write. Publish a snapshot buffer in the PLC, convert each field once to the integer width the dialogue table expects, and let the terminal apply the clock in one shot on a sequence value.

What the M241 publishes and what the STU clock needs #

The M241 serves its %MW variables as Modbus holding registers, and the HMI's driver reads and writes them there. Roles follow the traffic, not the project labels: the device that initiates each request is the Modbus client and the device that answers is the server, so a terminal that polls the controller is the client even if the PLC was configured as one. Prove the working direction with a non-clock test value before you touch the clock at all.

Each field in the SYSTIMEDATE block is a DINT, and a DINT spans two consecutive holding registers, because a Modbus register carries 16 bits. Modbus defines the register, not how a multi-register value splits across a pair, so word order is a setting of whatever reassembles the pair on the HMI side, and a wrong setting reads a plausible wrong number. The clock dialogue table does not accept a two-register DINT at all: it takes one integer per calendar field — year, month, day, hour, minute, second — in the order its own table documents. Each of those components fits a signed 16-bit integer, the range running from -32768 to 32767, with the year the largest component. The type gap — IEC time data in the PLC against plain integers in the terminal — is the entire fault, and correct addressing alone never closes it.

Example: forcing the year field to 2024 to prove the register layout #

This test identifies the driver's word order for a DINT pair before any clock logic is involved, using a value that cannot be misread.

  • Forced value: the SYSTIMEDATE year field, a DINT, forced to 2024 in the PLC for the test — chosen because its two register words differ.
  • Register width: each Modbus holding register carries 16 bits, so the DINT sits in two consecutive registers.
  • Reassembly rules in circulation: value = first word + 65536 × second word, or the same computation with the words exchanged.
  • Instrument: a numeric display on the raw register pair.

The rule in words: a DINT splits into a low word, the remainder of a division by 65536, and a high word, the integer part of that division. A driver that reads the pair back to front multiplies the wrong word by 65536, which is why the display shows a huge number instead of a small one.

The arithmetic: 2024 ÷ 65536 = 0 with remainder 2024 (hex 07E8), so the registers hold 0 and 2024; read in the expected order the display gets 2024 + 0 × 65536 = 2024, and read word-swapped it gets 0 + 2024 × 65536 = 132,644,864.

The result: the numeric display shows one of exactly two numbers — 2024 or 132,644,864 — and the number itself identifies the word order with no second test.

The decision: if the display shows 132,644,864, reverse the driver's word order for that tag or exchange the two register references, and retest until the display matches the forced value; run the same forced-value test on every clock field before releasing the force. The snapshot buffer in the rest of this article removes this failure mode from the finished application, because every buffer field is a single 16-bit register with no word order to choose.

Choose where the conversion runs #

Approach Who converts When it fits
PLC snapshot buffer — use this one The M241, on request One controller feeding one or several terminals; the mapping survives driver or terminal changes
Map the DINT registers directly The HMI driver, tag by tag The PLC cannot be changed; you own word-order, signedness and width settings on every clock tag permanently
Terminal writes the PLC clock The terminal Operators set plant time at the panel

Take the first row. The M241 stays the single time authority, the conversion lives in one scan of one program, and the clock dialogue table receives exactly the one-integer-per-field layout it expects. The third row is the reverse job — setting the controller clock from the panel — and it has its own field-mapping traps, covered step by step in Set a Premium PLC Clock From a Magelis HMI Over Unitelway. Whichever row you pick, one device writes and the other obeys; two automatic correctors chase each other's values, which is the same mechanism that lets a timed HMI write corrupt controller clock registers — documented for a PanelView against an SLC in Stop a PanelView Timed Write Corrupting SLC Clock Registers.

Synchronization procedure #

  1. Prove the path with values that cannot lie. Map a spare %MW word to a numeric display, change it in the M241, and watch the terminal follow; write a test value from the terminal into a second spare word to prove the write direction as well. If the link itself is not up yet, Connecting an XBTGT HMI to an M241 PLC over Modbus TCP sets up that connection end to end.
  2. Record the reference. Put a numeric display on each raw SYSTIMEDATE field so you can watch the block track the controller clock while you commission; keep these on a commissioning screen, not the operator's.
  3. Reserve the buffer. Choose a block of consecutive %MW words sized for six integer fields plus one sequence word, record the first address, and keep the block out of every other exchange.
  4. Convert once, in one scan. Copy the six calendar fields of the SYSTIMEDATE block into the buffer words in a single PLC scan, converting each DINT to the integer width the dialogue table uses. One scan per snapshot is what keeps the six fields mutually consistent.
  5. Gate the snapshot with a sequence word. Increment the sequence value only after the entire snapshot is written, never between fields. The terminal fires on a change of that word, so a read that lands mid-update cannot mix old and new components. If you want closed-loop confirmation, reserve one more word for the terminal to write back an acknowledge after it applies the clock.
  6. Map the fields in the HMI. Address one register per field, in exactly the order the terminal's clock dialogue table lists them, relative to the address base verified in step 1. Read that field order from the dialogue table in your own project — it is the runtime's contract, not something to infer from a display layout.
  7. Trigger the clock write from the sequence word. Point the dialogue table's clock operation at the mapped fields and fire it when the sequence value changes, not on a fixed timer. A periodic timer is what applies half a snapshot at a minute rollover and produces a clock with new seconds behind old minutes.
  8. Test with a visible difference. Set the terminal clock deliberately wrong — a different date, not just a minute — pulse the sync request once, and confirm the terminal jumps to the M241 time. Then confirm the seconds keep advancing on their own and that no further writes occur until the next request.

When the terminal clock still will not take the write #

Work down this list when the write stalls; each cause has a distinct signature.

  • Every field reads one register early or late: the address base is off by one. Retune it against a forced test value in a spare word, never against the clock, because a near-correct time keeps every field sitting one register off.
  • Month and day arrive swapped: the HMI mapping order does not match the dialogue table. Force a test date past the 12th of the month, where the swap becomes obvious.
  • The clock takes the write and then jumps back: a second automatic writer exists, in another client or in the terminal itself. Leave exactly one writer.
  • The values look right but nothing writes: the driver area is read-only or the trigger never fires. Repeat the spare-register write test from step 1, then check the trigger condition.
  • The applied time mixes old and new components: the terminal read a half-written snapshot. Confirm the sequence word changes strictly after the last field and that the terminal triggers on that word alone.

A clock any Modbus client may write is a clock any client may write wrongly: on machines where timestamps back traceability or shift records, commission the exchange on the bench with test values and keep the write behind the PLC-controlled request rather than a continuous background write.

Questions asked

Can I skip the buffer and point the clock dialogue table straight at the SYSTIMEDATE registers?

Yes, with care. Map both registers of each DINT to the terminal and let the driver reassemble them; the clock takes once the word order, signedness and field width are set correctly on every clock tag. The buffer costs seven words and moves all of that interpretation into one place in the PLC, so a later driver update or a second terminal cannot quietly reintroduce a wrong-date fault.

How do I find the address offset between %MW numbers and the driver's register addresses?

Force a distinctive test value, for example 12345, into a spare %MW word and read it from the terminal at the address the driver derives from that word. Adjust the driver's address base until the exact value appears, then map every clock field relative to that verified base. Tuning the offset against the clock itself is the classic mistake, because a near-correct time keeps working while every field sits one register off.

How often should the terminal re-apply the PLC time?

The two real-time clocks run on separate oscillators, so a Magelis STU set once will drift away from the M241 over days or weeks, and no documented drift rate replaces measuring your own pair. For most machines, re-applying the snapshot once per shift or once per day through the same sequence handshake is enough for shift logs and keeps the write away from operators' manual clock corrections.

Does the same method work over Modbus serial instead of Modbus TCP?

Yes. The DINT-to-integer snapshot does not depend on the physical link, so the same buffer and sequence handshake run over Modbus RTU. Serial polling adds delay, so expect the terminal to apply the clock up to one full poll period after the sequence word changes. Judge the handshake only after waiting out that period, and keep the clock exchange out of a serial link that is already near its time budget.

Keep reading

  • How-to

    Set a Premium PLC Clock From a Magelis HMI Over Unitelway

    In Vijeo Designer, open the Unitelway equipment in the I/O Manager, add a Dialogue Table with start address %SW50 and the Configure the PLC clock function, and clear the Include editor project option before transfer, because packaging the editor project is what aborts the download with an abnormal program termination. Keep the editable project on the engineering workstation and verify the PLC clock with its own read.

    HMI and touchscreens

  • How-to

    Schedule the PLC by day of week from the HMI clock

    Copy the panel's weekday system tag into a PLC tag with an event that fires on a change of value, then run the schedule's weekday comparisons on the received text. The adjustable panel clock becomes the only time source, so a PLC left powered down over midnight can no longer miss the weekday transition and drift the schedule.

    HMI and touchscreens

  • How-to

    Connecting an HMISTO735 to an M241 PLC with Vijeo XD

    Commission the HMISTO735 to M241 link in three layers: a driver and endpoint both Vijeo XD and the SoMachine project support, a proven Ethernet path with addresses and a ping, then one exposed test variable passed read and write end to end. Build screens only after that loop closes, and fix each fault at the first layer that fails.

    HMI and touchscreens