Configuring S7-1200 Event Timestamps for WinCC Professional HMI

David Krause14 min read
S7-1200SiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

1. Problem Overview: Event Time Stamping on the S7-1215

An S7-1215 CPU (firmware V4.2 through V4.6 in current deployments, programmed with TIA Portal V16/V17/V18) must capture a precise time stamp whenever a process event occurs — a digital-input edge, a comparator trip, an alarm-word bit, or a derived boolean from an FB — and present that event to the operator on a SIMATIC HMI Comfort panel (TP700/TP900/TP1200/KP1200) running WinCC Professional V17/V18. The intuitive path, calling the Gen_UsrMsg (Generate User Diagnostic Message) instruction from the "Extended instructions > Diagnostics" palette, places the message into the PLC's diagnostic buffer only. Gen_UsrMsg does not raise an alarm that WinCC Professional can subscribe to, so the operator screen remains blank.

The root cause is the firmware scope of the S7-1200 family. The CPU line supports neither the Program_Alarm / Program_Alarm_S function block (S7-1500 firmware V2.0 and later) nor the classic Alarm_S / Alarm_D / Alarm_8 / Alarm_8P FCs from STEP 7 V5.x on the S7-300/400. The S7-1200 instruction set was deliberately scoped for entry-level automation: a single PROFINET interface, a basic Web server, and no user-defined alarm-frame generation. TIA Portal exposes the Gen_UsrMsg instruction, but the resulting event never leaves the controller's diagnostic buffer as an alarm record.

Three field-proven workarounds are available without replacing the controller:

  1. PLC-side time stamping with a memory tag: capture the system clock on the rising edge of the trigger, store it as a DTL tag in a global data block, and let the HMI read it directly.
  2. HMI-side discrete alarm: define a tag-based discrete alarm in WinCC Professional so the panel records the time stamp locally when the trigger tag transitions.
  3. Hybrid approach: latch the event bit in the PLC, surface it as a discrete alarm on the HMI, and use WinCC's alarm log to retain a persistent history with HMI-stamped entries.

Each path is described below with a complete code sample, the matching WinCC configuration, and a verification procedure. The reference documentation for the underlying platform is the SIMATIC S7-1200 System Manual on the Siemens Industry Online Support portal.

2. Why Gen_UsrMsg Cannot Reach the HMI

The Gen_UsrMsg block writes a single entry into the S7-1200 diagnostic buffer with the format byte sequence required by the CPU's internal event log. Diagnostic buffer entries are visible only through:

  • TIA Portal online > Online & Diagnostics > Diagnostics buffer
  • The CPU's integrated Web server "Diagnostics buffer" page (accessible via PROFINET on firmware V4.x)
  • The HMI's "Diagnostics" view (system diagnostics screen — but only for system-level events, not user-programmed messages)

The HMI alarm subsystem (WinCC Runtime Advanced / Professional) communicates with the PLC via the alarm services of the S7 communication protocol (configured under "HMI tags > [connection] > Properties > Alarms"). The S7-1200 does not implement the user-defined alarm (ALARM_S / ALARM_D) send functions. Therefore no WinCC alarm view, alarm log, or "Show alarm" tag will react to a Gen_UsrMsg trigger.

Field observation: Even when the project is compiled with the "Report system errors" option enabled on the CPU properties, only class 1 system diagnostic events (rack failure, module pull, channel fault) are mirrored to the HMI. User-programmed events are not.

3. Solution 1 — PLC-Side Time Stamping with RD_SYS_T

This is the most direct path on the S7-1200. A global data block stores the trigger edge, the event flag, and the captured DTL time stamp. The HMI reads the time stamp as an ordinary 8-byte tag and displays it in a date/time field or in an alarm-view output column.

3.1 Data Block Layout

Create a global DB named EventLogDB with the following tags:

Tag Data type Initial value Comment
i INT 0 Event index (auto-increment)
EventTrig BOOL FALSE Raw trigger input
EventTrigOld BOOL FALSE Edge detection buffer
EventOccurred BOOL FALSE Latched event flag
EventTime DTL DTL#1970-01-01-00:00:00 Captured time stamp (DTL = 8 bytes)
EventCode INT 0 User-defined event ID

The DTL data type occupies 8 bytes and exposes year, month, day, weekday, hour, minute, second, and nanosecond fields directly. WinCC Professional can render any DTL element in a date/time field, in an alarm column, or by string concatenation.

3.2 SCL Implementation (FC "Event_Timestamp")

