Resolving S5TIME Timer Value Mismatch in S7-300/400 STEP 7
When migrating or extending a STEP 7 (S7-300/S7-400) program, one of the most common timer-related defects is the apparent corruption of an S5TIME variable after a MOVE block. The display in the online monitor shows a duration that does not match the active timer's preset, often shifted by orders of magnitude. This article isolates the defect, explains the bit-level format of S5TIME, and provides three field-proven solutions plus a verification procedure.
1. Problem Overview
Symptom: a MOVE instruction in LAD/FBD reads the running value of a standard timer (S_ODT, S_PULSE, S_PEXT, S_ODTS, S_OFFDT) and writes it into a data block word declared as S5TIME. The destination is read back with a different numerical content, e.g. the timer is preset to S5T#6m25s and the DB word shows S5T#1s810ms.
Affected platforms: SIMATIC S7-300, S7-400, C7, ET 200S (IM 151) running STEP 7 V5.x and S7-PLCSIM V5.x. The same logic also applies to S7-1200 and S7-1500 timers using the legacy S5TIME format (with 16-bit width on S7-1200/1500 S5TIME (duration) reference page).
Impact: any HMI tag, archive, recipe, or PID block that reads the S5TIME variable gets an incorrect duration, which can cause:
- Recipe values written back to the timer with the wrong time base.
- Visualization of process timers that are off by 10×, 100×, or 1000×.
- False trip conditions when S5TIME is used as a threshold for comparison or alarm generation.
2. S5TIME Data Type: Bit-Level Structure
S5TIME is a 16-bit value composed of two concatenated fields: a 2-bit time base selector and a 12-bit BCD-coded time value (range 0 to 999). The result of multiplication is the actual time. The reference for the structure is the official Siemens documentation page S5TIME (duration) - S7-300/S7-400.
Total time is calculated as duration = BCD_value × time_base. The BCD field stores the time value as three 4-bit BCD digits (hundreds / tens / ones), which is critical: a MOVE instruction does not perform a BCD-to-binary or binary-to-BCD conversion, it only copies the 16 bits as-is.
Example encoding:
| Logical value | Time base | BCD value | Hex word | Bit pattern (15-0) |
|---|---|---|---|---|
| S5T#25s | 1s (10b) | 25 (BCD) | W#16#8025 | 1000 0000 0010 0101 |
| S5T#6m25s | 1s (10b) | 385 (BCD) | W#16#8385 | 1000 0011 1000 0101 |
| S5T#1s810ms | 10ms (00b) | 181 (BCD) | W#16#0181 | 0000 0001 1000 0001 |
| S5T#5s | 100ms (01b) | 50 (BCD) | W#16#2050 | 0010 0000 0101 0000 |
1010b in any nibble means the source is not S5TIME, even if the word is numerically plausible as a binary integer.3. Time Base Encoding Reference
| Bit 15-14 | Time base | Range covered (value × base) | Resolution | Use case |
|---|---|---|---|---|
| 00 | 10 ms | 10 ms to 9.99 s | 10 ms | Short pulse, debounce, fast filter |
| 01 | 100 ms | 100 ms to 99.9 s | 100 ms | Default for S_ODT (5 s) and most HMI parameters |
| 10 | 1 s | 1 s to 999 s | 1 s | Pump, valve, motor cooldown |
| 11 | 10 s | 10 s to 9990 s (≈2 h 46 min) | 10 s | Long process, lubrication, drying |
For S7-1200/1500, Siemens provides an extended 32-bit S5TIME variant (time bases 1 ms, 10 ms, 100 ms, 1 s, 10 s) that can store up to 9 999 000 ms (~2.78 h) with the same BCD + time-base principle. The 16-bit format documented above applies to S7-300/400 only.
4. Timer Block Outputs: BI vs BCD
Every SIMATIC timer block in LAD/FBD exposes three outputs:
| Output | Type | Width | Encoding | Suitable for S5TIME? |
|---|---|---|---|---|
| BI | WORD (binary integer) | 16 bit | Current time value in time-base units (e.g. 385 means 385 × 1 s if base = 1 s) | No |
| BCD | WORD (BCD, S5TIME format) | 16 bit | Time base (bits 15-14) + 3 BCD digits (bits 11-0) | Yes |
| Q | BOOL | 1 bit | Timer status (1 = running) | N/A |
In STL, the same two words are accessed with the two distinct load operations:
-
L T<n>- load current timer value in BCD format (S5TIME). -
LC T<n>- load current timer value as binary integer (BI).
The naming is sometimes confusing: the LAD pin labelled BI corresponds to LC T<n> in STL, and the LAD pin BCD corresponds to L T<n>.
5. Root Cause: Why MOVE on BI Returns the Wrong Value
Three defects accumulate when a developer wires the BI pin into a MOVE box and stores the result in an S5TIME variable:
-
No format conversion. The
MOVE(a.k.a.BLKMOVin FBD/STL) block performs a byte-level copy. It does not perform a binary-to-BCD conversion. -
Missing time-base bits. The BI word is a pure integer; bits 15-14 are always 0b00 (time base 10 ms). When the target is interpreted as
S5TIME, the time base is forced to 10 ms regardless of the actual preset. - Value field is binary, not BCD. The BI word stores a binary integer, so a timer preset to 385 s with time base 1 s delivers 385 in the BI word. The destination S5TIME interprets those 12 low bits as BCD, giving 385 × 10 ms = 3.85 s instead of 385 s.
Combined effect: a one-line MOVE appears to work because the word size matches, but the time becomes wrong by a factor of 10, 100, 1000, or even 1.5 if the BCD digits happen to look similar (for example 1000b in a BCD nibble makes the value unreadable in S5TIME display).
MOVE is defined in IEC 61131-3 as a pure assignment of the source bit pattern to the destination. There is no implicit conversion in the language. The conversion has to be done explicitly by the user with an encoder function block or with the BCD pin of the timer.6. Solution 1: Wire the BCD Output of the Timer
The most compact fix in LAD/FBD: route the BCD pin of the timer block into a MOVE box whose output is the S5TIME tag in the data block.
Steps:
- Open the timer block in the network. The default view in LAD/FBD hides the BCD pin; click the small arrow at the bottom of the timer block to expand it.
- Place a
MOVEbox. SetEN= TRUE (or wire a condition if you need gating). - Wire the BCD output to the
INof theMOVE. - Wire the
OUTto the S5TIME tag, e.g.DB178.DBW36of typeS5TIME. - Download the program. Open the DB online and verify that the value matches the timer preset while the timer runs.
The BI pin can still be used in parallel if you need a pure integer for a comparison (==I, <I, etc.). Do not write the BI value into an S5TIME tag.
7. Solution 2: STL Transfer with L T<n>
If the network is already in STL (typical after a generated FBD-to-STL translation), the BI/BCD ambiguity is resolved with the choice of the load operation:
// Network 19 - transfer S5TIME-format value to DB word
L T1 // Load current value of T1 in S5TIME/BCD
T DB178.DBW36 // Store to S5TIME tag
// Network 20 - integer snapshot for math/compare
LC T1 // Load current value of T1 as binary (BI)
T MW120 // Store as WORD (integer)
The two operations are intentionally opposite to the LAD pin names. Use L for S5TIME and LC for integer work.
For an IEC timer (SFB 3 / SFB 4 / SFB 5 with multi-instance DB), the elapsed-time output is ET in 32-bit TIME format (milliseconds), not S5TIME. Direct assignment to an S5TIME tag is invalid; you must convert (see Section 9).
8. Solution 3: Direct S5TIME Encoding
Use this solution when the value comes from arithmetic (PID, scaling, recipe) rather than from a hardware timer. Build the word with the time base in bits 15-14 and the BCD value in bits 11-0. The approach is to load the BCD value, shift it left by 4, OR the time-base bits, and transfer.
// Parameters
// MW100 = time value in tenths-of-seconds (DINT, 0..999) -- pick whatever scale
// MW102 = time base code (0=10ms, 1=100ms, 2=1s, 3=10s)
// DB178.DBW36 = destination S5TIME
L MW100 // load integer time value
ITB // INT -> BCD (accumulator low word now BCD)
SRD 4 // shift BCD value left by 4 bits: clears time-base slot
L MW102 // reload time base (must be 0..3)
OW // OR with shifted BCD value
T DB178.DBW36 // store S5TIME
Decomposition:
-
ITBconverts the integer time value to BCD in ACCU1-L. After conversion, the low word is the BCD pattern (each 4-bit nibble is a 0-9 digit). -
SRD 4shifts the doubleword right by 4 bits, which positions the BCD digits into bits 11-0 and clears bits 15-12. -
OWinserts the time-base code (0..3) into bits 15-14.
Resulting layout: bits 15-14 = time base, bit 13-12 = 0, bits 11-0 = BCD value. This matches the S5TIME layout described in Section 2.
GRT 999 check. If the input time base code is outside 0..3, the time-base field is corrupted. Validate both before the T.9. S5TIME from IEC Timers and TIME Format
IEC timers (SFB 3 TP, SFB 4 TON, SFB 5 TOF) operate on the 32-bit TIME data type: 1 unit = 1 ms, range -2 147 483 648 ms to 2 147 483 647 ms. The block output is at the ET (elapsed time) parameter.
To expose the IEC timer value as S5TIME on a tag, you need a DINT→S5TIME conversion. A common engineering pattern uses a standardized function block (FB) that:
- Limits the DINT to ≤ 9 990 000 ms (the S5TIME range upper bound is 9 990 s with time base 10 s).
- Selects the largest time base that keeps the BCD value ≤ 999.
- Encodes the result as in Section 8.
// Pseudocode (ST) for DINT-to-S5TIME conversion
// IN : LTime (DINT, ms)
// OUT : S5Time (WORD)
IF LTime < 100 THEN // < 0.1 s -> 10 ms base
S5Time := (LTime / 10) * 16#0001; // base bits = 00
ELSIF LTime < 1000 THEN // < 1 s -> 100 ms base
S5Time := (LTime / 100) * 16#0001 + 16#4000; // base bits = 01
ELSIF LTime < 10000 THEN // < 10 s -> 1 s base
S5Time := (LTime / 1000) * 16#0001 + 16#8000;// base bits = 10
ELSE // 10 s..9990 s -> 10 s base
IF LTime > 9990000 THEN LTime := 9990000; END_IF;
S5Time := (LTime / 10000) * 16#0001 + 16#C000;// base bits = 11
END_IF;
The same FB can be reused in reverse (S5TIME→DINT) for recipe loads. For HMI drivers that already accept ms integer, e.g. Beijer iX panel drivers for S7 ISO-over-TCP/IP, the value can be written directly to a DINT tag; the driver expects the millisecond range 10-9 990 000 per the Beijer Electronics S7 addressing reference. The driver does the S5TIME encoding internally.
10. Verification Procedure
Use the following check sequence after applying any of the three solutions.
-
Static check (no timer running). With the timer reset, the S5TIME tag should show
S5T#0msorW#16#0000. If it shows a small non-zero value, the BI pin is still wired and the bug persists. -
Preset snapshot. Set the timer TV to a known value, e.g.
S5T#1m30s. Trigger the timer (rising edge on S) and immediately read the destination. The hex word should beW#16#8090(BCD 090, time base 1 s) - if it isW#16#0090the time base is wrong, if it isW#16#805Athe value was interpreted as binary 90 instead of BCD 090. - Dynamic check. Monitor the destination online for at least one full time-base tick. The value should count down, in BCD, until it hits zero. A linear binary decrement indicates the wrong pin was wired.
- HMI round-trip. From the HMI, force a new preset into the timer. The destination should match the new preset (BCD + time base) within one CPU scan.
- Cross-reference sweep. Use Options > Cross Reference in STEP 7 to confirm the destination S5TIME tag is not also written by other blocks (e.g. recipe download, OP input) that use the BI pin elsewhere - duplicate writers can re-introduce the bug.
11. Troubleshooting Matrix
| Symptom | Likely cause | Diagnostic | Fix |
|---|---|---|---|
| DB shows 0.1× to 1000× of expected duration | BI pin wired instead of BCD pin | Inspect network: BI/BCD pin in LAD; or LC vs L in STL |
Wire the BCD pin; replace LC with L
|
| DB shows 0 even when timer is running | Destination is WORD, not S5TIME; display interprets as 0 |
Open the DB, verify the data type column shows S5TIME
|
Change declaration of the data block word to S5TIME
|
| DB shows "invalid BCD" or asterisks | Source contains hex digits A-F (BI word used as source) | Look at the hex value of the BI word; any nibble ≥ 0xA is the BI pin | Switch source to the BCD pin or use a converter |
| DB shows 9990 s and never counts down | Time base coded as 11 (10 s) but the value 0 is in the high nibble | Hex 0xC000 means time base 11, value 0 |
Check encoder FB; ensure that the value 0 path does not set time base 11 |
| Value is right at start of cycle, wrong at next scan | Multiple writers to the same DB word (BI from one net, BCD from another) | Cross-reference on the DBW | Remove the BI writer or change the MCR / enable flags |
| DB shows S5T#2h46m30s when preset is 9 s | Value is in ms and the encoder picks 10 s base | Check the input scaling; ms input must be divided by 10000 before the encoder picks base 11 | Use the FB in Section 9; clamp to 9 990 000 ms |
12. Field Notes and Best Practices
-
Prefer IEC timers for new code.
SFB 4(TON) gives a clean DINTETand integrates with IEC 61131-3 idioms. Use S5TIME only for compatibility with existing HMIs, recipes, or S5-converted code. -
Document the time base. Tag names like
CycleTime_S5are useless; useCoolDown_S5_1sBaseor annotate the time base in the DB header. - Never mix BI and BCD writers. If a recipe loads the S5TIME tag in BCD form (e.g. via HMI driver) and the timer logic also writes it via BI, the last-writer-wins race will produce intermittent faults. Use a single owner of each S5TIME tag.
-
Watch the 999/1000 boundary. STEP 7 silently changes the time base when entering a value through the editor.
999suses base 1 s;1000suses base 10 s. Do not transcribe by hand; always read the resulting hex from the editor. -
S7-300/400 timer areas are 256 words.
T0-T255. In STL use only the absolute area address; the symbolic name (e.g.Timer_1) in some projects does not resolve on theL/LCoperation - use the absolute name in the address field. - PLCSIM parity. The same code reproduces the same hex patterns in S7-PLCSIM. You can validate the fix offline in seconds without hardware.
-
Cross-platform consistency. On S7-1200/1500 the IEC timer output
ETis also 32-bitTIME. The same FB from Section 9 can be reused; the time-base code 0..3 maps to the S5TIME 16-bit layout supported by the S7-1200/1500 firmware for backward compatibility.
Why does the MOVE instruction not convert BCD to integer?
MOVE (and the related BLKMOV, UW, OW primitives) is defined by IEC 61131-3 as a pure bit-pattern copy. STEP 7 does not add implicit conversions. To move a BCD value into an integer tag you must explicitly invoke ITB (integer to BCD) or BTD (BCD to integer), and to write an S5TIME from an integer you must also place the time base in bits 15-14.
What is the difference between the BI and BCD pins of a SIMATIC timer block in LAD/FBD?
BI is the current time value as a 16-bit binary integer in time-base units (no time base encoded); BCD is the same value already encoded in S5TIME format (time base in bits 15-14, BCD value in bits 11-0). To populate an S5TIME tag, wire the BCD pin. For pure comparison or scaling, use the BI pin and a WORD or INT tag.
Can I write a value in milliseconds into an S5TIME tag directly?
No. The S5TIME word is 16 bits and follows the BCD-plus-time-base format described by Siemens. A value in milliseconds must be scaled to the largest applicable time base (10 ms, 100 ms, 1 s, 10 s) so the BCD field stays in 0-999, then encoded. Use the FB pattern in Section 9 or rely on a driver that does the conversion (for example the Beijer iX S7 ISO-over-TCP/IP driver accepts values in the 10-9 990 000 ms range per the official addressing documentation).
What is the maximum time S5TIME can store on an S7-300/400?
With the 16-bit layout, the maximum is 999 × 10 s = 9 990 s (≈2 h 46 min 30 s). For longer times, switch to a 32-bit TIME tag (range about ±24.8 days) on an IEC timer, or use a counter plus time-base extension. S7-1200/1500 supports an extended 32-bit S5TIME up to 9 999 000 ms (~2.78 h) per the official Siemens S5TIME reference page.
Why does my S5TIME tag show a different value in the HMI than in STEP 7 online?
Two common causes: (1) the HMI tag is declared as WORD or INT instead of TIME/S5TIME, and the visualization driver shows the raw integer in ms or in time-base units. (2) The HMI reads the BI word through a custom driver script and re-encodes with the wrong time base. Re-declare the HMI tag as S5TIME (or as TIME in ms with a converter in the PLC) and confirm the driver expects S5TIME. The Siemens S5TIME (duration) page (S5TIME S7-300/S7-400) gives the exact layout the driver should reproduce.