How to Implement a Retentive Pause-Resume Timer in SIMATIC PCS 7 APL Using TimerP and Custom SCL
In SIMATIC PCS 7 Advanced Process Library (APL) V8.0, standard timer blocks such as TON reset their accumulated elapsed time to zero immediately when the timing condition transitions to false. To implement a retentive timer that pauses and freezes its elapsed time when conditions go false, resumes when conditions return to true, and sets an output flag when elapsed time reaches a preset value, engineers can utilize the APL 'TimerP' block by dynamically manipulating its block enable input 'EN'. Alternatively, a fully encapsulated retentive timer block can be coded in Structured Control Language (SCL) by integrating cyclic sampling time ('SAMPLE_T') when active, holding the accumulated accumulator when paused, and clearing only upon an explicit reset pulse.
Table of Contents
- Standard Timer Behaviors vs Retentive Pause-Resume Requirements
- Implementing Retentive Timing Using APL TimerP and Block Enable (EN)
- Developing a Dedicated Retentive Timer Block in SCL
- Integrating Retentive Timing in Continuous Function Charts (CFC)
- Comparison of Retentive Timing Methods in SIMATIC PCS 7
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Standard Timer Behaviors vs Retentive Pause-Resume Requirements
In process automation applications such as CIP (Clean-in-Place) wash cycles, catalyst exposure tracking, and filter backwashing:
* The Process Requirement: A process timer must accumulate running time only while certain conditions are satisfied (e.g., wash pump running AND temperature above 75 deg C). If temperature dips below 75 deg C, the timer must pause and hold its elapsed time. When temperature recovers, timing must resume from the frozen value.
* The Standard IEC Limitation: Standard IEC timers (TON - SFB4) are non-retentive; setting input IN := FALSE immediately clears the internal elapsed time (ET := T#0ms) and drops output Q.
* The APL Solution: Engineers must either adapt standard APL timing blocks or create custom SCL logic to provide retentive pause/resume functionality.
Implementing Retentive Timing Using APL TimerP and Block Enable (EN)
The TimerP block (FB1810) from the PCS 7 Basis / APL Library can be adapted to achieve pause-resume timing without writing custom code:
- Operating Mode Selection:
* ParameterMode: Set to0(Pulse),1(Extended Pulse), or2(On-Delay) depending on target output behavior.
* Set parameterTito the target duration in seconds (e.g.,120.0s). - Utilizing Block Enable (
EN):
* By default in CFC, the block enable inputENis hidden and tied to CPU execution.
* In CFC, right-click theTimerPblock: selectObject Properties > I/Os.
* Locate parameterENand uncheck theInvisibleattribute.
* Interconnect the process running condition (e.g.,Pump_Run AND Temp_OK) directly toEN.
* Interconnect the trigger signal toIn. - Execution Behavior:
* WhenEN = 1,TimerPexecutes cyclically, advancing elapsed time.
* WhenEN = 0, the S7 CPU skips execution of the block instance completely; its internal static memory retains the exact millisecond count where it stopped.
* WhenENreturns to1, execution resumes seamlessly from the frozen value.
Developing a Dedicated Retentive Timer Block in SCL
While TimerP with EN works, manipulating EN prevents the block from reporting frozen status to WinCC faceplates. Writing a custom SCL block using cyclic sampling time (SAMPLE_T) delivers a cleaner, fully observable solution:
FUNCTION_BLOCK FB_RetentiveTimer
TITLE = 'APL Retentive Accumulation Timer'
VERSION : '1.0'
AUTHOR : 'Cielo'
FAMILY : 'APL_TIM'
VAR_INPUT
In_Cond : BOOL; // Timing condition (TRUE = Run, FALSE = Pause)
Reset : BOOL; // Explicit Reset (Clears accumulator)
PresetTime : REAL; // Target duration in seconds
SAMPLE_T : REAL; // Sampling cycle time in seconds (from PCS 7 OB)
END_VAR
VAR_OUTPUT
Q : BOOL; // Timer Expired output flag
ElapsedTime : REAL; // Accumulated elapsed time in seconds
Remaining : REAL; // Remaining time in seconds
END_VAR
BEGIN
// Explicit reset overrides all operations
IF Reset THEN
ElapsedTime := 0.0;
Q := FALSE;
ELSIF In_Cond AND NOT Q THEN
// Accumulate cyclic sampling period
ElapsedTime := ElapsedTime + SAMPLE_T;
IF ElapsedTime >= PresetTime THEN
ElapsedTime := PresetTime;
Q := TRUE;
END_IF;
END_IF;
// Calculate remaining time
Remaining := PresetTime - ElapsedTime;
IF Remaining < 0.0 THEN
Remaining := 0.0;
END_IF;
END_FUNCTION_BLOCK
Integrating Retentive Timing in Continuous Function Charts (CFC)
To deploy the custom SCL retentive timer block in PCS 7:
- Insert into Cyclic Organization Block:
* Place the block into a standard cyclic interrupt OB (typically OB35, 100 ms execution frequency).
* PCS 7 automatically connects parameterSAMPLE_Tto the task cycle time (0.1s) during CFC compilation. - Interconnecting Signals:
* Connect process preconditions toIn_Cond.
* Connect sequence abort, batch termination, or operator reset buttons toReset.
* ConnectPresetTimeto an operator setpoint from WinCC.
* Connect outputQto the downstream transition condition or step advance logic.
Comparison of Retentive Timing Methods in SIMATIC PCS 7
The table below compares different approaches for implementing retentive timers in SIMATIC PCS 7.
Verification
To confirm that the retentive timer operates as designed:
1. In the CFC editor, open the chart containing the retentive timer and switch to Test Mode.
2. Set PresetTime to 20.0 seconds and apply In_Cond = TRUE.
3. Observe ElapsedTime counting up: when it reaches 8.0 seconds, set In_Cond = FALSE.
4. Verify that ElapsedTime freezes precisely at 8.0 seconds and output Q remains FALSE.
5. Wait 30 seconds: verify that ElapsedTime does not reset or drift.
6. Set In_Cond = TRUE: confirm timing resumes from 8.0 seconds and reaches 20.0 seconds, immediately setting Q = TRUE.
7. Pulse input Reset = TRUE: confirm that ElapsedTime clears to 0.0 and Q transitions to FALSE.
Limitations and Operational Precautions
- When using
TimerPwithENmanipulation, remember that the block's outputs will not update whileEN = 0; any downstream logic querying auxiliary status bits will see frozen states. - Ensure that
SAMPLE_Tis never left disconnected or set to0.0; without cycle time integration, accumulator algorithms will fail to advance. - Retentive timers maintain their accumulated elapsed time across CPU warm restarts if variables are declared in retentive instance data blocks; ensure restart handling explicitly resets or preserves timers as dictated by process safety rules.
- Always validate final software licensing and system documentation against the applicable Siemens catalog and authorized distributor quotation.
Engineer FAQ
Why does standard IEC timer TON reset when input goes false?
By IEC 61131-3 definition, TON is a non-retentive on-delay timer. De-asserting the enable input signals that the timing condition is no longer valid, requiring a complete timer restart upon the next true transition.
Can I view the custom SCL timer values in WinCC?
Yes. By declaring ElapsedTime and Remaining with the attribute { S7_m_c := 'true'; S7_unit := 's' }, the AS-OS compiler will automatically generate WinCC tags for faceplate display.
What happens if PresetTime is modified while the timer is paused?
In the SCL implementation, modifying PresetTime dynamically recalculates Remaining. If the new PresetTime is less than or equal to current ElapsedTime, output Q will trip immediately upon the next execution cycle.
Technical References
- SIMATIC Process Control System PCS 7 Advanced Process Library System Manual
- Siemens Industry Online Support FAQ: Implementing Retentive Timers in PCS 7
- SIMATIC S7-SCL for S7-300 and S7-400 Programming Manual
Related Articles
- How to Handle Operator Time Values Between WinCC Faceplates and SCL Blocks in SIMATIC PCS 7
- How the Intlock Input Governs PIDConL Manipulated Variables and Feature Bit Behaviors in PCS 7 APL
- Troubleshooting CFC Module Driver Generation Failures in PCS 7
Related Tags
- Retentive Timer
- TimerP
- SCL
- APL V8.0
- SAMPLE_T