1. Overview: The Track-and-Hold Problem in PCS 7 CFC
In SIMATIC PCS 7 V7.0 and the later releases through V9.1, the Continuous Function Chart (CFC) editor is the standard tool for programming the automation station (AS). Unlike ladder logic (LAD), function block diagram (FBD), or SCL, CFC is a free-form placement editor: function blocks, I/O blocks, and operator blocks are positioned on a chart sheet and connected by signal lines, while the runtime execution order is defined by numbered "tasks" (runtime groups) with configurable cycle time and phase offset. The CFC language is therefore extremely well suited to track-and-hold (T/H) functions, but the standard library does not ship a single dedicated HOLD_R or SAMPLE_HOLD_R block. Three engineering patterns cover the vast majority of real-world use cases without writing a custom function block:
- EN input freezing of a downstream block that consumes the value.
- SEL_R with output fed back to an input for an explicit sample-and-hold.
- Runtime group scheduling so the block is only re-evaluated every N seconds.
These techniques are valid for any REAL signal in a CFC chart: process measurements, controller outputs, calculated values, or operator-entered setpoints. They are also valid for other elementary types (BOOL, INT, DINT) by substituting the appropriate select block (SEL_BO, SEL_I, SEL_DI).
2. Prerequisites
Before implementing a track-and-hold function in CFC, verify the following:
- Engineering environment: SIMATIC PCS 7 V7.0 or later with the CFC option installed. CFC V7.0+ is included with every PCS 7 ES installation. Earlier PCS 7 V6.x versions use the same CFC engine but the runtime editor is slightly different.
- AS hardware: AS 400 series CPU (e.g., CPU 414-3, CPU 416-3, CPU 417-4 or H-CPU 417-4H) with sufficient free work memory. Each REAL feedback path consumes one block I/O slot.
-
Library access: The
SEL_Rblock is located in the Standard Library under Selection. In PCS 7 V7.0 SP1 and later, the same block is also exposed through the PCS 7 APL (Advanced Process Library). - CFC license: A valid CFC license is required on the Engineering Station (ES). The license is enforced at compile / download time, not at edit time.
- Runtime groups: At least one user-defined runtime group with the desired cycle time (OB35 by default, 1000 ms) is available to host the T/H logic.
- Online access: An established online connection to the AS for the verification step (recommended for trace recording).
For the elementary-block definitions used in this document, refer to the official Siemens manual CFC Elementary Blocks for S7 (PDF, Siemens Industry Online Support).
3. The Three Methods Compared
| Method | Block(s) required | Hardware cycles used | Output noise while holding | Holds over OB restart | Best use case |
|---|---|---|---|---|---|
| 1. EN-input freeze | 1 downstream block | 1 per scan of downstream block | None - output never re-evaluated while EN = FALSE | Yes - value frozen in block output image | Drive setpoint or controller SP freeze; PID output clamp |
| 2. SEL_R feedback T/H | 1 SEL_R + 1 AND/OR if latched | 2 per OB tick (SEL_R + feedback read) | None - IN0 carries the last OUT | Yes - feedback is latched in CFC image | Latching peak temperature, freezing a flow value at batch start |
| 3. Runtime group cycle | Any block placed in slow OB | 1 per N seconds (e.g. OB38 = 100 ms, OB35 = 1 s) | No sample - block simply not executed | Yes - holds the prior calculated value | Slow integration (averaging, totalization, drift correction) |
4. Method 1 - Freezing a Value with the EN Input
Every CFC block carries an implicit EN (enable) binary input and an ENO (enable output). When EN = FALSE, the block is not processed during the OB tick; its output pins retain the last computed value. This is the simplest track-and-hold pattern and requires no additional block at all.
4.1 Wiring procedure
- Place the consuming block (e.g., a CTRL_PID, OP_A_LIM, or any APL block) on the CFC sheet.
- Open its input list (View → Inputs/Outputs).
- Wire a BOOL tag (or a constant
TRUE) to theENinput. - Connect the REAL process value to the block's primary input (e.g.,
PVfor CTRL_PID).
4.2 Behaviour
-
EN = TRUE- the block updates each OB cycle with the live process value. -
EN = FALSE- the block is skipped;PVretains the last value it had when EN was last TRUE. The value is preserved across the entire OB scan, including in the output image sent to the OS.
Q or output flags (such as QL alarm flags on CTRL_PID) are not cleared. They keep their last computed state. This is normally desirable but must be understood when an alarm should follow the held value rather than the live PV.5. Method 2 - SEL_R as a Track-and-Hold
The standard SEL_R block implements a binary selection between two REAL inputs. The block is the canonical S7 CFC element for building a digital sample-and-hold. Its I/O definition is:
| Pin | Direction | Type | Description |
|---|---|---|---|
| K | Input | BOOL | Selector. K = FALSE selects IN0; K = TRUE selects IN1. |
| IN0 | Input | REAL | First candidate value. |
| IN1 | Input | REAL | Second candidate value. |
| OUT | Output | REAL | Selected value. |
5.1 Track-and-hold wiring (HOLD-when-K = TRUE)
- Place a
SEL_Rblock in the chart. - Wire the live process value (e.g., a temperature from an AI block) to IN1.
- Wire the output OUT back to IN0. This creates the holding feedback path.
- Wire a BOOL
HOLD_CMDtag to the K input. - Wire OUT to the downstream consumer (HMI, controller, batch record, etc.).
5.2 Resulting truth table
| HOLD_CMD (K) | OUT equation (this cycle) | Effective state |
|---|---|---|
| FALSE (0) | OUT = IN1 = live process value | TRACK |
| TRUE (1) | OUT = IN0 = OUT (last cycle) | HOLD |
When K transitions to TRUE, the block outputs its previous value (because IN0 = OUT of the previous cycle), and on every subsequent cycle IN0 still equals OUT, so the output remains latched. When K is released (FALSE), the output follows IN1 again with a one-cycle latency inherent to the feedback path.
NOT block if the signal is sourced from a normally-open contact. In a fail-safe chart (F-CFC), fail-to-hold is typically preferred because a fail-to-track may cause a process upset.5.3 Automatic hold for N seconds with a TP timer
To release the hold automatically after a fixed duration, combine the SEL_R with an IEC pulse timer from the Standard Library:
- Place a
TP(pulse, IEC 61131-3) block. - Wire the hold trigger (rising edge BOOL) to TP
IN. - Set TP
PTto the desired hold time, e.g.T#5sfor 5 seconds. - Wire TP
Q(the active pulse output) to the SEL_RKinput.
Result: when the trigger pulses, the SEL_R holds its value for 5 seconds regardless of further trigger events, then automatically reverts to TRACK mode. This is the standard PCS 7 pattern for "latch on alarm, release after timeout".
6. Method 3 - Runtime Group Cycle Scheduling
Every CFC chart has a "Run sequence" that lists the runtime groups installed on the AS. Each runtime group is associated with one of the S7-400 cyclic interrupt OBs. The PCS 7 V7.0 default mapping is:
| Cyclic interrupt OB | Default cycle time | Typical use in PCS 7 |
|---|---|---|
| OB30 | 5 s (configurable) | Slow integration, totalizer, average calculation |
| OB35 | 1 s (configurable) | Master runtime group - closed-loop control, alarms |
| OB36 | 500 ms | Fast loops, secondary control |
| OB37 | 200 ms | High-speed auxiliary logic |
| OB38 | 100 ms | Fast interlock, position controller |
The cycle time of OB30 to OB38 is configured in HW Config → CPU properties → Cyclic Interrupts. PCS 7 will not start the AS if the configured cycle time is shorter than the worst-case OB execution time (CPU goes into OB85 "Organization block error" if the OB is missed).
6.1 Configuring a new runtime group
- Open the CFC chart.
- From the menu, select Options → Run sequence (or right-click the chart background and choose Run sequence).
- In the Run sequence dialog, click Insert to add a new runtime group.
- Assign a descriptive name, e.g.
TEMP_HOLD_GROUP. - Assign the OB (e.g., OB35 for 1 s).
- Set the reduction ratio (default 1) and the phase offset (default 0). The phase offset is the delay, in OB-tick units, applied at startup to spread CPU load.
- Click Install to download the runtime group to the AS. Without "Install" the group exists only in the ES project.
6.2 Why cycle scheduling works as a hold
If a block is placed in OB35 (1 s), its outputs are recomputed once per second. If a downstream block is placed in OB38 (100 ms), it samples the OB35 output ten times per second. Between two OB35 evaluations, the downstream block sees the same frozen REAL value ten times. This is the cheapest possible "hold" because no logic is required - the value simply cannot change more often than the producing OB allows.
7. Step-by-Step Implementation: Latch Peak Temperature on Alarm
Combining methods 1 and 2, the following procedure latches a temperature reading on a high-high alarm and releases it 10 seconds after the alarm clears. This is a field-proven PCS 7 pattern used in fired-heater and reactor interlock applications.
- Create a CFC chart named
TEMP_LATCHin the AS program. - From the PCS 7 APL, drop an
CTRL_PID(or aMONOblock) for the temperature signal as the source. - Drop a
SEL_Rblock (Standard Library → Selection). - Wire the temperature measurement to
IN1. - Wire
OUTback toIN0. - Drop a high-limit alarm block (e.g., APL
LIMITorMONOalarm) to detect the high-high condition. Wire the alarm output to a BOOLHH_FLAG. - Drop a
TP(pulse) block from the IEC Timers folder. SetPT = T#10s. - Wire the rising edge of
HH_FLAGto TPIN(use an edge-detectR_TRIGblock in front of TP for a clean edge). - Wire TP
QtoKof the SEL_R. - Wire SEL_R
OUTto the consumer (HMI faceplate tag, archive tag, or interlock). - Open Run sequence and place the chart in OB35 (1 s).
- Compile and download to the AS.
8. Verification and Commissioning
8.1 Offline checks (S7-PLCSIM)
- Start S7-PLCSIM and load the compiled S7 program.
- Force the process value at the AI block to a known constant (e.g., 25.0 degC).
- Observe the SEL_R output: it must follow IN1.
- Toggle the TP input (set HH_FLAG high, then low). The SEL_R output should hold 25.0 degC for 10 s and then resume tracking.
- Repeat with the process value changing during the hold - the output must remain pinned to 25.0 degC for 10 s.
8.2 Online checks (live AS)
- Open the chart online and use Control & Monitoring (CFC Online) to watch the SEL_R input/outputs in real time.
- Insert a trace in S7-SCOPE (PCS 7 V7.0+ ships with this) on
IN1,OUT, andK. Trigger on K rising edge. - Confirm hold duration is within ± one OB cycle of the configured PT.
- Verify that ENO of the consuming block goes FALSE when EN is forced FALSE.
9. Common Errors and Diagnostics
| Symptom | Likely root cause | Corrective action |
|---|---|---|
| Output oscillates between IN1 and IN0 | Feedback wired to wrong input (IN1 instead of IN0, or vice versa) | Swap IN0 and IN1, or move feedback to the non-tracking input |
| Output always equals IN0 | K stuck at TRUE; feedback prevents any change | Check the source of K; verify in CFC Online |
| Block does not run at all | Runtime group not installed on the AS | Open Run sequence, select the group, click Install, then download |
| EN=TRUE/FALSE has no effect | EN input has been hard-wired to a constant that is overwritten by HMI | Disconnect the constant and verify the HMI tag connection |
| Hold releases early | TP timer is being reset by another trigger; PT too short for OB jitter | Use non-retriggerable TP, increase PT by 2 OB cycles margin |
| OB85 (OB missed) on AS at startup | Cyclic interrupt OB cycle time shorter than worst-case OB execution | Increase OB cycle time in HW Config or distribute blocks across more groups |
| F-Compiler reports feedback error | F-CFC does not allow logic inside a feedback path | Use a separate safety T/H block from the F-library (F_SEL_R) or place the T/H outside the F-chart |
10. Block Diagram of the SEL_R Track-and-Hold
11. Performance and Sizing Notes
- Cycle time impact: a SEL_R feedback T/H adds two block executions per OB tick (one read, one write). On a CPU 416-3 with 1 s OB35, this is negligible (< 0.05 ms per block).
- Scan latency: a one-cycle latency exists between K transition and OUT change. For an alarm-latch function this is irrelevant; for a closed-loop interlock that must respond in < 50 ms, place the chart in OB38 (100 ms) or OB37 (200 ms).
- Memory: each block I/O consumes 4 bytes for BOOL and 4 bytes for REAL. A T/H chain of 100 tags costs approximately 800 bytes of work memory and 1.6 kB of load memory on the CPU.
- HMI: every latched value that is sent to WinCC must be configured in the tag management. Add the SEL_R output to the AS-OS connection in NetPro if not already in the default transfer list.
12. Frequently Asked Questions
What is the difference between EN and ENO in CFC?
EN is the binary enable input. When EN = FALSE, the block is skipped during the OB tick and its outputs retain their last value. ENO mirrors the EN state and is intended to cascade enables to downstream blocks, although in CFC it is often simply left unconnected.
Can I use a custom FB instead of the SEL_R pattern?
Yes. You can write a SCL function block that takes a TRACK input, a HOLD input, and a value input, and write the held output. The advantage of the SEL_R pattern is that it requires no compilation step, no FB call overhead, and no new library, so it remains visible to maintenance engineers in any PCS 7 version without importing a project-specific library.
Does the SEL_R track-and-hold work in a safety-related (F) CFC chart?
No, not directly. F-CFC charts have strict topology rules that prohibit feedback loops. Use the F-library equivalent F_SEL_R from the F-Application Blocks, or place the T/H outside the F-chart and route the safe-valued result back in through a safety input block.
How do I release the hold after exactly N seconds?
Use an IEC pulse timer (TP) from the Standard Library → Timers. Wire the rising edge of your hold command to TP IN, set PT to the desired duration (e.g., T#5s for 5 seconds), and connect TP Q to the SEL_R K input. The TP is non-retriggerable in CPU 4xx firmware V4.x, so additional triggers during the hold window are ignored.
What is the relationship between runtime group cycle and OB cycle?
Each runtime group is associated with one cyclic interrupt OB. The OB cycle time is the natural period of the group; PCS 7 will not invoke the group more often than the OB fires. To change the cycle time, edit the OB configuration in HW Config → CPU → Cyclic Interrupts. Common values are OB35 = 1 s, OB36 = 500 ms, OB37 = 200 ms, OB38 = 100 ms. The phase offset is a startup delay, also expressed in OB ticks, used to spread CPU load across the cycle.