Calculating Process Value Standard Deviation in SIMATIC PCS 7 CFC for Tank Leak Detection

Calculating Process Value Standard Deviation in SIMATIC PCS 7 CFC for Tank Leak Detection

In SIMATIC PCS 7 (v7.0 through v8.2), calculating the standard deviation of an analog process measurement (such as hydraulic tank level for leak detection) can be implemented using standard function FC102 DEV from the STEP 7 'TI-S7 Converting Blocks' library. Because FC102 requires an array input, engineers wrap FC102 within a custom S7-SCL Function Block that samples the level transmitter at fixed time intervals into a circular FIFO buffer. Alternatively, a rolling variance algorithm (such as Welford's algorithm) can be programmed directly in SCL to compute real-time mean and standard deviation continuously without memory-heavy array buffering.

Table of Contents

Statistical Process Monitoring for Tank Leak Detection

Detecting subtle fluid leaks in hydraulic reservoirs or chemical storage tanks by monitoring raw level signals is difficult due to measurement noise, surface agitation, and pump cycling slosh.

Standard deviation ($\sigma$) measures the dispersion of process data around the arithmetic mean ($\mu$). In closed hydraulic systems during quiescent holding states:
* Under normal conditions: Fluid level exhibits a steady mean with low standard deviation (sensor white noise).
* When a leak occurs: The process exhibits a continuous downward drift, drastically inflating the calculated standard deviation over a rolling observation window.

Computing moving standard deviation in the AS controller allows the DCS to trigger proactive maintenance alarms before low-level emergency shutoffs trip.

Standard Library Block FC102 DEV (TI-S7 Converting Blocks)

STEP 7 includes a dedicated mathematical block for standard deviation:
* Location: Standard Library -> TI-S7 Converting Blocks -> Blocks -> FC102 DEV.
* Mathematical Function: Calculates the sample standard deviation over $N$ data points:
$$\sigma = \sqrt{\frac{1}{N-1} \sum_{i=1}^{N} (x_i - \bar{x})^2}$$
* Interface Limitations: FC102 accepts a pointer (ANY pointer) to an array of REAL numbers in a Data Block. Because standard CFC charts cannot wire dynamic time-series signals directly to an ANY pointer array input, an intermediate sampling block is required.

Implementing a FIFO Circular Sample Buffer in S7-SCL

To feed FC102, create an SCL Function Block running in a cyclic interrupt OB (e.g., OB32 1000ms):

FUNCTION_BLOCK FB1510
TITLE = 'Sample_Buffer_DEV'
{ S7_m_c := 'true'; S7_tasklist := 'OB32' }
VAR_INPUT
  In_Val    : REAL := 0.0;    // Process Level Input
  Sample_En : BOOL := TRUE;   // Sampling Enable
END_VAR

VAR_OUTPUT
  Std_Dev   { S7_m_c := 'true' } : REAL := 0.0; // Moving Std Dev
  Mean_Val  { S7_m_c := 'true' } : REAL := 0.0; // Mean Level
END_VAR

VAR
  Buffer : ARRAY[1..60] OF REAL; // 60-second rolling window
  Idx    : INT := 1;
  Count  : INT := 0;
END_VAR

BEGIN
  IF Sample_En THEN
    Buffer[Idx] := In_Val;
    Idx := Idx + 1;
    IF Idx > 60 THEN Idx := 1; END_IF;
    IF Count < 60 THEN Count := Count + 1; END_IF;

    // Call FC102 DEV or internal summation when buffer is primed
    IF Count >= 2 THEN
      // Compute standard deviation over Count samples
    END_IF;
  END_IF;
END_FUNCTION_BLOCK

Online Moving Standard Deviation Algorithm (Welford's Method)

The following table compares statistical calculation methods for SIMATIC PCS 7 CFC controllers:

Method / BlockAlgorithm MechanismWork Memory OverheadCPU Scan Time ImpactBest Suited ForStandard FC102 DEVTwo-pass batch sum of squaresLow (Requires external DB buffer)Moderate (Array pointer resolution)Periodic batch evaluations (e.g. shift reports).SCL Welford AlgorithmSingle-pass recurrence relationMinimal (Only 3 state variables: $M, S, k$)Extremely fast (< 50 $\mu$s per scan)Real-time continuous leak and noise monitoring.APL Smooth FilterFirst-order low-pass exponentialNegligibleNegligibleBaseline trend smoothing; does not compute variance.APL TotalL TotalizerTrapezoidal integrationLowLowMass-balance flow leak detection across pipes.

Verification

To confirm that the standard deviation calculation is functioning accurately:
1. In the CFC chart, connect a stable constant REAL value (e.g., 50.0) to the input of the standard deviation block; verify online that Std_Dev converges to 0.0.
2. Connect a simulated noisy signal (e.g., a square wave alternating between 49.0 and 51.0); verify that Std_Dev calculates the expected theoretical variance ($\sigma \approx 1.0$).
3. Connect the live tank level transmitter tag to the block in runtime; observe steady-state standard deviation.
4. Simulate a controlled drain rate; confirm that Std_Dev spikes distinctly above the quiescent threshold, triggering the leak detection alarm.

Limitations and Operational Precautions

Avoid sizing sample buffer arrays excessively large (e.g. > 1000 REAL elements) inside cyclic interrupt OBs like OB35 (100ms). Iterating over large arrays every 100ms increases CPU execution time and risks OB80 cycle time overruns. For long observation windows (e.g., 1 hour), execute the sampling block in a slow cyclic task (such as OB32 1000ms or OB31 5000ms).

Engineer FAQ

Where can I find FC102 DEV in SIMATIC Manager?

In SIMATIC Manager, select File -> Open -> Libraries tab -> 'TI-S7 Converting Blocks'. Under Blocks, copy FC102 (DEV) into your project's block folder.

Why does FC102 require at least two data points?

Sample standard deviation divides by $(N - 1)$ to provide an unbiased estimator (Bessel's correction). If $N < 2$, division by zero occurs, generating a mathematical fault (OB121).

Can standard deviation detect slow micro-leaks?

Standard deviation detects changes in process dynamics and slosh. For very slow micro-leaks, combine standard deviation with a regression slope estimator or mass-balance totalizer (TotalL).

Does FC102 handle invalid or bad quality signals?

No. Standard STEP 7 math blocks do not evaluate APL signal status (ST). Always verify that the input signal status equals 16#80 (Good) before feeding values into FC102.

Technical References

Related Articles

Related Tags

  • Standard Deviation
  • FC102 DEV
  • TI-S7 Library
  • Leak Detection
  • S7-SCL Sampling
6 respuestas