How to Handle Operator Time Values Between WinCC Faceplates and SCL Blocks in SIMATIC PCS 7

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

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#-24d20h31m23s648ms to T#+24d20h31m23s647ms (Integer values -2,147,483,648 to +2,147,483,647 ms).
  • An IEC TIME literal of T#10s is stored in CPU memory as hexadecimal DW#16#00002710 (decimal 10,000 ms).
  • 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 DigTimDel for digital alarm delay, motor run monitoring times, or flush durations) as floating-point REAL numbers in seconds (e.g., 10.5 seconds).
  • The Bug Mechanism: If the SCL block declares DigTimDel : REAL; and attempts a naive conversion TimeVal := DINT_TO_TIME(REAL_TO_DINT(DigTimDel));, entering 10 on the faceplate passes the integer 10 directly 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:

  1. 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;
  2. 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;
  3. Using Cycle Time (SAMPLE_T) Integration:
    * For continuous PID or ramp calculations, rather than using TON timer blocks, accumulate the cyclic execution period SAMPLE_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, and MotL) do not expose the IEC TIME data type to WinCC. All operator and engineering delay parameters are defined strictly as REAL representing 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.

Data TypeMemory SizeResolution / UnitInternal RepresentationStandard SCL Conversion FunctionTIME32-bit (DWORD)1 msSigned DINT (Milliseconds)DINT_TO_TIME(val) / TIME_TO_DINT(val)REAL32-bit (IEEE Float)Fractional secondsIEEE 754 Floating PointREAL_TO_DINT(val) / DINT_TO_REAL(val)S5TIME16-bit (WORD)10 ms to 10 sBCD time base + mantissaS5TI_TO_TIME(val) / TIME_TO_S5TI(val)DATE_AND_TIME (DT)64-bit (8 Bytes)1 ms / Calendar dateBCD encoded Year to msDT_TO_TOD(val) / DT_TO_DATE(val)TIME_OF_DAY (TOD)32-bit (DWORD)1 msUnsigned DINT since midnightTOD_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_DINT conversions without bounds checking; floating-point values exceeding 2,147,483.0 seconds 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

Related Articles

Related Tags

  • SCL
  • IEC TIME
  • WinCC Faceplate
  • Time Conversion
  • PCS 7 Engineering
6 respuestas