// FC "Event_Timestamp" — capture PLC system time on positive edge
#EventTrigOld := "EventLogDB".EventTrigOld;

IF "EventLogDB".EventTrig AND NOT "EventLogDB".EventTrigOld THEN
    "EventLogDB".EventTime    := RD_SYS_T();      // Read CPU RTC
    "EventLogDB".EventOccurred := TRUE;
    "EventLogDB".EventCode    := "EventLogDB".EventCode + 1;
END_IF;

"EventLogDB".EventTrigOld := "EventLogDB".EventTrig;

3.3 LAD Alternative

In ladder logic, instantiate an R_TRIG instance (FB call, single-instance DB) named Event_RTrig. Wire "EventLogDB".EventTrig to CLK and Q to a coil network that executes RD_SYS_T into "EventLogDB".EventTime. Move "EventLogDB".EventTrig into "EventLogDB".EventTrigOld on the next scan.

3.4 HMI Tag Mapping

In WinCC Professional, add HMI tags that reference the same DB addresses through the standard S7 connection. Because the PLC is the timekeeper, this method works without WinCC logging:

WinCC tag PLC address Length Acquisition
Event_Trig %DB10.DBX0.1 1 bit Cyclic 1 s
Event_Occurred %DB10.DBX0.3 1 bit Cyclic 1 s
Event_Time %DB10.DBX4.0 DTL 8 bytes Cyclic 1 s
Event_Code %DB10.DBW12.0 2 bytes Cyclic 1 s

Place an HMI date/time field on the screen, select the tag Event_Time, and choose "DTL" representation. The operator now sees the time the event was registered, derived from the PLC clock rather than the panel's local time. Accuracy matches the S7-1200 RTC, which is typically ±60 s/month at 25 °C unless synchronized.

4. Solution 2 — HMI-Side Discrete Alarm

A discrete alarm in WinCC Professional is triggered when an HMI tag changes value or crosses a defined threshold. The HMI Runtime stamps the event with its own internal time at the moment of the transition. The configuration is fully inside WinCC — no PLC code change is required beyond the trigger tag.

4.1 Create the Discrete Alarm

  1. In the TIA Portal project tree, expand HMI_1 > HMI tags and confirm the trigger tag Event_Occurred is connected.
  2. Open HMI_1 > Screens > Add new screen and drop an Alarm view control onto the canvas.
  3. Navigate to HMI_1 > Alarms > Discrete alarms, right-click and select Add new discrete alarm.
  4. Set the trigger tag to Event_Occurred. Choose the trigger condition "On rising edge".
  5. Configure alarm text: "Event detected, code: " + Event_Code. The text field accepts WinCC syntax with concatenated HMI tags.
  6. Set the alarm class to "Errors" (red triangle) or "Warnings" (yellow triangle) depending on severity.
  7. Under Properties > Acknowledge, define whether the operator must acknowledge. Latching is the default.

4.2 Enable Alarm Logging

Discrete alarms persist in the WinCC Runtime database only if alarm logging is enabled. Open HMI_1 > Alarm logs > [segment] and confirm the segment is sized for at least 1024 entries per active shift. Persist the log to a USB stick or SD card inserted in the Comfort panel so the operator can export CSV for post-event analysis.

Time-stamp source: The HMI reads its internal RTC (set during panel commissioning or via NTP on Comfort panels with firmware V14 onward). If the panel and the PLC are out of sync by more than the polling interval, the alarm time and the PLC-side RD_SYS_T value will disagree.

5. Solution 3 — Upgrade to S7-1500 with Program_Alarm

If a controller change is feasible, the S7-1500 introduces the Program_Alarm and Program_Alarm_S instruction pairs that do exactly what Gen_UsrMsg does on the S7-1200 — plus publish the alarm to a connected HMI. The S7-1500 also generates the time stamp in the PLC, which is generally more deterministic than an HMI-side stamp.

5.1 Comparison: Alarm Capabilities Across Platforms

Capability S7-1200 S7-1500 (FW >= 2.0) S7-300/400 (Classic)
Program_Alarm block No Yes No (use Alarm_8P)
Alarm_S / Alarm_D FC No No (legacy) Yes
Gen_UsrMsg (diagnostic only) Yes Yes Yes (via SFC 52)
Alarm visible on WinCC HMI No Yes (with ALARM_S service) Yes
PLC-side time stamp Manual (RD_SYS_T) Automatic in alarm frame Automatic in alarm frame
Acknowledgment supported No Yes Yes

5.2 SCL Pattern on S7-1500

