Overview
Displaying a Siemens S5TIME value on a WinCC HMI panel requires two coordinated steps: configuring the WinCC tag with the DwordToSimaticBCDTimer format adjustment, and adding a VBScript that decodes the BCD-encoded time base and value into hours, minutes, and seconds. STEP 7 and TIA Portal PLCs do not expose a native S5TIME-to-string driver inside WinCC, so the conversion is performed in the runtime script.
This reference covers the S5TIME bit layout, the WinCC tag configuration, the conversion script, the integer-type ranges that drive the WinCC format choice, and a multi-motor control architecture that uses FB-MOTOR and FB-CONTROL function blocks with instance DBs to implement priority selection based on operating hours or start counts. The same technique applies to WinCC Flexible, WinCC Runtime Advanced, and WinCC Professional panels.
S5TIME Data Type Deep Dive
The S5TIME data type in STEP 7 occupies 16 bits and packs two fields into a BCD-encoded word. The upper 12 bits encode the time value in BCD, while the lower 4 bits encode the time base. The time base determines the resolution that the operating system applies when it decrements (or increments, for retentive timers) the value every scan.
| Time Base Bits (b3..b0) | Resolution | Maximum BCD Value | Maximum Representable Time |
|---|---|---|---|
| 0000 | 0.01 s (10 ms) | 999 | 9.99 s |
| 0001 | 0.1 s (100 ms) | 999 | 99.9 s |
| 0010 | 1 s | 999 | 16 m 39 s (999 s) |
| 0011 | 10 s | 999 | 2 h 46 m 30 s (9990 s) |
For example, S5T#1m30s is encoded as 0x0130 with time base 0010 (1 s) and BCD value 130. The value S5T#25h30m is encoded as 0x3300 with time base 0011 (10 s) and BCD value 330 (330 x 10 s = 3300 s = 55 minutes — note that values larger than 999 cannot be encoded and require a longer time base). When the timer is running, WinCC receives the current elapsed/remaining time as a DWORD where the same BCD layout is preserved in the lower 16 bits.
The script must therefore strip the time base, read the BCD value, and multiply by the time-base factor to obtain the time in seconds. The general formula is:
T_seconds = BCD_value * time_base_factor
where time_base_factor is 0.01, 0.1, 1, or 10 depending on the lower four bits. WinCC's DwordToSimaticBCDTimer format adjustment does this multiplication implicitly and returns the value as a 32-bit integer in tenths of the time base.
WinCC Tag Configuration
Open the WinCC Tag Management and add the tag that mirrors the PLC timer word. The tag properties must match the bit layout exactly:
- Data type: 32-bit unsigned value (Unsigned 32-bit / DWORD)
-
Format adjustment:
DwordToSimaticBCDTimer -
PLC address: the data block word where the S5TIME is stored, e.g.
DB15.DBW4for a timer captured into a data block - Acquisition cycle: 250 ms for a continuously updated display, 1000 ms for trend-only use
DwordToSimaticBCDTimer format adjustment is the only built-in adapter that interprets the lower 16 bits as an S5TIME value. Other adapters such as DwordToBCDByte or DwordToBCDWord decode different BCD layouts and will produce nonsense if used here. Reference: Siemens Industry Online Support.If the S5TIME is read directly from a T timer word (for example, MW20 for T20), address the tag at MW20 in WinCC. The DWORD width is still required because WinCC internally expands the 16-bit S5TIME into a 32-bit value for the format adjustment to operate on.
VBScript for H:M:S Conversion
Attach the following VBScript to the Output Value change event or to the Source property of the I/O field or text field. The script reads the BCD-encoded DWORD, divides by 1000 to neutralize the time-base scaling performed by the format adjustment, and splits the result into hours, minutes, and seconds using integer arithmetic.
Dim TIEMPO, HR, MIN, SEC
Dim T
Set TIEMPO = HMIRuntime.Tags("TIEMPO_RESTANTE")
TIEMPO.Read
T = TIEMPO.Value / 1000
HR = Int(T / 3600)
MIN = Int((T / 60) - (HR * 60))
SEC = Int(T - (HR * 3600) - (MIN * 60))
ITEM.Text = CStr(HR & "h. " & MIN & "m. " & SEC & "sg.")
The factor /1000 converts the WinCC-side representation (where the value arrives in thousandths of the time base for BCD compatibility) into whole seconds. The integer arithmetic extracts whole-hour, whole-minute, and remainder-second components. Adjust the divisor if your HMI is configured with a different time-base interpretation:
| Time Base | Divisor in Script | Resulting Units | Typical Use |
|---|---|---|---|
| 10 ms | 100 | 0.01 s ticks | Fast pneumatic timing |
| 100 ms | 1000 | 0.1 s ticks | Default S7-300 timer |
| 1 s | 10000 | 1 s ticks | Long-delay timing |
| 10 s | 100000 | 10 s ticks | Hour-range timing |
Output Value change event. For event-driven updates, attach the script to the value-change property of the I/O field rather than the static Source.Alternative Display Methods
Three approaches exist for displaying S5TIME on a WinCC HMI. The choice depends on the number of timers, the available HMI CPU budget, and the desired maintenance footprint.
| Method | PLC Code | HMI Code | Best For |
|---|---|---|---|
| VBScript H:M:S conversion | None | Script on every tag | 1 to 10 timers |
| PLC-side HR/MIN/SEC tags | Conversion FB | Three I/O fields | 10+ timers, TIA Portal |
| Native SIMATIC_TIME adjustment | None | Format adjustment only | TIA Portal V16+ panels |
The PLC-side approach computes hours, minutes, and seconds in the PLC and stores them in three INT tags. The HMI binds three I/O fields to those tags with no script. The conversion FB runs once per cycle and is trivial to maintain. For installations with hundreds of timers, this method is the preferred choice because it eliminates the HMI CPU cost of running conversion scripts and keeps the logic in one place.
The native SIMATIC_TIME format adjustment is available in TIA Portal V16 and later for Comfort Panel and WinCC Runtime Advanced. It renders the value directly in d hh:mm:ss format and requires no VBScript. Use it whenever the panel firmware supports it.
PLC Data Type to WinCC Format Mapping
WinCC requires the format adjustment to match the data width and signedness of the PLC tag. Choose the type when creating the variable in the PLC data block, then mirror it exactly in WinCC. A mismatch is the most common source of garbage values on the HMI.
| STEP 7 / TIA Type | WinCC Data Type | Example PLC Address | Signedness |
|---|---|---|---|
| BYTE | 8-bit value | DB15.DBB4 | Choose signed or unsigned |
| WORD | 16-bit value | DB15.DBW4 | Unsigned only |
| INT | 16-bit value | DB15.DBW4 | Signed (default) |
| DWORD | 32-bit value | DB15.DBD4 | Unsigned only |
| DINT | 32-bit value | DB15.DBD4 | Signed (default) |
| REAL | 32-bit floating-point number | DB15.DBD4 | IEEE 754 signed |
The signed/unsigned option applies only to the 8-bit and 16/32-bit integer types. Choose unsigned when the value is always non-negative (operating hours, start counters, setpoints). Choose signed when the value can go negative (deviations, error codes, two's-complement bitmasks).
Integer Type Ranges
| Type | Size | Range | Overflow at |
|---|---|---|---|
| INT (S7) | 16 bits | -32,768 to 32,767 | 32,767 (about 3.7 years continuous) |
| DINT (S7) | 32 bits | -2,147,483,648 to 2,147,483,647 | 2,147,483,647 (about 245,000 years) |
| REAL | 32 bits | ±3.402823e+38 | Roughly 7 significant digits |
For operating-hour accumulators that grow indefinitely, DINT is the correct choice. INT overflows at 32,767 hours (about 3.7 years of continuous operation), which is rarely acceptable for industrial assets. If the hour counter must outlive a DINT, split into high/low DWORD words and concatenate in a script, or store as REAL with periodic archiving.
Timer Implementation: T Timers vs. IEC Timers
The native S7 timer word (for example, T20) is read-only from the user's perspective once the timer is started; the operating system updates the BCD-encoded elapsed/remaining value automatically. There is no need to instantiate a custom timer block — the PLC ships with 256 T timers in the S7-300/400 and 512 in the S7-1500. Using a T timer is simpler than instantiating an IEC timer block because:
- The S5TIME format is exposed directly without conversion.
- The scan updates the time value on every OB1 cycle.
- WinCC reads the timer word with the
DwordToSimaticBCDTimeradapter without intermediate PLC code.
For TIA Portal projects, IEC timers (TP, TON, TOF, TONR) use the TIME data type (32-bit milliseconds, layout: 0x01mmmmmm), which is a different layout than S5TIME. To bridge IEC timer outputs to WinCC's S5TIME format, copy the elapsed/remaining value into a data word and apply the TIME_TO_S5TIME conversion, or build the BCD structure manually with a shift-and-OR ladder network. The TIA Portal library "IEC Timer to S5TIME" provides a ready-made FC for this conversion.
Multi-Motor Control Architecture
A common requirement is a redundant pump or compressor pair that automatically rotates duty based on operating hours, start counts, or a manual priority override. The architecture uses two reusable function blocks:
- FB-MOTOR (FBMT): encapsulates the run command, feedback, hour accumulator, and start counter for one motor. Each instance owns its own instance DB.
- FB-CONTROL (FBCT): reads the operating-hours and start-count values from all FB-MOTOR instances, applies the selection rule, and drives the run-permission output for each motor.
The selection rule is selected via an HMI mode selector. The mode tag is a single INT bound to a WinCC option list:
| Mode | Selection Rule | Use Case |
|---|---|---|
| 0 | Manual priority — Motor 1 always preferred | Lead/lag with fixed lead |
| 1 | Manual priority — Motor 2 always preferred | Lead/lag with fixed lead |
| 2 | Auto — motor with fewer operating hours starts first | Even wear distribution |
| 3 | Auto — motor with fewer starts starts first | Reduced inrush stress |
FB-MOTOR Interface Definition
FB-MOTOR encapsulates everything that makes a single motor unique. The interface definition uses standard STEP 7 input/output sections:
FUNCTION_BLOCK FBMT
VAR_INPUT
RUN_CMD : BOOL; // Operator or sequencer request
FB_OK : BOOL; // Contactor closed feedback
RESET : BOOL; // Maintenance reset of hours/starts
END_VAR
VAR_OUTPUT
RUNNING : BOOL; // True while motor is running
HOURS : DINT; // Cumulative operating hours x 100
STARTS : DINT; // Cumulative start count
FAULT : BOOL; // Feedback mismatch detected
END_VAR
VAR
PREV_RUN : BOOL; // Edge-detection helper
TICK_S : BOOL; // 1-second clock from OB35
HOURS_X100: DINT; // Internal accumulator (hours x 100)
END_VAR
The 1-second clock from OB35 (or a hardware timer) is multiplied into the hour accumulator. Storing hours x 100 allows one decimal place of fractional hours (36.25 hours is stored as 3625). The start counter increments on every rising edge of RUN_CMD while FB_OK confirms closure within a configurable watchdog window (default 3 seconds).
FB-CONTROL Selection Logic
FB-CONTROL receives the hours and starts from each FB-MOTOR instance and computes the run-permission output for each motor. The selection logic is implemented as a CASE branch on the MODE input:
FUNCTION_BLOCK FBCT
VAR_INPUT
MODE : INT; // 0..3 selector from HMI
HOURS_M1 : DINT;
HOURS_M2 : DINT;
STARTS_M1 : DINT;
STARTS_M2 : DINT;
END_VAR
VAR_OUTPUT
PERMIT_M1 : BOOL;
PERMIT_M2 : BOOL;
SELECTED : INT; // 1 or 2, for HMI indication
END_VAR
BEGIN
CASE MODE OF
0: PERMIT_M1 := TRUE; PERMIT_M2 := FALSE; SELECTED := 1;
1: PERMIT_M1 := FALSE; PERMIT_M2 := TRUE; SELECTED := 2;
2: IF HOURS_M1 <= HOURS_M2 THEN
PERMIT_M1 := TRUE; PERMIT_M2 := FALSE; SELECTED := 1;
ELSE
PERMIT_M1 := FALSE; PERMIT_M2 := TRUE; SELECTED := 2;
END_IF;
3: IF STARTS_M1 <= STARTS_M2 THEN
PERMIT_M1 := TRUE; PERMIT_M2 := FALSE; SELECTED := 1;
ELSE
PERMIT_M1 := FALSE; PERMIT_M2 := TRUE; SELECTED := 2;
END_IF;
ELSE PERMIT_M1 := FALSE; PERMIT_M2 := FALSE; SELECTED := 0;
END_CASE;
END_FUNCTION_BLOCK
<= not < so that a tie is broken in favor of Motor 1. This ensures deterministic behavior across power cycles. If you prefer the opposite tiebreak, swap M1 and M2 in the comparator.FB and Instance DB Relationship
Every FB call in STEP 7 / TIA requires an associated instance DB (also called DI — Data Instance). The instance DB stores all STAT (static) variables declared in the FB plus the previous values of IN, OUT, and IN_OUT parameters. When you instantiate FB-MOTOR twice (one per physical motor), you create two instance DBs:
CALL FBMT, DB_MOTOR_1 // First motor instance
RUN_CMD := I0.0
FB_OK := I0.1
RESET := FALSE
CALL FBMT, DB_MOTOR_2 // Second motor instance
RUN_CMD := I0.2
FB_OK := I0.3
RESET := FALSE
The FBCT then receives the hours and starts from both instances and computes the run-permission outputs:
CALL FBCT, DB_CONTROL
MODE := MW120
HOURS_M1 := DB_MOTOR_1.HOURS
HOURS_M2 := DB_MOTOR_2.HOURS
STARTS_M1 := DB_MOTOR_1.STARTS
STARTS_M2 := DB_MOTOR_2.STARTS
PERMIT_M1 := Q4.0
PERMIT_M2 := Q4.1
STEP 7 enforces the instance DB length to match the FB interface. If you change the FB interface (add a variable), regenerate all instance DBs with the right-click "Instance DB" → "Regenerate" command. Failing to regenerate causes the PLC to enter SF (system fault) at the next download.
Wiring the FB Outputs in an FC
The FBs are wired together through an FC (function) that calls both blocks and routes the values. The FC contains no static memory of its own; it acts as the wiring diagram that the PLC executes each cycle.
// FC 100 — Motor coordination
U "MTR1_RUN_REQ" // Operator start request, motor 1
= %DB_MOTOR_1.RUN_CMD
U "MTR2_RUN_REQ" // Operator start request, motor 2
= %DB_MOTOR_2.RUN_CMD
CALL FBMT, DB_MOTOR_1
RUN_CMD := "MTR1_RUN_REQ"
FB_OK := I0.1
CALL FBMT, DB_MOTOR_2
RUN_CMD := "MTR2_RUN_REQ"
FB_OK := I0.3
CALL FBCT, DB_CONTROL
MODE := "MODE_SEL"
HOURS_M1 := DB_MOTOR_1.HOURS
HOURS_M2 := DB_MOTOR_2.HOURS
STARTS_M1 := DB_MOTOR_1.STARTS
STARTS_M2 := DB_MOTOR_2.STARTS
PERMIT_M1 := Q4.0
PERMIT_M2 := Q4.1
The FBCT compares the hours and starts and routes the appropriate permit output to the corresponding motor contactor. The actual start command to the contactor is the AND combination of PERMIT_Mn and the operator request. This guarantees that a fault or mode change cannot energize the wrong contactor.
Multi-Instance FBs in TIA Portal
TIA Portal extends the instance model with multi-instance FBs. A multi-instance FB calls other FBs as local instances, sharing the parent FB's instance DB. The benefit is a single instance DB per coordination block, reducing DB count and simplifying online viewing. Multi-instance FBs are supported in S7-1500 and S7-1200, but not in S7-300/400.
FUNCTION_BLOCK FB_DUTY_ROTATOR
VAR
MOTOR_1 : FBMT; // Multi-instance — shares DB_DUTY_ROTATOR
MOTOR_2 : FBMT;
CTRL : FBCT;
END_VAR
BEGIN
MOTOR_1(RUN_CMD := I0.0, FB_OK := I0.1);
MOTOR_2(RUN_CMD := I0.2, FB_OK := I0.3);
CTRL(MODE := MW120,
HOURS_M1 := MOTOR_1.HOURS,
HOURS_M2 := MOTOR_2.HOURS,
STARTS_M1 := MOTOR_1.STARTS,
STARTS_M2 := MOTOR_2.STARTS,
PERMIT_M1 => Q4.0,
PERMIT_M2 => Q4.1);
END_FUNCTION_BLOCK
For S7-300/400 projects, use the single-instance (separate DB) approach shown in the previous section. Both produce identical behavior; multi-instance is purely a packaging choice.
Hour Counter Overflow Protection
The DINT hour counter covers approximately 245,000 years of continuous operation, but the start counter can grow fast in a high-cyclic application. A pump that starts 10 times per hour for 8,760 hours per year accumulates 87,600 starts per year. INT overflows at 32,767 starts (~142 days at this rate). DINT is therefore the only safe choice for the start counter. If the system designer insists on INT, add a roll-over detection:
// Reset DINT at INT overflow
IF STARTS > 32000 THEN
STARTS := 0;
END_IF;
Commissioning and Verification
- Download the hardware configuration and the S7 program to the PLC. Confirm the PLC goes to RUN with no SF.
- Open the FB-MOTOR instance DB online and confirm the
HOURSandSTARTStags increment on each successful start. - From the HMI, toggle the
MODE_SELtag through 0, 1, 2, 3 and observe whichPERMIT_Mnoutput activates. TheSELECTEDoutput should mirror the active motor. - Force the
HOURS_M1value higher thanHOURS_M2and verify that mode 2 swaps the active permit after the next cycle. - Open the WinCC tag list and confirm the
TIEMPO_RESTANTEtag carries theDwordToSimaticBCDTimerformat adjustment. - Trigger the HMI display update and confirm the
HR h. MIN m. SEC sg.text reflects the live timer value within one acquisition cycle. - Disconnect the field wiring to one contactor and verify that
FAULTbecomes TRUE on the corresponding FB-MOTOR within the watchdog window. - Cycle PLC power and confirm the hour/start values persist (they must be stored in a retentive instance DB, not in M or L memory).
Troubleshooting Matrix
| Symptom | Likely Cause | Corrective Action |
|---|---|---|
| Display shows 0 h. 0 m. 0 sg. | Tag format adjustment missing | Set the WinCC tag format adjustment to DwordToSimaticBCDTimer
|
| Display shows wrong hours / minutes | Wrong time-base divisor | Match the script divisor to the S5TIME time base (see divisor table) |
| Display freezes after first read | Script bound to wrong event | Bind to Output Value change of the I/O field |
| FB call returns SF (system fault) | Instance DB missing or wrong length | Regenerate the instance DB from the FB interface |
| Both permits active simultaneously | FBCT comparison not exclusive | Verify the comparator branches enforce mutual exclusion in all modes |
| Hour counter wraps to negative | INT overflow | Change accumulator type to DINT or REAL |
| Tag reads garbage (e.g. 9999h) | Wrong DB number or offset | Reconcile the WinCC tag address with the PLC online view |
| Script triggers on every cycle but text does not change | ITEM.Text assignment targets wrong object | Use ITEM.OutputValue instead of ITEM.Text for I/O fields |
| Mode change has no effect | FBCT not called in scan | Verify the FC that wires FBCT is in OB1 |
| Hour counter resets on PLC restart | Instance DB not marked retentive | Right-click the instance DB → Properties → Retain → set HOURS and STARTS as retentive |
Performance and Scan-Time Considerations
The script runs on every change of the I/O field source. If the source updates faster than the HMI can render (e.g., 100 ms cycle on a 4-inch Panel), throttle the acquisition cycle to 500 ms or 1 s to reduce CPU load. For multi-screen displays, host the script on the central process picture and reuse the formatted string on every screen.
For large fleets with hundreds of timers, compute the H:M:S string on the PLC side using a dedicated FB that emits three INT outputs (HR, MIN, SEC), then display each INT directly without script. This approach trades a few DB words for zero HMI script load and is preferred on Comfort Panel and WinCC Runtime Advanced installations.
The FB-MOTOR and FB-CONTROL calls add a few microseconds per cycle to the PLC scan time. On a 300/400 CPU, expect 50 to 200 microseconds per instance. On a 1500 CPU, expect less than 10 microseconds. Neither is significant for typical installations with fewer than 50 motors.
Migration from STEP 7 to TIA Portal
In TIA Portal, the IEC timer types (TP, TON, TOF, TONR) use the 32-bit TIME data type instead of S5TIME. To keep the same WinCC display technique, write a small FB that converts TIME (milliseconds, DWORD) into the S5TIME BCD layout and store the result in a data word. The WinCC tag configuration remains identical: DWORD with DwordToSimaticBCDTimer. Alternatively, TIA Portal HMI tags support the SIMATIC_TIME format adjustment natively (V16 and later), which renders the value directly without a script.
When migrating STEP 7 classic projects that use T timers, keep the T timer calls in place. TIA Portal still supports T timers on S7-300/400 (with the optional T_TIMER block) and on S7-1500 via the legacy timer support package. The S5TIME layout and the WinCC adapter remain valid.
Safety and Operational Considerations
The motor coordination logic described here is non-safety. It must not be used to make safety-relevant decisions such as emergency stop, overspeed, or fire-suppression sequencing. If the application requires SIL-rated motor selection (for example, fire pumps where redundancy is safety-critical), use a separate safety PLC or safety relay and keep the duty-rotation logic strictly informational.
Permissive wiring is mandatory: PERMIT_Mn is an enabling signal, not a run command. The final contactor command must be the AND of PERMIT_Mn, the operator request, and the safety chain (E-stop, thermal overload, guard interlock). This three-way AND guarantees that a fault in FBCT cannot energize a motor outside the safety envelope.
Retentivity is critical for the hour and start counters. Mark both variables as retentive in the instance DB properties so that power-cycle does not lose audit trail data. If the CPU has a rechargeable battery (S7-300/400), confirm the battery is healthy; otherwise the data is lost on power-down.
FAQ
Why does WinCC show the raw S5TIME bits instead of a readable value?
WinCC has no native S5TIME driver. Configure the tag as a 32-bit unsigned value with the DwordToSimaticBCDTimer format adjustment so the runtime strips the time-base bits and exposes the BCD value. Without the format adjustment the tag carries raw BCD bits that the script cannot decode.
Which divisor should I use in the VBScript to get seconds?
Use T = TIEMPO.Value / 1000 for the default 100 ms time base. For a 1 s base use 10000, for 10 ms use 100, and for 10 s use 100000. The divisor matches the format adjustment's internal scaling factor for that time base.
Can I avoid the script and display the timer as-is?
Yes, if you compute hours, minutes, and seconds on the PLC side into three INT tags and bind each to a separate I/O field, no HMI script is required. This is the preferred approach for large fleets. TIA Portal V16 and later also offer the SIMATIC_TIME format adjustment which renders directly without script.
Does every FB need an instance DB?
Yes. In STEP 7 and TIA Portal, every FB call is associated with exactly one instance DB that holds the block's static memory. Multi-instance FBs (TIA Portal only) can share a parent instance DB to reduce DB count.
How do I rotate two motors by operating hours?
Implement FB-MOTOR per motor with hour and start counters, implement FB-CONTROL that compares both pairs and emits the permit output, and call both from a coordinating FC. Mode 2 selects the motor with fewer hours; mode 3 selects the motor with fewer starts. Manual modes 0 and 1 fix the lead motor.
What integer type should I use for the hour accumulator?
DINT. INT overflows at 32,767 hours (~3.7 years), which is rarely acceptable. DINT covers approximately 245,000 years of continuous operation and is the safe default for any value that grows indefinitely.