Overview: WinCC Tag Logging Acquisition vs. Archiving Cycles
Siemens SIMATIC WinCC V7 Tag Logging decouples the acquisition of process values from the archiving of those values to the SQL/MMF back-end. A typical configuration acquires a tag every 1 s and writes a single archive row every 60 s. Between those two boundaries, the Tag Logging runtime applies a processing function that compresses N samples into a single archive value.
The default processing operators are documented in the WinCC Information System under "Processing of process values": Current, Total, Maximum, Minimum, Average. When the required archive value cannot be expressed by any of these five operators – for example, 2×sum or an energy integration (Σ kW) / 3600 – engineers must use the Action processing type and call a user-defined project function written in C. This article details the procedure, the dimensionally correct energy formula, and the alternatives (Linear Scaling, Online Trend Control user scaling, Global Script triggers) that often come up when the Action route seems too invasive for installations in the 10,000-tag range.
Reference: Tag Logging Built-in Processing Functions
| Processing Function | Behavior in the Archive Period | Typical Use Case |
|---|---|---|
| Current | Last acquired raw value in the period | Status / state bits, instantaneous readings |
| Total | Algebraic sum of every acquired value in the period | Counters, batch totals, energy precursors |
| Maximum | Highest acquired value in the period | Peak pressure, peak current, surge detection |
| Minimum | Lowest acquired value in the period | Valley voltage, minimum tank level |
| Average | Arithmetic mean of all acquired values | Temperature, flow rate, average load |
| Action | Returns the result of a user-defined C function | Custom math, 2×sum, energy (kWh), scaled totals |
Reference: SIMATIC WinCC V7.5 Tag Logging Manual – Processing of Process Values (Siemens Support, entry ID 109763081).
Action Functions: How WinCC Passes Archive Data to C
When the processing type is set to Action, WinCC calls a configured C function once per archive cycle. The function signature is fixed by the Tag Logging interface:
double Action_Function(double doLmtValue, double doValue, int dwCount, int Archiving);
| Parameter | Direction | Meaning |
|---|---|---|
| doLmtValue | IN | Limit value configured for the tag at the time of the call. |
| doValue | IN | The most recently acquired raw value passed into the action. |
| dwCount | IN | Number of samples accumulated within the archive period. |
| Archiving | IN | 1 = call is triggered by the archive boundary; 0 = otherwise. |
| Return value | OUT | Value written into the archive row. |
Because doValue only delivers the most recent sample, a project function cannot directly see the entire history of samples that occurred during the 60 s window. There are two strategies to faithfully reproduce "2×sum":
- Static accumulator inside the function – the Action is called once per acquisition sample (Archiving == 0); when the archive boundary hits (Archiving == 1) the accumulator is multiplied by 2 and returned, then cleared.
- Read the archived "Total" of an internal accumulator tag – a parallel archive on an internal tag uses built-in Total processing; the Action reads that archive value and multiplies by 2.
Step-by-Step: Implementing a 2×Sum Archive Action
For projects of 10,000 tags the recommended pattern is to keep an internal accumulator tag so that the Action only runs once per archive cycle. Below is the full commissioning procedure.
-
Create the source tag in WinCC Explorer → Tag Management (example name
PWR_KW_001, data type Float, length 4 bytes, PLC connection on the appropriate channel). -
Create the accumulator tag as an internal tag (no PLC connection) named
PWR_KW_001_SUM, data type Float, start value 0.0. - Enable Tag Logging on the accumulator tag: acquisition 1 s, archive cycle 1 min, processing type Total. This archives the running 1-minute sum to the back-end.
- Create the Action project function in Global Script → Project Functions. The function reads the last-archived Total and returns it doubled:
double SumX2(double doLmtValue, double doValue, int dwCount, int Archiving)
{
double dSum;
/* Read the running 1-min Total written by Tag Logging
on the accumulator tag. */
dSum = GetTagFloat("PWR_KW_001_SUM");
/* Multiply by 2 and return as the archive value. */
return (dSum * 2.0);
}
-
Wire the Action into Tag Logging: in Tag Logging → select the source tag (or a parallel "output" tag) → Properties → Processing → set Processing Function to Action → enter
SumX2as the function name. - Compile the project: Global Script → Compile → Compile All. Without compilation the action is not registered with the Tag Logging runtime database.
- Activate WinCC Runtime and open Tag Logging Runtime to verify a new row every 60 s with value = 2 × sum.
- Validate against a hand calculation: if the source was 5 kW constant for one minute, the sum is 300 kW·s (5 kW × 60 s), so 2×sum = 600 kW·s. Confirm the archive matches.
GetTagFloat inside an Action reads the last archived value of the accumulator tag, which lags by one archive cycle. To read the current cycle, either accumulate inside the action with a static variable and configure the Action to be called on every value change, or call the C-API TlgGetArchivDataByTime() (function group "TagLogging") and pass the current timestamp. The latter is the official, library-supported method when sub-cycle lag is unacceptable.Energy Calculation: Converting Power to kWh
The original question eventually reveals the underlying engineering intent: integrate instantaneous power (kW) over time to obtain energy (kWh). The base equation is:
E_kWh = (1 / 3600) * Σ (P_kW_i × dt_i)
If the acquisition is uniform (1 s sample, 60 samples per archive cycle, dt = 1 s):
E_kWh(per_minute) = (1 / 3600) * Σ P_kW_i × 1 s = Σ P_kW_i / 3600
A project function that returns the kWh for one archive window – using a static accumulator so the Action is called on every acquired sample:
double PowerToKWh(double doLmtValue, double doValue, int dwCount, int Archiving)
{
static double dAccum_kWs = 0.0;
/* Called per acquisition sample when Archiving == 0,
and at the archive boundary when Archiving == 1. */
if (Archiving == 0)
{
dAccum_kWs += doValue; /* running sum [kW * s] */
return 0.0; /* do not write sub-cycle */
}
/* Archiving == 1 -> archive boundary reached */
double dKWh = dAccum_kWs / 3600.0; /* kJ / 3600 = kWh */
dAccum_kWs = 0.0; /* reset for next window */
return dKWh;
}
Verify dimensionally: doValue = 50 kW sampled every 1 s for 60 s gives Σ = 3000 kW·s = 3000 kJ. Dividing by 3600 yields 0.833 kWh, which is exactly 50 kW × (60 s / 3600 s/h) = 0.833 kWh. ✓
| Symbol | Unit | Description |
|---|---|---|
| P_kW | kW | Instantaneous electrical power from the PLC |
| dt | s | Acquisition period (1 s in this example) |
| Σ P·dt | kW·s (= kJ) | Energy per archive window in joules |
| E_kWh | kWh | Energy written to the archive |
| 3600 | s/h | Conversion factor (kJ → kWh) |
If the acquisition period is not 1 s, the divisor changes: for a 2 s acquisition with 30 samples per minute the divisor becomes 1800 (because dt = 2 s, so the factor is 3600/2 = 1800).
Triggering Calculations with a Global Script Instead of Action
An alternative – useful when the project function infrastructure is unavailable – is to fire a Global Script C-Action on every value change of the source tag and write the result into an internal output tag that is then archived.
/* Global Script C-Action
Trigger: "On change" of tag PWR_KW_001 */
{
double dSource = GetTagFloat("PWR_KW_001");
SetTagFloat("PWR_KW_001_X2", dSource * 2.0);
}
Then archive PWR_KW_001_X2 with processing type Current and archive cycle 1 min. The drawback is one additional internal tag per source tag – 10,000 source tags implies 10,000 derived tags. Possible but expensive in terms of licensing and runtime memory.
| Approach | Extra Tags Required | CPU Cost (10k tags) | Archive Stores Scaled Value? |
|---|---|---|---|
| Action function (static accumulator) | 0 | 10,000 calls/min (low) | Yes |
| Action + internal accumulator tag | 1 per source | Low | Yes |
| Global Script change-triggered | 1 per source | 10,000 calls/s (high) | Yes |
| Linear Scaling (display only) | 0 | None | No – raw value archived |
| Trend Control user scaling | 0 | None | No – raw value archived |
Linear Scaling in Tag Properties
If the only requirement is to display a value scaled by a constant in a trend or table, Linear Scaling under the tag's properties in WinCC Explorer is the cheapest option. Open the tag → Properties → check "Linear Scaling" → enter the scale factor (e.g. 2.0 for 2×) and offset (0.0). Scaling is applied at read time so the archive stores the original raw value.
| Parameter | Value (2× Example) | Effect |
|---|---|---|
| Linear Scaling – Enable | Yes | Activates runtime scaling on read |
| Scale Factor | 2.0 | Multiplies the raw value at read time |
| Scale Offset | 0.0 | Additive offset applied after scaling |
| Tag Logging archive value | Unchanged | Archive stores raw, scaled value only on display |
WinCC Online Trend Control: User Scaling on the Value Axis
The WinCC Online Trend Control (inserted via Graphics Designer) supports user scaling on each value axis independently. Configure the trend → Properties → Value axis → check "User Scaling" → set the lower and upper limit to the desired range. This is purely a display transformation and has zero impact on Tag Logging, the archive, or other consumers.
For the WinCC Online Table Control the user-scaling mechanism is not available. If the doubled value must appear in the table, the options are:
- Switch to Action-based archiving (preferred).
- Create a derived internal tag and archive that tag.
- Use a custom column in the table with a C/VB script calling
GetTagFloat()at row-paint time.
Performance Considerations with 10,000 Tags
For installations in the 10,000-tag range the runtime profile is dominated by three factors. The numbers below assume acquisition 1 s, archive 1 min, single-server WinCC V7.5 project.
| Subsystem | Load (10k tags, 1 s acq.) | Mitigation |
|---|---|---|
| Tag Logging acquisition callbacks | ~10,000/s | Raise cycle to 2–5 s on non-critical tags |
| SQL/MMF archive writes (1 min) | ~167 rows/s steady | Move database to separate SSD; enable swap-out |
| Action function calls (archive cycle) | 10,000/min | Use archive-cycle Action, not per-sample Action |
| Global Script change-triggered | 10,000/s if any value change | Avoid; prefer Action function |
| Online Trend/Control redraws | Per user, varies | Limit number of visible curves; archive swapping |
The Action function approach scales better than the Global Script + internal tag approach because it executes only at the archive boundary (1/min) instead of on every PLC value change (1/s). For 10,000 tags the projected CPU usage is roughly 10–15 % of one core on a WinCC V7.5 server equipped with an Intel Xeon E-class CPU and 16 GB RAM. Verify on the target hardware with the Performance Viewer (CCPerfMon.exe) and the SQL Profiler attached to the archive database.
Verification Checklist
- Open WinCC Tag Logging Runtime → select the tag → confirm a new archive row appears every 60 s.
- Right-click the latest row → Display properties → verify the value matches 2 × Σ(samples) or the calculated kWh.
- Open the Online Table Control → bind it to the archive tag → confirm the same value renders without user scaling.
- Open the Online Trend Control → overlay the archive value against the raw source for one hour and confirm the expected shape (e.g. for 50 kW constant: archive value = 0.833 kWh each minute).
- Export 24 h of data via Tag Logging Export → cross-check the cumulative energy against an external reference meter.
- Use Performance Viewer to confirm archive write rate ≈ 167 rows/s and CPU load stays below 60 %.
- Restart the WinCC Runtime and confirm that the static accumulator inside the Action re-initialises correctly (no spurious spike in the first archive row).
Troubleshooting Matrix
| Symptom | Likely Cause | Resolution |
|---|---|---|
| Archive value is always 0 | Project function not compiled | Global Script → Compile All → restart WinCC Runtime |
| Archive value equals the raw value, not 2× | Tag processing type still set to Current | Change Processing Function to Action; assign function name |
| Function call returns NaN or 0 unexpectedly | Source tag disconnected or quality bad | Check PLC connection in Channel Diagnostics; verify tag status |
| Action only runs once at startup | Action trigger mis-configured | Set Action trigger to "On archive" or "On every value change" |
| Online Trend shows correct value, Online Table does not | Table bound to source tag instead of archive tag | Bind the Table to the archive tag, not the source |
| SQL back-end grows 50 GB/day | Action mis-configured to write per sample | Force Action to execute only when Archiving == 1 |
| GetTagFloat returns stale value (lags one cycle) | Reading last archive instead of current cycle | Use static accumulator inside Action; or call TlgGetArchivDataByTime() |
| Trend Control user scaling has no effect | Wrong axis selected | Select the value column, then configure Value axis → User Scaling |
| Energy value too high or low by factor | Wrong divisor (forgetting dt ≠ 1 s) | Verify acquisition period; divisor = 3600 / dt_seconds |
| WinCC Runtime cannot find function SumX2 | Function declared but not in Project Functions | Move function from Local Functions to Project Functions; recompile |
Related Configuration: Tag Logging Back-end and Retention
For 10,000 tags with minute-granular archives the back-end tuning is as important as the Action function code. Recommendations that consistently apply:
- Database location: move the WinCC archive database (SQL Server or Microsoft Access) to a dedicated SSD separate from the OS drive.
- Swap-out time: configure Tag Logging → Properties → Archive → Swap-out time to 24 h for fast queries plus a daily long-term archive.
- Tag logging runtime service: confirm the "WinCC TagLoggingRuntime" service is set to "Automatic (Delayed Start)" so it begins after the SQL Server service is fully online.
- Size the temp folder: the swap-out files (.TRC) grow quickly; allocate at least 20 % free disk on the swap volume.
Reference: Siemens Industry Online Support – SIMATIC WinCC documentation portal.
Key Takeaways
- Built-in Total processing gives you the sum; the × 2 multiplier requires either an Action function, a Global Script writing a derived internal tag, or Linear Scaling for display-only.
- For energy (kWh), the formula
Σ P_kW · dt / 3600is dimensionally correct. Static accumulators inside the Action avoid the one-cycle lag of GetTagFloat on the accumulator tag. - The Action function approach scales to 10,000 tags as long as it executes only at the archive boundary (Archiving == 1) rather than on every value change.
- Linear Scaling and Trend Control user scaling never affect the archive – they are display transformations only.
- Always verify with a hand calculation (e.g. 50 kW × 60 s = 0.833 kWh) before trusting the archived number.
FAQ
Can WinCC Tag Logging archive "2 × sum" without writing C code?
No. The built-in Total function returns the raw sum; the × 2 multiplier must be applied either by an Action function, a Global Script that writes a derived internal tag, or by Linear Scaling if only the display needs to change. There is no built-in constant-multiplier processing type.
How do I compute kWh from a power tag acquired every 1 s?
Configure the tag's Processing → Action, then write a project function that accumulates samples in a static variable and divides by 3600 when Archiving == 1. Verify with a hand calculation: 50 kW constant × 60 s = 3000 kW·s = 3000 kJ = 0.833 kWh per archive row.
Why does GetTagFloat inside the Action return the previous archive value?
Tag Logging writes the archive row first, then triggers the Action; reading the accumulator tag returns the row from the previous cycle. To access the current cycle, accumulate samples inside the Action with a static variable and call the Action on every value change, or use the C-API call TlgGetArchivDataByTime() to query the in-memory buffer.
Does Linear Scaling affect the archived value?
No. Linear Scaling is a read-time transformation only. The archive always stores the raw value from the PLC. To persist a scaled value, use Action processing or a derived internal tag that is archived with Current processing.
Will the Action approach scale to 10,000 tags?
Yes, provided the Action executes once per archive cycle (Archiving == 1) rather than once per acquisition sample. At 10,000 tags with a 1 min archive this is ~167 function calls per second, well within the capacity of a WinCC V7.5 single-server project on recommended hardware (Xeon E-class, 16 GB RAM, dedicated SSD for the archive database).