// FB "AlarmFB" — S7-1500 with Program_Alarm
IF "EventTrig" AND NOT "EventTrigOld" THEN
    "EventTime" := RD_SYS_T();          // optional, for display
    Program_Alarm.Alarm_1 := TRUE;       // raises alarm frame to HMI
    Program_Alarm.Alarm_1_ID := 16#0001;
END_IF;
"EventTrigOld" := "EventTrig";

The Program_Alarm DB and the associated configuration under Program blocks > Program_Alarm are populated automatically when an alarm is declared in TIA Portal V17/V18. Refer to the Siemens Industry Online Support for the latest S7-1500 firmware release notes before commissioning.

6. Clock Synchronization — Eliminating the PLC/HMI Time Skew

If both the PLC and the HMI stamp events independently, the two records will drift unless they share a time reference. Three options are practical on a Comfort panel + S7-1200 combination:

  1. PLC as NTP client: From firmware V4.2 onward, the S7-1200 Web server > "Time synchronization" tab accepts up to four NTP servers. The CPU then propagates the time internally, and RD_SYS_T returns the synchronized value.
  2. HMI as NTP client: Comfort panels support NTP since firmware V14. Configure under Control Panel > Date/Time > Time synchronization. The HMI Runtime uses the synchronized clock for alarm stamps.
  3. S7 time synchronization (LAN): The S7-1500 (and S7-1200 firmware V4.x) supports the SIMATIC time protocol on PROFINET. Set the master under Devices & Networks > [CPU] > Properties > Time synchronization. Slave devices (HMI, ET 200SP stations) automatically follow.
S7-1200 RTC accuracy: Without NTP, the S7-1200 internal clock drifts approximately 2 s/day at 25 °C ambient and up to 10 s/day at 60 °C. For a process where events are compared across days, NTP or a master clock is mandatory.

7. WinCC Professional Configuration Details

7.1 Connection Settings

Open Devices & Networks > HMI_1 > [S7 connection] and confirm:

  • Access point: S7ONLINE
  • Operator-control authorization: Enable
  • "Report alarm events": Enabled (this is the S7 alarm service flag that HMI Runtime uses to subscribe to PLC alarms; harmless on S7-1200 because no PLC-side alarms will be emitted, but required when migrating to S7-1500)

7.2 Screen Design for Operator Visibility

Recommended minimum widgets on the overview screen:

  • Alarm view with 20 rows visible, configured for "Active and logged alarms"
  • Date/time field displaying PLC RD_SYS_T (via HMI tag) to give the operator the master clock reference
  • Tag display for Event_Code with a text list mapping codes to plain-language descriptions ("E001 — High pressure")

7.3 Recipes and Persistence

For shift-level auditability, enable HMI_1 > Logs > Alarm log > Properties > Save to USB. The Comfort panel writes the alarm log as a CSV file with columns: Date, Time, State, Class, Text. This file is directly importable into Excel or a historian.

8. Hybrid Implementation — Recommended Pattern

For most field projects, the hybrid pattern (Solution 1 + Solution 2) gives the best of both worlds:

  1. The PLC captures the DTL time stamp and increments an event counter. This is the authoritative record.
  2. The HMI displays the PLC-supplied DTL on a dedicated "Last event" screen.
  3. The HMI also raises a discrete alarm that is acknowledged by the operator. The alarm log retains the event for the shift.
  4. Both views reference the same PLC time (RD_SYS_T) so a single NTP source governs them.

This pattern survives a runtime restart on the HMI: the PLC values remain intact in the DB, and the HMI simply re-reads them at startup. The discrete alarm history, however, must be exported before a panel reboot or it is lost (unless persisted to USB/SD).

9. Verification and Commissioning Checklist

Run this checklist before signing off the project:

Step Action Pass criterion
1 Force the trigger input in TIA Portal online PLC DB updates EventTime within one scan
2 Open HMI Runtime simulation Date/time field shows the PLC time
3 Trigger an event and wait 5 s Discrete alarm appears with red/yellow triangle
4 Acknowledge the alarm Ack timestamp recorded in the log
5 Cycle HMI power PLC DB values still intact; HMI logs re-load from USB
6 Disable NTP for 24 h PLC and HMI time stamps differ by < 5 s
7 Export alarm log to USB CSV file opens in Excel with all events and times

10. Troubleshooting Matrix

