Holding REAL Values in PCS 7 CFC: Track-and-Hold Methods

David Krause13 min read
HMI ProgrammingSiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

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:

  1. EN input freezing of a downstream block that consumes the value.
  2. SEL_R with output fed back to an input for an explicit sample-and-hold.
  3. 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).

Note: The S7 REAL type is IEEE-754 single-precision (32 bits). Range is approximately ±3.4028235E+38 with roughly 7 significant decimal digits. All selection and feedback operations below are bit-exact: the held value is identical to the last accepted input sample at the bit level.

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_R block 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

  1. Place the consuming block (e.g., a CTRL_PID, OP_A_LIM, or any APL block) on the CFC sheet.
  2. Open its input list (View → Inputs/Outputs).
  3. Wire a BOOL tag (or a constant TRUE) to the EN input.
  4. Connect the REAL process value to the block's primary input (e.g., PV for CTRL_PID).

4.2 Behaviour

  • EN = TRUE - the block updates each OB cycle with the live process value.
  • EN = FALSE - the block is skipped; PV retains 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.
Caution: When EN transitions from TRUE to FALSE, the block's 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)

  1. Place a SEL_R block in the chart.
  2. Wire the live process value (e.g., a temperature from an AI block) to IN1.
  3. Wire the output OUT back to IN0. This creates the holding feedback path.
  4. Wire a BOOL HOLD_CMD tag to the K input.
  5. 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.

Tip: Some teams prefer the inverse convention (HOLD when K = FALSE) to fail-safe to a held value. To implement that, swap IN0 and IN1, and invert K with a NOT_BOOL or use 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:

  1. Place a TP (pulse, IEC 61131-3) block.
  2. Wire the hold trigger (rising edge BOOL) to TP IN.
  3. Set TP PT to the desired hold time, e.g. T#5s for 5 seconds.
  4. Wire TP Q (the active pulse output) to the SEL_R K input.

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

  1. Open the CFC chart.
  2. From the menu, select Options → Run sequence (or right-click the chart background and choose Run sequence).
  3. In the Run sequence dialog, click Insert to add a new runtime group.
  4. Assign a descriptive name, e.g. TEMP_HOLD_GROUP.
  5. Assign the OB (e.g., OB35 for 1 s).
  6. 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.
  7. 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.

  1. Create a CFC chart named TEMP_LATCH in the AS program.
  2. From the PCS 7 APL, drop an CTRL_PID (or a MONO block) for the temperature signal as the source.
  3. Drop a SEL_R block (Standard Library → Selection).
  4. Wire the temperature measurement to IN1.
  5. Wire OUT back to IN0.
  6. Drop a high-limit alarm block (e.g., APL LIMIT or MONO alarm) to detect the high-high condition. Wire the alarm output to a BOOL HH_FLAG.
  7. Drop a TP (pulse) block from the IEC Timers folder. Set PT = T#10s.
  8. Wire the rising edge of HH_FLAG to TP IN (use an edge-detect R_TRIG block in front of TP for a clean edge).
  9. Wire TP Q to K of the SEL_R.
  10. Wire SEL_R OUT to the consumer (HMI faceplate tag, archive tag, or interlock).
  11. Open Run sequence and place the chart in OB35 (1 s).
  12. Compile and download to the AS.
Engineering note: The TP timer is retriggerable in some S7 firmware versions and non-retriggerable in others. In firmware V4.x of CPU 416/417 the TP is non-retriggerable; a re-trigger during the 10 s window is ignored, which is normally the desired behaviour for an interlock. Confirm against your CPU's CPU 31xC and CPU 31x, CPU 31xC and CPU 31x Reference Manual or equivalent if behaviour is critical.

8. Verification and Commissioning

8.1 Offline checks (S7-PLCSIM)

  1. Start S7-PLCSIM and load the compiled S7 program.
  2. Force the process value at the AI block to a known constant (e.g., 25.0 degC).
  3. Observe the SEL_R output: it must follow IN1.
  4. 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.
  5. 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)

  1. Open the chart online and use Control & Monitoring (CFC Online) to watch the SEL_R input/outputs in real time.
  2. Insert a trace in S7-SCOPE (PCS 7 V7.0+ ships with this) on IN1, OUT, and K. Trigger on K rising edge.
  3. Confirm hold duration is within ± one OB cycle of the configured PT.
  4. 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

LIVE VALUE (REAL) HOLD_CMD (BOOL) TP PT = T#10s SEL_RK IN0 IN1OUT HELD REALto OS / CTRL_PID Feedback: OUT → IN0 (latch)

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.

Back to blog