Siemens S5Time Data Type BCD Format, Range Limits, and FC40

David Krause13 min read
SiemensTechnical ReferenceTIA Portal
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

Overview

The S5TIME data type (also written S5Time, S5T#) is the legacy duration format used by the SIMATIC S5 and S7-300/S7-400 timer functions. It encodes a preset value in a compact 16-bit word so that any value between 10 ms and 9 990 s (2 h 46 min 30 s) can be expressed with only one BCD word in the controller's I/O image. Although TIA Portal V13 and later prefer the TIME (IEC 61131-3) data type with the SFB/SFC timer blocks (IEC_TP, IEC_TON, IEC_TOF), STEP 7 Professional V13.0 still ships the original pulse generators SP, SE, SD, SS, SF that consume an S5TIME word directly.

This reference documents the bit layout, timebase selection, range calculations, FC40/IEC conversion, ladder conversions, and field-verified troubleshooting for engineers who must interface existing ladder code, SCADA/HMI tags, or third-party drivers that expose the 16-bit BCD word. The official Siemens entry is the S5TIME (duration) topic in the STEP 7 Professional V13.0 help, ID 89515142, available at the Siemens Industry Online Support portal and the TIA Portal V20 cloud manual.

S5Time Bit Layout and BCD Encoding

An S5TIME value occupies exactly 16 bits of memory, typically a data word (MW), data block word (DBW), or a temporary local word (LW). The layout follows the classic SIMATIC S5 KT format:

  15  14  13  12   11  10   9   8    7   6   5   4    3   2   1   0
+---+---+---+---+----+----+----+----+----+----+----+----+----+----+----+----+
| T | T | T | T | B  | B  | B  | B  | B  | B  | B  | B  | B  | B  | B  | B  |
| 3 | 2 | 1 | 0 | 3  | 2  | 1  | 0  | 3  | 2  | 1  | 0  | 3  | 2  | 1  | 0  |
+---+---+---+---+----+----+----+----+----+----+----+----+----+----+----+----+
         4-bit timebase                12-bit BCD value (3 BCD digits, 0-999)
  • Bits 15-12 (high nibble): Timebase code in BCD. Only values 0, 1, 2, and 3 are valid.
  • Bits 11-0: Three BCD digits representing the count of timebases from 0 to 999.
  • Storage: Always loaded with the S5TIME format attribute; the CPU does the multiply internally when the timer is started.

The physical elapsed time the timer runs is the product time = count × timebase. Because the count is constrained to 0-999, the maximum value in each timebase is:

Timebase code (BCD) Timebase duration Minimum time Maximum time (count=999)
0000 10 ms 10 ms (count=001) 9 990 ms = 9.99 s
0001 100 ms 100 ms (count=001) 99 900 ms = 99.9 s
0010 1 s 1 s (count=001) 999 s = 16 min 39 s
0011 10 s 10 s (count=001) 9 990 s = 2 h 46 min 30 s
Maximum theoretical range: 9 990 s = 2 h 46 min 30 s. Values above 9 990 s cannot be encoded in a single S5TIME word and must be split into cascaded timers or migrated to IEC TIME / SFB timer blocks.

Why BCD Instead of Integer

The BCD encoding dates back to the SIMATIC S5 era. Three advantages justify the format for legacy designs:

  1. Display on HMI five-digit LEDs: the upper nibble selects the decimal-point position; the lower three digits are the count.
  2. Human readability: a debugger or printout of the word reads as W#16#3999 (timebase 3, count 999) instead of an opaque integer.
  3. Compact storage: 16 bits cover a 1:1 000 000 dynamic range (10 ms to 9 990 s) without integer overflow.

The trade-off is that arithmetic on S5TIME must use the IEC conversion block (FC40) or the explicit ITD/DTB/BCD_I sequence described in the conversion section.

Timer Coil Instructions That Consume S5TIME

STEP 7 / TIA Portal still provides five legacy timer instructions whose preset input expects an S5TIME word. Each loads the running time into the corresponding IEC bit memory timer (T 0 to T 255 on S7-300, T 0 to T 2047 on S7-400).

Instruction Symbol Behavior
SP Start pulse timer Output on for the preset duration on a rising edge of the input.
SE Start extended pulse timer Output on for the preset duration; retriggerable.
SD Start ON-delay timer Output on after preset time has elapsed while input is still high.
SS Start retentive ON-delay Latched ON-delay; output stays high until reset.
SF Start OFF-delay timer Output stays high for preset time after input goes low.

The preset can be supplied in three ways:

  1. Direct literal: S5T#2s500ms, S5T#1m30s, or S5T#2h46m30s. The compiler converts to BCD with the smallest possible timebase.
  2. Symbolic tag of type S5TIME: assigned in the PLC tag table or DB.
  3. Word (MW / DBW / LW): loaded with the BCD value at runtime. This is the path used when the time is calculated in user code or sent from an HMI.
Field-proven pitfall: assigning the symbolic format S5TIME to a memory word forces the editor to validate BCD digits. Using a plain WORD tag bypasses validation but the CPU still expects BCD at the timer input. Mismatched formats cause the timer to ignore the value, run for 0 ms, or behave erratically. See the troubleshooting matrix at the end of this article.

IEC Conversion: Standard Library FC40

The cleanest path to drive an S5TIME input from a DINT millisecond value is the standard library function FC40 "IEC_Time_to_S5Time", supplied with every STEP 7 Professional installation.

Interface

Parameter Type Direction Description
IN DINT (TIME) IN Duration in milliseconds (0 ... 9 990 000).
RET_VAL WORD (S5TIME) OUT BCD-encoded S5TIME word with auto-selected timebase.
OUT_STATUS BYTE OUT Status: 0 = OK; non-zero = out of range or invalid BCD.

Selection Rules Used by FC40

FC40 picks the smallest timebase that still keeps the count ≤ 999. The selection algorithm is:

IF IN <=      9 990 THEN timebase := 10ms  count := IN / 10
ELSE IF IN <=    99 900 THEN timebase := 100ms count := IN / 100
ELSE IF IN <=   999 000 THEN timebase := 1s   count := IN / 1000
ELSE IF IN <= 9 990 000 THEN timebase := 10s  count := IN / 10 000
ELSE  OUT_STATUS := W#16#80 (range overflow)

Inputs above 9 990 000 ms (2 h 46 min 30 s) are rejected with OUT_STATUS = W#16#80; the function returns 0 in RET_VAL. Inputs that round to a BCD count above 999 are also rejected; the caller must pre-validate or split the time into multiple cascaded timers.

Call Example (ST / SCL)

// Drive an SD ON-delay timer from a DINT tag "Setpoint_ms"
VAR
    s5word : WORD;        // BCD S5TIME word
    status : BYTE;
END_VAR

FC40( IN := Setpoint_ms, RET_VAL := s5word, OUT_STATUS := status );
IF status = 0 THEN
    "Timer_DB".Preset := s5word;   // DBW of type S5TIME
END_IF;

Manual BCD Conversion in Ladder

On older CPUs without the standard library, or when a long sequence of timers is generated from a recipe, the manual approach mirrors the historical "KT-from-integer" routine:

  1. Accept an INT or DINT (ms) input.
  2. Normalize it into a value ≤ 9 990 000.
  3. Detect the appropriate timebase using four compare/coil branches.
  4. Divide the value by the timebase to produce the count (0-999).
  5. Convert the count to BCD with the ITB / BCD_I conversion.
  6. OR the timebase nibble into the high nibble of the word with WOR_W (16-bit word OR).
  7. Move the resulting word to the timer's preset input.

Ladder Fragment (STEP 7 Classic)

Network 1 - select 1 s timebase
A   "Preset_ms_valid"
L   "Preset_ms"
L   9990       // max ms for 10 ms base
>I
JCN TB1
L   "Preset_ms"
ITD
DTR
L   1.0e+1
/R
TRUNC
T   "tmp_count"
Network 2 - build BCD word for 10 ms timebase
TB1: L   "tmp_count"
      ITB             // INT to BCD
      L   W#16#0000   // timebase 0 in high nibble
      OW
      T   "Preset_s5t"

The same pattern is repeated three more times for 100 ms (timebase = W#16#1000), 1 s (W#16#2000), and 10 s (W#16#3000) timebases. Finally the four partial words are OR-ed into one S5TIME word so that the active branch wins:

L   "Preset_s5t_TB0"
L   "Preset_s5t_TB1"
OW
L   "Preset_s5t_TB2"
OW
L   "Preset_s5t_TB3"
OW
T   "Timer_DB".Preset_S5T
Common bug: mixing INT and DINT. The ITB conversion accepts only 0-999; values above that trip CPU error SF (BCD conversion error) in some firmware. Always scale the count to ≤ 999 before ITB. Refer to the Siemens S5TIME help ID 89515142 for the canonical limits.

S5TIME Versus TIME (IEC 61131-3)

Property S5TIME TIME (IEC)
Width 16 bits (BCD) 32 bits (signed DINT, ms)
Range 10 ms to 9 990 s -2 147 483 648 ms to +2 147 483 647 ms (≈ 24.8 days)
Resolution Coarse, timebase-dependent 1 ms
Consumed by SP / SE / SD / SS / SF IEC_TP, IEC_TON, IEC_TOF, IEC_TIMER (SFB)
Storage BCD in MW / DBW DINT in MD / DBD
Typical use Legacy ladder, compact HMI tags Modern TIA Portal blocks, SCL arithmetic

For new developments on S7-1200, S7-1500, and S7-300/400 with TIA Portal V13 or later, prefer IEC_TIME and the SFB3/4/5 blocks because:

  • The IEC range covers minutes, hours, and days without cascading.
  • The IEC timer provides elapsed-time outputs (ET) for diagnostics.
  • Arithmetic on TIME (addition, subtraction, scaling) is native DINT math.

S5TIME remains mandatory only when the timer coils SP/SE/SD/SS/SF are retained, when an HMI tag or third-party OPC driver exposes the raw 16-bit word, or when the system is locked to STEP 7 V5.x without an IEC standard library.

HMI and SCADA Interface Considerations

An HMI "I/O field" bound to an S5TIME word can either accept a literal (e.g. S5T#5s) or a 16-bit integer written by the panel. To accept an integer from WinCC, FactoryTalk View, or Wonderware InTouch:

  1. In the PLC tag table, declare the tag as WORD (not S5TIME) so the editor does not mask the high nibble.
  2. In the HMI variable, set the data type to UINT 16 or BCD16 depending on driver.
  3. Compute the BCD word in the PLC by dividing the operator value (in tenths of a second) and OR-ing the timebase nibble, or send the seconds value as a DINT and run FC40 on the PLC side.

The Siemens SiePortal int↔s5time thread documents the same flow with concrete tag mappings.

Troubleshooting Matrix

Symptom Likely root cause Diagnostic step Fix
Timer fires immediately (0 ms) Preset word = 0 (high nibble cleared or count = 0) Cross-reference the preset in VAT; check the high nibble with status display Ensure timebase nibble is set (≥ W#16#0000) and count ≥ 1
Timer never fires (latched) Timebase nibble = 4-F (illegal BCD) or count > 999 Watch the preset in PLCSIM Restrict input to 1-9 990 000 ms and re-run FC40
Step7 BCD conversion error SF ITB fed a value above 9999 Check arithmetic Scale the count to ≤ 999 before ITB
Compiler rejects the WORD tag Tag is symbolic S5TIME; high nibble mismatch Inspect DB type Switch to WORD format or pre-build the BCD correctly
FC40 returns OUT_STATUS ≠ 0 Input above 9 990 000 ms or negative Read OUT_STATUS byte Clamp input; cascade two SD timers for ≥ 2 h 47 min
HMI shows wrong duration HMI writes raw integer; PLC expects BCD Compare raw HMI value with expected BCD Use DINT path + FC40 instead of direct MW write
Display on 5-digit LED shifted Timebase nibble wrong Verify BCD nibble Recompute using the timebase table above

Verification with PLCSIM

Before loading code to a physical CPU, validate every S5TIME timer in PLCSIM with the following sequence:

  1. Open the project in TIA Portal / STEP 7 and start S7-PLCSIM.
  2. Download the hardware and software to the simulated CPU.
  3. Create a Variable Table (VAT) that contains the timer preset word (WORD), the timer number (T n), and the timer enable input.
  4. Force the preset to each boundary value: W#16#1000 (1 × 100 ms), W#16#2999 (999 s), and W#16#3999 (9 990 s). Trigger the timer and observe the run-time bit and ET.
  5. Force an illegal BCD nibble (e.g. W#16#4001). The CPU should reject the value; check the diagnostic buffer for BCD conversion errors.
  6. Drive FC40 from a DINT that walks 0 → 9 990 000 → 0 and confirm the BCD output matches the timebase table above.

PLCSIM does not run the actual 1-ms system clock as accurately as physical hardware, so for time-critical acceptance tests loop the timer into a millisecond counter from the CPU clock memory (OB1 scan-time tick).

Migration to IEC TIME (Optional)

If a system must move from S5TIME to the IEC TIME type, perform the following substitution:

  • Replace each SD/SS/SP/SE/SF coil with the matching IEC_TON, IEC_TOF, IEC_TP, IEC_TONR block from the TIA Portal "Timers" palette.
  • Change the preset tag from S5TIME to TIME (literal T#2s500ms).
  • Use the built-in TIME_TO_BCD / BCD_TO_TIME functions if any external consumer still needs the BCD word.
  • Validate with a step test of 1 s, 1 min, 1 h, and 24 h to confirm the wider IEC range.

FAQ

What is the maximum value an S5TIME word can represent?

An S5TIME word encodes a count (0-999) and a timebase (10 ms, 100 ms, 1 s, or 10 s). The largest legal value is W#16#3999, which equals 999 × 10 s = 9 990 seconds or 2 h 46 min 30 s. Values above this cannot fit in the 16-bit BCD word.

How do I convert a DINT millisecond value to S5TIME on an S7-300?

Call FC40 from the STEP 7 standard library: FC40(IN := ms_value, RET_VAL := s5word, OUT_STATUS := status). The function selects the smallest possible timebase and returns the BCD word. Inputs above 9 990 000 ms are flagged in OUT_STATUS.

Why does my S5 timer run for zero seconds after I write a value from the HMI?

The HMI typically writes an INT or UINT into the tag. The CPU expects the high nibble to contain the BCD timebase code. If the high nibble is 0 because the HMI never sets it, the timer interprets the count as 10 ms × count. Solution: either pre-format the value in the PLC with FC40, or have the HMI send the time as a DINT and convert on the PLC side.

Can an S5TIME value exceed 2 h 46 min 30 s?

No. S5TIME is limited to 9 990 s. To obtain longer delays, cascade two SD timers (the second triggered by the first), or migrate to the IEC TIME data type and IEC_TON/IEC_TOF blocks that support durations up to 24.8 days.

Which timer coils accept an S5TIME word?

The five legacy coils SP (pulse), SE (extended pulse), SD (ON-delay), SS (retentive ON-delay), and SF (OFF-delay) all consume a 16-bit S5TIME word. Modern IEC blocks (IEC_TP, IEC_TON, IEC_TOF, IEC_TONR) instead consume a TIME/DINT input.

Why does the compiler refuse a WORD tag for the timer preset?

If the tag is symbolically typed as S5TIME, STEP 7 validates that the loaded value is a legal BCD with a timebase of 0, 1, 2, or 3. Use a plain WORD tag if you intend to compute the BCD in user code, or build the value with FC40 to remain type-safe.

Is S5TIME still supported in TIA Portal V20?

Yes. The TIA Portal V20 S5TIME documentation retains the data type for legacy S7-300/S7-400 timer instructions. New programs can use TIME and IEC timer blocks instead.

Summary

The S5TIME data type is a compact, BCD-encoded 16-bit duration word that survived from the SIMATIC S5 generation into the current STEP 7 and TIA Portal toolchains. By reserving the high nibble for the timebase (10 ms, 100 ms, 1 s, 10 s) and the remaining 12 bits for a BCD count (0-999), it covers 10 ms to 9 990 s in a single word, ideal for SP/SE/SD/SS/SF timer coils. For new designs, prefer the 32-bit IEC TIME format and the IEC_TP/IEC_TON/IEC_TOF/IEC_TONR blocks; reserve S5TIME for legacy ladder, HMI-bound words, and external drivers that consume the BCD word. Use FC40 for safe DINT-to-S5TIME conversion, validate boundaries with PLCSIM, and follow the troubleshooting matrix when a timer fires immediately, never fires, or returns a BCD conversion error.

Back to blog