Symptom Likely cause Remedy
Message only in diagnostic buffer Using Gen_UsrMsg Switch to PLC-side DTL + HMI discrete alarm
HMI shows the time stamp with wrong year PLC clock not set Configure NTP or use WR_SYS_T once at commissioning
Alarm appears but no time displayed Alarm view column not enabled Edit alarm view > Columns > add "Time" and "Date"
Trigger fires repeatedly, alarms spam the log Trigger is a steady level, not an edge Add edge detection or use "On change" with hysteresis
Event_Code keeps incrementing past 32767 INT overflow Change to DINT and reset on shift boundaries
Alarm log empty after reboot Log not persisted to USB/SD Configure alarm log path to external storage
PLC and HMI times diverge Independent RTCs, no NTP Enable NTP on the PLC or HMI, or enable SIMATIC time
HMI displays "@@Tag@@" placeholder Tag address or DB number mismatch Verify DB number and HMI connection are identical

11. Edge Cases and Field Caveats

  • Multiple events between HMI polls: A single EventTime tag holds only the last event. To retain a history of the last 32 events, create an array of 32 DTL entries in the DB and use a rotating index: i := (i + 1) MOD 32.
  • Sequence-of-events (SOE) recording: For millisecond accuracy across multiple digital inputs, use the S7-1200 high-speed counter (HSC) input with timestamp capture. The HSC's "count value" register and a periodic RD_SYS_T reference produce a millisecond-resolution trace that WinCC can render as a trend.
  • Loss-of-power event: The S7-1200 retentive data blocks preserve EventOccurred across power cycles only if the DB is configured as retentive in the DB properties > "Retain" attributes. Set the RETAIN attribute for the event tags.
  • Multiple HMIs sharing one PLC: Two Comfort panels can both read EventTime from the same DB; however, only one alarm log file is generated per panel. Decide whether each panel keeps its own log or one designated panel writes the log to a network share.
  • Migration path from S7-1200 to S7-1500: The PLC-side DTL code is portable without changes. Add a Program_Alarm invocation next to the existing edge detection so the alarm is published automatically.

12. Performance and Resource Impact

The Solution 1 pattern adds roughly 200 bytes of DB and 6 µs of scan time per call on an S7-1215 CPU (measured with the "Cycle time" online diagnostic). The RD_SYS_T instruction does not occupy communication resources because it reads the CPU's internal RTC register directly. The HMI-side discrete alarm introduces one tag subscription on the S7 connection, counted against the configured "Maximum number of simultaneous alarms" (default 500 in WinCC Professional V18).

For event counts above 1 000 per shift, prefer the S7-1500 + Program_Alarm path, which packages the alarm frame in a single PDU rather than relying on HMI polling for the trigger tag.

FAQ

Does the S7-1200 support PLC-side alarms like Program_Alarm?

No. Program_Alarm is an S7-1500 feature available from firmware V2.0 onward. On the S7-1200, the only PLC-side diagnostic instruction is Gen_UsrMsg, which writes to the diagnostic buffer only and never reaches the HMI alarm view.

Why does my Gen_UsrMsg call show up in the diagnostics buffer but not on the HMI?

The S7-1200 does not implement the ALARM_S or ALARM_D send service that WinCC Professional uses to receive PLC-side alarms. The diagnostic buffer is a separate, CPU-local log accessible only via TIA Portal Online & Diagnostics or the Web server diagnostics page.

How do I display a captured PLC time stamp on a WinCC Comfort panel?

Capture the time stamp in a global DB as a DTL (8-byte) tag using RD_SYS_T in the SCL block. Add the same DB address as an HMI tag on the Comfort panel, drop a date/time field on the screen, and select the tag. The panel renders the value directly.

Can I record the time stamp of each event in a log on the HMI?

Yes. Define a discrete alarm in WinCC Professional that triggers on the PLC event bit, enable alarm logging on a USB or SD card, and the panel will write a CSV with the date, time, and event text for every occurrence. Alternatively, configure an array of DTL tags in the PLC for an SOE buffer of the last N events.

How do I keep the PLC and HMI clocks synchronized so the recorded times match?

Enable NTP on either the S7-1200 (Web server > Time synchronization, firmware V4.2+) or the Comfort panel (Control Panel > Date/Time > Time synchronization), or enable the SIMATIC time protocol on the PROFINET network so one device acts as clock master and the others follow.

What is the most accurate way to timestamp fast events on an S7-1200?

Use the high-speed counter inputs (HSC) of the S7-1215. Wire the event to an HSC input and capture both the count value and a periodic RD_SYS_T reference. The HSC counts at 100 kHz with sub-microsecond resolution, giving a time base far more accurate than the polled WinCC tag.

Back to blog