Calculating 24-Hour Moving and Daily Averages for Analog Variables in SIMATIC PCS 7
In SIMATIC PCS 7, calculating 24-hour averages across analog process variables (such as emissions, mass flow, or temperatures) can be implemented at the automation layer (AS controller) or the supervisory layer (WinCC OS). For regulatory daily compliance reports where values must be archived and reported, the recommended supervisory method utilizes WinCC Tag Logging Compressed Archives, configuring a 24-hour compression period that automatically computes mathematical mean, minimum, maximum, and sum from 1-minute raw samples. If the 24-hour rolling average is required in real-time control logic inside the S7-400 CPU, engineers must implement the Advanced Process Library Totalizer block (TotalL) or author an S7-SCL cyclic ring-buffer block executed in a slow cyclic interrupt OB.
Table of Contents
- Architectural Approaches: Supervisory Archiving vs Controller Logic
- Method 1: WinCC Tag Logging Compressed Archives (24-Hour Mean)
- Method 2: Controller-Level SCL Ring-Buffer Rolling Average (AS Layer)
- Method 3: Group Averaging Across Multiple Process Variables
- Comparative Implementation Matrix for 24-Hour Averaging
- Step-by-Step Procedure: Configuring a 24-Hour Compressed Archive
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Architectural Approaches: Supervisory Archiving vs Controller Logic
Calculating time-based averages over extended operational durations (such as 24-hour daily averages) is a standard requirement for environmental reporting (CEMS), energy consumption tracking, and material balancing.
Engineers must choose between two distinct computational architectures:
1. Supervisory Layer (WinCC Tag Logging):
- Best suited for historical compliance, shift reports, and trend display.
- Computes statistical averages directly within the WinCC SQL database using Compressed Archives.
- Zero consumption of controller CPU work memory or execution cycle time.
2. Controller Layer (S7-400 / CPU 410 CFC):
- Mandatory if the 24-hour average is actively fed back into closed-loop control logic, interlocks, or dynamic alarm trip limits.
- Requires accumulating samples over 86,400 seconds without causing arithmetic floating-point precision loss or buffer overflow.
Method 1: WinCC Tag Logging Compressed Archives (24-Hour Mean)
WinCC Tag Logging incorporates a high-speed compression engine:
- Raw process variables are logged cyclically into Process Value Archives (e.g., sampled every 10 seconds or 1 minute).
- A Compressed Archive is defined with a calculation cycle of 1 Day (24 hours).
- The compression algorithm evaluates all raw samples committed within the 24-hour window, computing:
- Mean Value (Mathematical Average)
- Min Value and Max Value
- Sum (Totalized Volume)
- The resulting single compressed value is committed to the long-term SQL database and can be queried by WinCC OnlineTrendControl, Information Server, or custom reporting scripts.
Method 2: Controller-Level SCL Ring-Buffer Rolling Average (AS Layer)
If a true rolling (moving) 24-hour average is required in the AS controller:
- Storing 86,400 one-second samples in PLC memory is impossible due to DB size constraints ($86400 \times 4\text{ bytes} \approx 345\text{ KB}$).
- Instead, sample the process variable at a slower rate: e.g., once every 10 minutes ($144$ samples per 24 hours) or once every 15 minutes ($96$ samples).
- An S7-SCL function block maintains an internal array (ring buffer):
```pascal
// Ring buffer sample acquisition
RingBuffer[Pointer] := InputValue;
Pointer := (Pointer MOD MaxSamples) + 1;
// Compute average
RunningSum := 0.0;
FOR i := 1 TO MaxSamples DO
RunningSum := RunningSum + RingBuffer[i];
END_FOR;
Average24h := RunningSum / REAL(MaxSamples);
```
- This block is scheduled in OB32 (1.0 s) or driven by a 10-minute timer pulse, maintaining minimal CPU load.
Method 3: Group Averaging Across Multiple Process Variables
When calculating the combined average across 5 distinct analog tags (e.g., 5 furnace temperature sensors):
1. Spatial Group Average:
- In CFC, sum the 5 analog inputs using standard addition blocks (ADD_R or Sum from CFC Library).
- Divide the sum by 5.0 using DIV_R.
2. Time-Based 24h Average:
- Route the single spatial average output into the 24-hour Tag Logging compressed archive or the SCL ring buffer.
- This hierarchical approach minimizes database storage and ensures mathematical consistency.
Comparative Implementation Matrix for 24-Hour Averaging
The table below compares 24-hour averaging techniques in SIMATIC PCS 7:
Step-by-Step Procedure: Configuring a 24-Hour Compressed Archive
Follow this procedure in WinCC Explorer:
Step 1: Configure Raw Process Tag Logging
- Open Tag Logging in WinCC Explorer.
- Ensure the analog tag is assigned to a Process Value Archive (e.g.,
Archive_ProcessValues). - Set the acquisition cycle to 1 Minute with storage type Cyclic continuous.
Step 2: Create the 24-Hour Compressed Archive
- In Tag Logging navigation tree, right-click Compressed Archives and select New Compressed Archive.
- Name the archive
Archive_24h_Average. - In properties, set Time Period:
1 Day(24 Hours). - Set Start Time:
00:00:00(daily midnight rollover).
Step 3: Add Compressed Tags
- Right-click
Archive_24h_Averageand select New Tag. - Select the raw process tag from
Archive_ProcessValues. - Set Calculation Type: Average.
- Save Tag Logging and run OS compilation.
Verification
To confirm that 24-hour averaging operates correctly:
1. Online Table Verification: Open WinCC OnlineTableControl in runtime; bind it to Archive_24h_Average; verify that daily rows appear with valid timestamps and calculated mean values.
2. Mathematical Accuracy Audit: Manually export 24 hours of 1-minute raw samples to Excel; calculate the average; verify that the WinCC compressed tag matches within 0.01%.
3. Controller Ring-Buffer Test: If using SCL in CFC, monitor the block in test mode; verify that the ring-buffer pointer increments cyclically and output tracks the moving average.
Limitations and Operational Precautions
Engineering teams must observe the following precautions:
- Arithmetic accumulation of floating-point numbers over large sample counts can induce IEEE 754 precision truncation; always maintain running sums using Double Precision (DINT) or reset accumulation windows periodically.
- WinCC compressed archives calculate data at the end of the configured period; daily averages will commit to SQL at midnight.
- Always validate final license quantities and MLFBs against the applicable Siemens catalog and authorized distributor quotation when ordering WinCC archive expansion licenses.
Engineer FAQ
Does WinCC Tag Logging require an extra license for Compressed Archives?
No. Compressed Archives are a standard built-in feature of WinCC Tag Logging and do not consume additional archive tag licenses beyond the standard archive tag count.
Can I calculate a 24-hour average of Boolean run signals?
Yes. Converting the Boolean to an integer (0 or 1) and logging it allows the compressed archive to calculate the percentage run time over 24 hours.
How does Tag Logging handle missing data during an OS restart?
If the OS Server was stopped for 2 hours, the compression algorithm computes the average based strictly on the available valid samples within that 24-hour window, flagging degraded quality code.
Technical References
- WinCC Process Value Archiving (Tag Logging) Manual (A5E37536420)
- SIMATIC PCS 7 Advanced Process Library (APL) Function Manual (A5E36986980)
- Siemens Support: Mathematical Algorithms in WinCC Tag Logging (Entry ID: 109740190)
Related Articles
- Archiving STRING Data Types in SIMATIC PCS 7 - S7_archive Limitations and Alternative Storage Solutions
- Converting Boolean to Integer in SIMATIC PCS 7 CFC - Standard Multiplexer vs SCL Implementation
- Customizing Alarm and Archive Report Templates in SIMATIC Information Server 2014 SP2
Related Tags
- Tag Logging
- Compressed Archives
- 24-Hour Average
- S7-SCL
- Analog Calculations