How to Handle Operator Time Values Between WinCC Faceplates and SCL Blocks in SIMATIC PCS 7
In SIMATIC PCS 7 and STEP 7 SCL programming, operator time values entered in seconds via WinCC faceplates (typically as floating-point REAL variables) do not map directly to the IEC standard TIME data type inside the controller. The IEC TIME data type is represented internally as a signed 32-bit double integer (DINT) storing duration in milliseconds. If an operator enters '10.0' seconds into a faceplate, assigning this directly to a TIME variable results in a 10-millisecond duration rather than 10 seconds. To convert correctly in SCL, multiply the REAL input by 1000.0, convert to DINT, and cast to TIME using 'DINT_TO_TIME(REAL_TO_DINT(DigTimDel * 1000.0))'.
Table of Contents
- IEC TIME Data Type Representation in SIMATIC S7 Controllers
- Floating-Point REAL Operator Inputs vs Internal Millisecond Counters
- SCL Conversion Algorithms and Clamping Rules
- Advanced Process Library (APL) Time Value Conventions
- Comparison of Time Data Types and Conversion Functions in SCL
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
IEC TIME Data Type Representation in SIMATIC S7 Controllers
In the SIMATIC S7-400 architecture, time handling conforms to IEC 61131-3 standards. Understanding internal memory representation is essential for custom block development in Structured Control Language (SCL):
- The IEC TIME Format:
- Occupies 32 bits (one double word / DINT).
- Measures time in milliseconds as an absolute integer counter.
- Range:
T#-24d20h31m23s648mstoT#+24d20h31m23s647ms(Integer values-2,147,483,648to+2,147,483,647ms). - An IEC TIME literal of
T#10sis stored in CPU memory as hexadecimalDW#16#00002710(decimal10,000ms). - The S5TIME Format:
- Legacy 16-bit BCD format used by classic S5 timers. In modern PCS 7 APL development, S5TIME is deprecated in favor of IEC TIME or direct REAL cycle integration.
Floating-Point REAL Operator Inputs vs Internal Millisecond Counters
When designing an operator faceplate in WinCC Graphics Designer:
- Process engineers expose operator time parameters (such as
DigTimDelfor digital alarm delay, motor run monitoring times, or flush durations) as floating-point REAL numbers in seconds (e.g.,10.5seconds). - The Bug Mechanism: If the SCL block declares
DigTimDel : REAL;and attempts a naive conversionTimeVal := DINT_TO_TIME(REAL_TO_DINT(DigTimDel));, entering10on the faceplate passes the integer10directly into the millisecond counter. - The timer will expire in 10 milliseconds (a fraction of a single CPU cycle) rather than 10 seconds, causing immediate false trips or alarm triggers.
SCL Conversion Algorithms and Clamping Rules
To implement robust, bulletproof time handling in custom SCL blocks:
- Conversion Algorithm (Seconds to TIME):
pascal // Multiply seconds by 1000.0 to convert to milliseconds, // clamp to prevent mathematical overflow, and cast to TIME. IF DigTimDel < 0.0 THEN InternalTime := T#0ms; ELSIF DigTimDel > 2147483.0 THEN InternalTime := T#24d20h31m23s647ms; // Maximum positive IEC TIME ELSE InternalTime := DINT_TO_TIME(REAL_TO_DINT(DigTimDel * 1000.0)); END_IF; - Reverse Conversion (Remaining Time to Display Output):
* To report remaining delay time back to the operator faceplate in seconds:
pascal // Convert internal TIME back to floating-point seconds DigTimRem := DINT_TO_REAL(TIME_TO_DINT(InternalTimer.ET)) / 1000.0; - Using Cycle Time (SAMPLE_T) Integration:
* For continuous PID or ramp calculations, rather than usingTONtimer blocks, accumulate the cyclic execution periodSAMPLE_T(provided by PCS 7 OB30–OB38 schedulers):
pascal IF TimerActive THEN ElapsedSec := ElapsedSec + SAMPLE_T; END_IF;
Advanced Process Library (APL) Time Value Conventions
In the Siemens Advanced Process Library (APL), time parameters adhere to standardized technological conventions:
- Pure REAL Seconds Convention: Modern APL blocks (such as
TimerP,MonAnL, andMotL) do not expose the IECTIMEdata type to WinCC. All operator and engineering delay parameters are defined strictly asREALrepresenting seconds. - High/Low Clamping: APL blocks incorporate high and low limits (
Ti_OpScale.High/Low) configured in CFC to prevent operators from entering negative numbers or astronomically high durations that could lock safety interlocks. - Standard OCM Attributes: Parameters are decorated with system attributes:
pascal DigTimDel { S7_m_c := 'true'; S7_unit := 's'; S7_shortcut := 'Delay' } : REAL := 10.0;
Comparison of Time Data Types and Conversion Functions in SCL
The table below outlines time representation formats and standard conversion routines in SIMATIC STEP 7 SCL.
DINT_TO_TIME(val) / TIME_TO_DINT(val)REAL_TO_DINT(val) / DINT_TO_REAL(val)S5TI_TO_TIME(val) / TIME_TO_S5TI(val)DT_TO_TOD(val) / DT_TO_DATE(val)TOD_TO_DINT(val) / DINT_TO_TOD(val)Verification
To verify that time value conversion operates properly:
1. In the CFC editor, insert the compiled SCL block into an OB35 (100 ms) cyclic task.
2. Interconnect parameter DigTimDel to a WinCC analog input object with unit s.
3. Switch CFC to Test Mode: enter 10.0 at parameter DigTimDel.
4. Inspect the internal converted TIME variable: verify it displays T#10s (or 10000 ms).
5. Trigger the timer condition: verify using a stopwatch that the output delay flag trips after exactly 10.0 seconds.
6. Enter boundary conditions (-5.0 and 3000000.0): verify that internal clamping prevents mathematical faults or CPU overflow traps.
Limitations and Operational Precautions
- Never perform unconstrained
REAL_TO_DINTconversions without bounds checking; floating-point values exceeding2,147,483.0seconds will trigger a CPU math overflow and transition an unhandled CPU to STOP. - SCL conversion functions truncate or round floating-point fractions; ensure that fractional second requirements align with the cyclic execution frequency of the host Organization Block.
- In high-speed interlock routines, do not rely on WinCC script timers; all deterministic timing logic must execute strictly within the controller SCL/CFC environment.
- Always validate final software licensing and system documentation against the applicable Siemens catalog and authorized distributor quotation.
Engineer FAQ
Why did entering 5 on my faceplate make the timer run for only 5 milliseconds?
Because IEC TIME is measured internally in milliseconds. The value 5 was interpreted as 5 ms. In your SCL code, you must multiply the operator's input by 1000.0 before casting to TIME.
What happens if an operator enters a negative time value?
Without clamping logic, a negative REAL converts to a negative DINT. While IEC TIME supports negative values mathematically, standard IEC timer blocks (TON, TOF) treat negative presets as expired (0 ms) or fault out.
Can I use standard IEC timers (TON) in PCS 7 CFC charts?
Yes, but Siemens APL blocks prefer the TimerP block from the PCS 7 Basis Library, which operates seamlessly with cyclic sampling time (SAMPLE_T) and offers built-in pause, reset, and faceplate integration.
Technical References
- SIMATIC S7-SCL for S7-300 and S7-400 Programming System Manual
- Siemens Industry Online Support FAQ: Converting Real Seconds to TIME in SCL
- SIMATIC Process Control System PCS 7 Advanced Process Library System Manual
Related Articles
- How the Intlock Input Governs PIDConL Manipulated Variables and Feature Bit Behaviors in PCS 7 APL
- How to Implement Bumpless Override Control with Dual PIDConL Loops and Opposing Gain Directions in PCS 7 APL
- Troubleshooting CFC Module Driver Generation Failures in PCS 7
Related Tags
- SCL
- IEC TIME
- WinCC Faceplate
- Time Conversion
- PCS 7 Engineering