S5TIME to TIME Conversion in Siemens STEP 7 and TIA Portal
The S5TIME data type is the legacy timer format carried forward from SIMATIC S5 into the S7-300, S7-400, S7-1200, and S7-1500 families. It is still used by the S_ODT, S_ODTS, S_PULSE, S_PEXT, and S_OFFDT timer functions, by the coil instructions SP, SE, SD, SS, and SF, and by most HMI input fields that ask the operator for a preset time. Modern applications, however, expect an IEC 61131-3 TIME value (DINT, milliseconds) so it can be added, multiplied, scaled, compared, and used inside arithmetic expressions. This reference covers three production-ready conversion paths: STEP 7 Classic FC33/FC40, TIA Portal explicit conversion, and a manual SCL implementation, together with the BCD layout, range limits, BR bit behavior, and HMI integration.
S5TIME Binary Layout
S5TIME occupies one 16-bit WORD. The lower two bits encode the time base; the upper 12 bits hold a BCD value of 0 to 999. The effective duration is duration = BCD_value × time_base. The structure follows the S7-300/400 System Software manual and is identical on S7-1200 and S7-1500.
| Bit 15-12 | Bit 11-8 | Bit 7-4 | Bit 3-2 | Bit 1-0 | Meaning |
|---|---|---|---|---|---|
| BCD hundreds | BCD tens | BCD units | 0 | 00 | 0.01 s resolution (10 ms) |
| BCD hundreds | BCD tens | BCD units | 0 | 01 | 0.1 s resolution (100 ms) |
| BCD hundreds | BCD tens | BCD units | 0 | 10 | 1.0 s resolution (1 s) |
| BCD hundreds | BCD tens | BCD units | 0 | 11 | 10.0 s resolution (10 s) |
Bits 2 and 3 are always 0. Examples of encoded values:
-
S5T#0s= W#16#0000 -
S5T#1s= W#16#1001 (BCD 1, base 10 ms = 10 ms; PLC stores as 1 s because base 10 is incompatible, instead the editor picks base 1 s with BCD 1) -
S5T#2m30s= W#16#3252 (BCD 250, base 1 s = 250 s after rendering; rendered value uses 150 s / 10 s base = W#16#2315, since 150 × 10 s = 1500 s = 25 min) -
S5T#9990s= W#16#3999 (BCD 999, base 10 s)
999 × 10 s = 9990 s = 02:46:30.000. Any larger value stored in the S5TIME cell is automatically clipped, and the BR (binary result) bit of the conversion block is reset to 0.Range and Time-Base Selection
The IEC TIME data type on S7 is a signed 32-bit value in milliseconds. The range is -2_147_483_648 ms to +2_147_483_647 ms (approximately ±24.86 days). S5TIME is always non-negative, so the only relevant bound is the upper end.
| Time base (bits 1-0) | Resolution | Range min | Range max | Time max |
|---|---|---|---|---|
| 00 | 10 ms | 10 ms | 9 990 ms | 9 s 990 ms |
| 01 | 100 ms | 100 ms | 99 900 ms | 1 min 39 s 900 ms |
| 10 | 1 s | 1 s | 999 s | 16 min 39 s |
| 11 | 10 s | 10 s | 9 990 s | 2 h 46 min 30 s |
STEP 7 picks the time base that yields the most precise representation of the entered value. Selecting a smaller base (better resolution) reduces the achievable maximum. Programming tools display the value with the chosen base plus the BCD value, e.g. S5T#250ms = base 10 ms, BCD 25; S5T#1h30m = base 10 s, BCD 540.
Prerequisites
- STEP 7 V5.x for the FC33/FC40 path (S7-300/400, plus S7-1200/1500 in compatibility mode). TIA Portal V14 or higher for explicit conversion (S7-1200/1500).
- CPU with firmware that supports the required instruction set. S7-1500 needs firmware V1.8 or later for some S5TIME_TO_TIME overloads of SCL (see TIA Portal help for the specific instruction version).
- The "Standard Library > IEC Function Blocks" library installed in STEP 7 Classic. In TIA Portal, the standard conversion instructions are shipped with the basic libraries; no extra package is required.
- For HMI integration, a tag connection (M, DB, or I/O) typed as
S5TIMEfrom the PLC. The HMI tag will display the value asS5T#xxxsautomatically.
Method 1: STEP 7 Classic with FC33 and FC40
FC33 (symbolic name S5TI_TIM) converts S5TIME to TIME. FC40 (symbolic name TIM_S5TI) converts TIME to S5TIME. Both blocks are in the "Standard Library > IEC Function Blocks" section of STEP 7 Classic.
FC33 S5TI_TIM - S5TIME to TIME
| Parameter | I/O | Type | Meaning |
|---|---|---|---|
IN |
INPUT | S5TIME | Time value in S5TIME format |
RET_VAL |
OUTPUT | TIME | Converted value in ms as TIME |
Calling example in STL (S7-300/400):
CALL FC 33
IN := DB10.DBX0.0 // S5TIME source, e.g. MW20
RET_VAL:= MD30 // TIME result in ms
NOP 0
Calling example in LAD/FBD: drag FC33 from the IEC Function Blocks library onto the network, connect a tag of type S5TIME to IN, and a tag of type TIME (DWORD) to RET_VAL.
FC40 TIM_S5TI - TIME to S5TIME
| Parameter | I/O | Type | Meaning |
|---|---|---|---|
IN |
INPUT | TIME | Time value in ms |
RET_VAL |
OUTPUT | S5TIME | Converted value in S5TIME format |
STL example:
CALL FC 40
IN := MD40 // TIME source in ms
RET_VAL:= MW50 // S5TIME result
NOP 0
S5T#9990s. Any input above T#9990s returns S5T#9990s and clears BR; any input below the minimum resolution of the chosen base rounds toward the base. Always evaluate BR with SAVE or check OV if a value can exceed the S5TIME range.Method 2: TIA Portal Explicit Conversion for S7-1500
The S7-1500 system family supports direct explicit type conversion instructions between S5TIME and TIME/DWORD. The conversion is described in the TIA Portal help under "Data types > Data type conversion for S7-1500 > Timers (S7-1500) > Explicit conversion of S5TIME".
Available instructions:
| Instruction | Source | Target | Behavior |
|---|---|---|---|
S5TIME_TO_TIME |
S5TIME | TIME | Returns duration in ms |
S5TIME_TO_DWORD |
S5TIME | DWORD | Returns the raw 16-bit S5TIME image (base + BCD) |
S5TIME_TO_INT |
S5TIME | INT | Returns duration in ms (truncated to INT range) |
TIME_TO_S5TIME |
TIME | S5TIME | Encodes into the smallest possible base; overflow clips to S5T#9990s and sets ENO = 0 |
DWORD_TO_S5TIME |
DWORD | S5TIME | Reinterprets a 16-bit value as the S5TIME image |
These conversions are documented in the TIA Portal online help; see TIA Portal V20: Explicit conversion of S5TIME (S7-1500) for the official instruction set, status flags, and overloads.
SCL usage example (TIA Portal V16+):
// DB "RecipeTimes"
VAR
s5Preset : S5TIME; // HMI input
timeMs : TIME; // IEC value in ms
s5FromArith : S5TIME; // result of arithmetic, fed to S_ODT
END_VAR
timeMs := S5TIME_TO_TIME(s5Preset); // e.g. S5T#2m30s -> T#2m30s0ms
// perform arithmetic on timeMs:
timeMs := timeMs + T#10s;
// re-encode for an S5-style timer:
s5FromArith := TIME_TO_S5TIME(timeMs);
ENO (enable output) is set to 0 if the source value would overflow the destination. Connect ENO to a global error marker or to the "ERR" input of a downstream block to detect overflow without polling BR.
LAD/FBD on S7-1500
The converters are available as boxes under "Instructions > Converter operations". Drag S5TIME_TO_TIME or TIME_TO_S5TIME onto a network, connect the source tag and the destination tag, and compile. The status word and AR1/AR2 are not affected because the converter uses the standard IEC call interface.
Method 3: Manual SCL Conversion (S7-300/400/1200/1500)
If the FC library is unavailable, the conversion can be implemented manually by reading the time base and the BCD value, then multiplying. The implementation below matches the FC33 algorithm exactly.
FUNCTION "S5TimeToTime" : Time
VAR_INPUT
s5Input : S5TIME;
END_VAR
VAR_TEMP
wRaw : WORD;
nBase : INT; // 0..3
nBcd : DINT; // 0..999
nResult : DINT;
END_VAR
BEGIN
wRaw := DWORD_TO_WORD(S5TIME_TO_DWORD(s5Input));
nBase := WORD_TO_INT(wRaw AND 16#0003);
// BCD lives in bits 4..15, value 0..999
nBcd := BCD16_TO_DINT(SHR(IN:=WORD_TO_INT(wRaw AND 16#FFF0), N:=4));
CASE nBase OF
0: nResult := nBcd * 10; // 10 ms steps
1: nResult := nBcd * 100; // 100 ms steps
2: nResult := nBcd * 1000; // 1 s steps
3: nResult := nBcd * 10000; // 10 s steps
ELSE
nResult := 0;
END_CASE;
"S5TimeToTime" := DINT_TO_TIME(nResult);
END_FUNCTION
BCD16_TO_DINT is available in the "Standard Library > IEC Function Blocks" of TIA Portal. If the IEC function is missing, replace it with a nibble-wise decode loop:
FUNCTION "BcdToDint" : DINT
VAR_INPUT
iBcd : INT;
END_VAR
VAR_TEMP
i : INT;
n : DINT;
nib : INT;
src : INT;
END_VAR
BEGIN
src := iBcd;
n := 0;
FOR i := 0 TO 3 DO
nib := src AND 16#000F;
IF nib > 9 THEN
"BcdToDint" := -1; // invalid BCD
RETURN;
END_IF;
n := n * 10 + nib;
src := src SHR 4;
END_FOR;
"BcdToDint" := n;
END_FUNCTION
HMI Integration and Tag Mapping
HMI panels expect S5TIME for the legacy timer input fields. The recommended wiring is to keep a single S5TIME tag at the HMI boundary, convert once to TIME, perform the application logic in TIME, and convert back only when a value must be fed to an S5-style timer. This avoids drift caused by repeated round-trips between the two formats.
| HMI field | PLC tag | Type | Path to TIME |
|---|---|---|---|
| Operator preset (S5T#) | DB100.DBW0 | S5TIME | FC33 / S5TIME_TO_TIME |
| Recipe step duration (T#) | DB100.DBD4 | TIME | Direct use, multiply, scale |
| Arithmetic output to S5 timer | DB100.DBW8 | S5TIME | FC40 / TIME_TO_S5TIME |
| SCADA value (Ignition / WinCC) | DB100.DBD12 | TIME | Use TIME tag; format as HH:mm:ss in the SCADA |
For Node-RED environments, the Siemens S5Time converter flow wraps the conversion into two function nodes (Seconds to S5Time and S5Time to Seconds) that produce the same wire format as FC40 and FC33. Use it for tag mirrors that go to a Node-RED dashboard or to a cloud historian. For Ignition, store the TIME value in the PLC, expose it as a DINT (milliseconds) OPC tag, and let the Ignition expression language format the display value; do not try to consume S5TIME directly from the OPC server because most OPC stacks do not know the S5TIME encoding.
Verification Procedure
- Create a new VAT (variable table) or watch table in STEP 7 or TIA Portal. Add the S5TIME source tag and the TIME result tag.
- Force the S5TIME value to known points:
S5T#0s,S5T#10ms,S5T#1s,S5T#1m,S5T#1h,S5T#2h46m30s, andS5T#9990s. - Read the TIME result. It must equal the duration in ms. For example,
S5T#2h46m30s=9990 s = 9_990_000 ms. - Reverse direction: write a TIME value
T#9990sto the FC40 input. Read the S5TIME output; it must beS5T#9990sand BR/ENO must be 1. - Write a TIME value above the S5TIME maximum, e.g.
T#10000s. The S5TIME output must be clipped toS5T#9990sand BR/ENO must be 0. Connect BR to a status bit in the VAT and verify the bit is reset. - Force the S5TIME raw cell to
W#16#FFFF(BCD invalid, base 11) and read the TIME output. Some versions of FC33 returnT#0swith BR = 0; the TIA PortalS5TIME_TO_TIMEreturnsT#9990swith ENO = 0. Document the chosen behavior in the function description.
Troubleshooting Matrix
| Symptom | Likely cause | Diagnostic | Resolution |
|---|---|---|---|
| TIME result is always 0 | Source tag is not declared as S5TIME in the DB | Open DB in STEP 7 / TIA Portal and confirm data type | Set the DB element to type S5TIME; the editor will then reformat the initial value |
| TIME result is exactly 9990 s for any input | FC33/FC40 BR was not evaluated and the source contains garbage (e.g. uninitialized WORD) | Monitor BR / ENO and inspect the raw WORD | Initialize the S5TIME cell to W#16#0000 at startup; reject inputs that set BR=0 |
| Round-trip drift (TIME differs from original S5TIME) | Multiple conversions cascade (S5TIME → TIME → S5TIME) and the new base is coarser than the original | Log the S5TIME WORD before and after each conversion | Do the round-trip only at the HMI boundary; carry the value in TIME for all internal logic |
| HMI shows raw hexadecimal instead of S5T#x | HMI tag is typed as WORD instead of S5TIME | Open the HMI tag list and inspect the data type | Set the HMI tag type to S5TIME; rebuild the HMI project |
| EN/ENO on SCL converter is always 0 | Source tag is in an optimized DB and is read by symbolic name; the compiler cannot trace the symbolic address | Switch the SCL block to absolute addressing or uncheck "Optimized block access" on the data block | Restore the original DB attribute and recompile |
| S5T#1s round-trips to 10 ms or 1 s, not 1 s exactly | Editor auto-selected a finer base (10 ms) because the entry used the same value in ms | Re-enter the value as S5T#1s with cursor in the seconds field |
Accept the new base; treat both encodings as equal at 1 s |
| FC33 not found in the project | IEC Function Blocks library not installed | Open the library tree in SIMATIC Manager | Open the library "Standard Library > IEC Function Blocks" and copy FC33/FC40 into the project |
| TIA Portal: instruction not found on S7-1200 | Firmware < V4.0 does not include the S5TIME explicit converter | Check the device firmware in "Online & diagnostics" | Upgrade the CPU firmware or fall back to the FC33/FC40 pair in a compatible SCL block |
Edge Cases and Field Notes
Negative TIME values. The S5TIME data type has no sign bit, so any negative TIME passed to FC40 or TIME_TO_S5TIME is treated as out of range. The output becomes S5T#0s and BR/ENO is 0 on S7-1500, and the block also returns S5T#0s with BR = 0 on S7-300/400. Add a sign check before calling the encoder when the upstream arithmetic can produce negative durations.
Zero handling. Both encoders treat T#0s and S5T#0s identically (W#16#0000). Decoders preserve the value. This is the safe default for HMI pre-population.
Time-base ambiguity. A S5TIME value of W#16#1000 is BCD 100 with base 00 (10 ms) and represents 1 000 ms. A S5TIME value of W#16#1010 is BCD 10 with base 10 (1 s) and also represents 10 000 ms. The two encodings are not equivalent because the round-trip S5TIME → TIME → S5TIME will choose the most precise base. The result is the same effective duration but the raw WORD will change. Treat the S5TIME WORD as an opaque value, never as a checksum.
Library name in TIA Portal. On S7-1500 the explicit conversion is in the instruction catalog under "Basic instructions > Converter operations". On S7-1200 with firmware V4.0 or later the same instructions are available; on older S7-1200 firmware the explicit converters do not exist and the manual SCL implementation must be used.
Safety and SIL applications. For F-CPU work, keep the time value in TIME inside the standard program and route only the preset through S5TIME. Do not feed the encoder output back into a safety-related timer instruction; the S5TIME data type is not part of the F-runtime signature.
References and Linked Documentation
What is the maximum S5TIME value and why does the encoder clip larger values?
The maximum S5TIME is S5T#9990s (BCD 999, base 10 s). The encoder uses 12 BCD bits, so it can only store 0 to 999. FC40 and the TIA Portal TIME_TO_S5TIME instruction return S5T#9990s and set BR/ENO to 0 for any larger input.
Do FC33 and FC40 work on S7-1200 and S7-1500?
Yes. Copy FC33 and FC40 from the Standard Library > IEC Function Blocks into the project; they execute on every S7 CPU that supports the IEC library. On S7-1500, prefer the explicit conversion instructions S5TIME_TO_TIME and TIME_TO_S5TIME because they integrate with EN/ENO and the TIA Portal type checker.
How do I read a S5TIME value that the HMI wrote into the PLC?
Read the 16-bit WORD, mask the lower two bits to get the time base (0=10 ms, 1=100 ms, 2=1 s, 3=10 s), and decode the upper 12 bits as BCD to get the count 0 to 999. Multiply and you have the duration in ms. For an automated path, call FC33 S5TI_TIM or the S7-1500 instruction S5TIME_TO_TIME.
Why does my S5TIME value change after a round-trip through TIME?
The encoder picks the most precise time base, so the same duration can be stored with a different base and a different BCD count. The effective time is identical; only the raw 16-bit representation differs. Avoid using the S5TIME cell as a checksum.
Can I use S5TIME values directly in WinCC or Ignition?
WinCC on a Siemens HMI displays S5TIME natively when the tag type is set to S5TIME. Ignition does not know the S5TIME encoding; expose the duration as TIME/DINT in milliseconds from the PLC, then format the display value in the Ignition expression language (e.g. ms/3600000 for hours).