Calculating Values in WinCC 7.0 SP3: Divide PLC Tags Dynamically

David Krause12 min read
SiemensTutorial / How-toWinCC
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

Overview

In WinCC 7.0 SP3 the runtime database stores every external variable (process tag) as a raw value supplied by the AS (Automation Station). When the HMI application needs a derived value - for example a length in millimeters divided by a constant, or a count scaled to engineering units - the calculation can be performed at three distinct layers:

  1. Inside the I/O Field using Dynamic Dialog (presentation layer).
  2. Inside the Tag Management / Channel using Linear Scaling (acquisition layer).
  3. Inside a VBScript action or global script cycle (logic layer).

Each approach has different performance, scalability, and licensing implications. This reference documents all three methods for a recurring requirement: receive a numeric value from the PLC, divide it by a constant (e.g. 300), and expose the result either on the screen or as a new internal tag that other graphics or archives can consume.

Engineering rule of thumb: if the scaled value is needed by more than three graphics or by the Tag Logging / Alarm Logging archive, perform the scaling in the channel or in a script - not in a single I/O field. The Dynamic Dialog method is convenient but it is evaluated per picture object, not per tag.

Prerequisites

Before configuring any of the three methods, verify that the engineering station meets the following requirements:

Item Requirement Notes
WinCC version WinCC 7.0 SP3 (7.0.3.0) or later Dynamic Dialog syntax is identical from V6.2 through V7.4; later SPs add the long tag prefix.
Licensing WinCC RT 1 024 / 8 192 / 65 536 Power Tags as applicable Scaled internal tags still consume a PowerTag license.
PLC connection Configured channel (S7-300/400, S7-1200/1500, OPC, etc.) Channel must be in Connected state in WinCC Explorer.
Source tag External tag of type Signed 32-bit or Floating-point 32-bit IEEE 754 Match WinCC datatype to PLC datatype to avoid truncation.
Result tag Internal tag configured under Internal Tags Required for script-based and linear-scaling methods.
Authorisation Local administrator on the WinCC server Tag changes require write access to the project directory.

Open the project in the WinCC Explorer, then launch Graphics Designer for screen-level methods or stay in the Explorer for channel-level scaling.

Method 1 - Dynamic Dialog inside an I/O Field

This is the fastest method for a single graphic object. It does not require an internal tag; the I/O field evaluates the formula on each redraw cycle.

Step-by-step

  1. In the Graphics Designer, open the target picture (e.g. NewPdl.pdl).
  2. From the Standard object palette, drop an I/O Field onto the canvas.
  3. Right-click the I/O Field and select Properties > Output/Input.
  4. In the Output Value cell, click the small bulb icon and choose Dynamic Dialog.
  5. The Dynamic Dialog wizard opens. Configure the four fields as follows:
Field Entry Explanation
Expression / Formula ('Tag1' * 100) / 'Tag2' or 'Tag1' / 300 Use single quotes for tag names; arithmetic operators + - * / are supported. Parentheses force evaluation order.
Datatype Analog (signed 32-bit) or Float Select Float if the source tag or the divisor is non-integer.
Format 999.99 or as required by HMI standard Decimal places are fixed by the format string.
Trigger Default update (250 ms) or via tag change Use on change for low-frequency values to reduce CPU.
  1. Click Apply, then OK. The dialog closes and the I/O field now displays the computed value at runtime.
  2. Save the picture and activate the project (File > Activate in WinCC Explorer).

Syntax rules for Dynamic Dialog formulas

  • Tag names must be wrapped in single quotes: 'MyTag'. Long tag prefixes (WinCC 7.4+) use the form 'Siemens\::MyTag'.
  • Constants can be integer (300) or floating point (300.0). Mixing an integer source with an integer divisor returns an integer - use 300.0 to force floating-point division.
  • Supported operators: +, -, *, /, % (modulo), unary minus.
  • Bitwise operations (&, |, ^) are not available in Dynamic Dialog; use VBScript for these.
  • The dialog rejects formulas longer than 256 characters and silently truncates results that exceed the chosen datatype range.
Common pitfall: the user setting Datatype = Analog while the source tag is a 32-bit signed value is correct, but if the source is Float the formula returns only the integer part. Switch the datatype to Float (or Double for full IEEE-754 range) before declaring the result "not working".

Method 2 - Linear Scaling at the Tag / Channel layer

Linear Scaling is the cleanest approach when the same conversion must be applied globally (e.g. a 0-30 000 raw count from a flow meter is always shown as 0-100 % on every screen). The conversion happens once per acquisition cycle, the result is a normal WinCC tag, and every consumer (I/O fields, trends, alarms, scripts) reads the already-scaled value.

Configuration path

  1. In WinCC Explorer, right-click Tag Management and open the relevant channel (e.g. SIMATIC S7 PROTOCOL SUITE > TCP/IP).
  2. Select the connection (e.g. S7-1200/1500) and click New Tag.
  3. Name the tag (e.g. FlowRate_Eng), set datatype to Floating-point 32-bit IEEE 754, and click Select to choose the PLC address (e.g. DB10.DBD0).
  4. Click the Scaling button. Enable Linear scaling and enter:
Parameter Value (example) Meaning
PLC raw range start 0 Value sent by the AS at the lower end (PLC units).
PLC raw range end 30000 Value sent by the AS at the upper end.
HMI range start 0.0 Value shown in WinCC at the lower end.
HMI range end 100.0 Value shown in WinCC at the upper end.
  1. Apply. The formula applied internally is:

HMI = HMI_low + ( Raw - Raw_low ) * ( HMI_high - HMI_low ) / ( Raw_high - Raw_low )

This is a two-point linear interpolation. For a pure division by a constant (e.g. raw 0-300 000 → engineering 0-1 000), set PLC raw end = 300 000 and HMI end = 1 000. The WinCC tag FlowRate_Eng will then automatically contain the divided value, and any I/O field bound to it displays the engineering units directly.

Linear Scaling is evaluated every time the raw tag updates. If the raw tag is on a 1-second acquisition cycle, the scaled tag also updates at 1 second. Reduce the acquisition cycle on the raw tag (Properties > Acquisition cycle) if faster response is required.

Method 3 - VBScript calculation into an internal tag

When the formula is too complex for Dynamic Dialog - conditional scaling, multi-tag averaging, unit conversion tables - use a VBScript action. This method mirrors the pattern described in the Microsoft Visual Basic documentation for calculating numeric values: combine literals, constants, and variables in a numeric expression.

Creating the internal tag

  1. WinCC Explorer → Internal Tags → right-click → New Tag.
  2. Name: RawDiv300, Datatype: Floating-point 64-bit IEEE 754 (highest precision available).
  3. Click OK. The tag is now visible to every script and screen.

Creating the action

  1. WinCC Explorer → Global Scripts → right-click → New > Action.
  2. Choose trigger: Tag trigger on the source PLC tag RawValue (right-click the line, select Trigger, browse the tag).
  3. Insert the following code body:
' WinCC VBS action - divide incoming PLC tag by 300
Option Explicit

Dim rawVal
Dim scaledVal

' Read external tag (auto-quotes allowed in HMIRuntime.Tags path syntax)
rawVal = HMIRuntime.Tags("RawValue").Read

' Guard against divide-by-zero and invalid float
If IsNumeric(rawVal) Then
    scaledVal = CDbl(rawVal) / 300.0
    HMIRuntime.Tags("RawDiv300").Write scaledVal
Else
    ' keep last good value, optionally raise a bit in an alarm tag
    HMIRuntime.Trace "RawValue not numeric - division skipped" & vbCrLf
End If
  1. Compile (Ctrl+F7) and confirm Script successfully compiled.
  2. Save the action. Activation is automatic when the runtime starts.

Why use VBScript instead of Dynamic Dialog

  • Supports CDbl, CLng, Round, FormatNumber - higher precision than the I/O field engine.
  • Conditional logic (If...Then, Select Case) allows range-dependent scaling or fallback values.
  • One script scales one tag but can also fan out to multiple internal tags in a single execution.
  • Errors can be logged with HMIRuntime.Trace to the WinCC diagnosis file WinCC_Sys_xx.log.
Performance budget: one VBS action per PLC tag that updates every 250 ms creates roughly 4 script evaluations per second. WinCC 7.0 SP3 scales to a few hundred actions per second on a typical IPC, but beyond 1 000 active actions consider migrating the formula to the AS (PLC) or to a C-script (ANSI-C actions) for lower overhead.

Data Type Handling and Conversion Pitfalls

The most frequent cause of "I am not receiving the answer" in WinCC 7.0 SP3 is datatype mismatch between the PLC value and the HMI datatype declared on the tag.

PLC datatype (S7-300/400/1200/1500) Recommended WinCC datatype Notes
BOOL Binary tag Division not applicable; use logical AND/OR in script.
INT (16-bit) Signed 16-bit Range -32 768 .. 32 767.
DINT (32-bit) Signed 32-bit Range -2 147 483 648 .. 2 147 483 647.
REAL (32-bit IEEE 754) Floating-point 32-bit IEEE 754 ~7 significant digits; rounding may show.
LREAL (64-bit IEEE 754) Floating-point 64-bit IEEE 754 S7-1500 only; double precision recommended for engineering values.
WORD / DWORD Unsigned 16/32-bit Use only for bitwise operations; division still works but is unsigned.

If the PLC side is REAL and the WinCC tag is Signed 32-bit, the value is truncated to integer before the formula runs. Always match the WinCC datatype to the PLC datatype when first commissioning the tag.

Common Errors and Fixes

Symptom Likely cause Fix
I/O field shows ### Result larger than format width Increase the format string width (e.g. 9999.99) or reduce decimal places.
I/O field always shows 0 Tag is integer, divisor is integer, source value < divisor Switch tag datatype to Float or use divisor 300.0.
Value flickers between correct and zero Acquisition cycle slower than trigger Lower acquisition cycle to 250 ms or 100 ms on the raw tag.
VBS action shows "Object required" at runtime Tag name spelling error Verify tag name in WinCC Explorer; case-sensitive on long tag prefixes.
Linear scaling returns wrong end-points Swapped PLC and HMI ranges Re-check: PLC_low / PLC_high / HMI_low / HMI_high correspond to the formula's literals.
Result drifts after several hours Floating-point accumulation (rare for division alone) Use 64-bit float or perform division in the AS.

Verification Procedure

After applying any of the three methods, validate the result with the following checklist before handing the project to operations.

  1. Open WinCC Explorer and confirm the source tag shows a Quality Code of 0xC0 (Good) in the diagnostics view (right-click tag → Properties > Statistics).
  2. Force a known value from the PLC (e.g. write 30000 to the source DB word in STEP 7 / TIA Portal) and observe the I/O field or internal tag.
  3. Cross-check the displayed value with a handheld calculation: 30000 / 300 = 100. If the HMI shows 99.99, the value was truncated at the integer boundary - switch the tag to Float.
  4. Force a value that exercises the upper range (e.g. 300000) and confirm the result equals the configured upper engineering value.
  5. Force a negative value if the engineering range allows it; confirm two's-complement behaviour matches the PLC.
  6. Restart the WinCC runtime (Start > Programs > Siemens Automation > WinCC > WinCC Runtime Stop / Start) and verify the scaled tag retains its last value or starts at the configured start value.
  7. Inspect the WinCC diagnosis file <Project>\Diagnostics\WinCC_Sys_01.log for any VBScript error entries.

Method Selection Matrix

Criterion Dynamic Dialog Linear Scaling VBScript Action
Number of consumers 1 (the I/O field itself) Unlimited (one tag) Unlimited (one internal tag)
Formula complexity Simple arithmetic only Two-point linear only Arbitrary (loops, conditionals)
Performance impact Per object redraw Per acquisition cycle Per trigger
Visibility in Tag Logging No (result is virtual) Yes (archive the scaled tag) Yes (archive the internal tag)
Licensing None extra 1 PowerTag per scaled tag 1 PowerTag per internal tag
Engineering effort Lowest Low Medium (script syntax, error handling)
Recommended for One-off calculation on a single screen Engineering-unit conversion applied project-wide Conditional / multi-tag maths

Performance and Commissioning Tips

  • Push the maths down to the PLC. A S7-1500 CPU executes a single /R instruction in < 1 µs and the result is available to WinCC as a normal tag - no licensing, no script overhead, no maintenance burden. Reserve HMI-side calculation for values that genuinely depend on HMI state (e.g. operator-selected units).
  • Avoid cyclic float division in VBS. If a value must be divided every cycle, do it once on the AS and transmit the pre-scaled value.
  • Use bit-triggered actions instead of time-triggered ones when the source tag rarely changes - saves CPU.
  • Document the formula in the tag comment. WinCC Explorer allows a free-text comment per tag. Recording "RawValue / 300 = engineering mm" prevents the next engineer from re-deriving the scaling factor.
  • Centralise scripts in project functions. If ten tags need the same divide-by-300, create one project function fncScaleBy300(raw) and call it from each action - simplifies maintenance and version control.

Safety and Archiving Considerations

Scaled values that are archived in Tag Logging must be added to an archive tag manually; the archive does not inherit the scaling from the source tag. Configure the archive cycle independently - typically 1 s for trending and 100 ms for fast process values. For redundant WinCC servers, ensure the scaled internal tag is configured identically on the standby server and that VBS actions are exported/imported via the Project Duplication tool.

Alarms that trigger on the scaled value use the same bit or limit logic as on the raw value; re-evaluate alarm limits in engineering units, not raw units, otherwise the alarm will fire at the wrong point. For example, an alarm on a raw count of 30 000 corresponds to an engineering value of 100, not 30 000.

How do I divide a WinCC tag by 300 and display the result?

Drop an I/O field on the picture, open its Output Value property, choose Dynamic Dialog, and enter the formula 'MyTag' / 300. Set the datatype to Floating-point 32-bit IEEE 754 so the result keeps its decimals, then click Apply. The I/O field shows the divided value without creating an internal tag.

Why does my Dynamic Dialog formula return 0 in WinCC 7.0 SP3?

The most common cause is an integer-only datatype: if the source tag and the divisor are both integer (e.g. 'Tag1' / 300), integer division truncates any fractional part. Change the divisor to 300.0 or set the datatype in the Dynamic Dialog to Float. Also confirm the source tag is in Quality Code Good state in Tag Management.

Which method - Dynamic Dialog, Linear Scaling or VBScript - is best for a project-wide scaling?

Use Linear Scaling at the tag/channel layer for project-wide scaling. It evaluates once per acquisition cycle, the scaled value is a normal WinCC tag that every graphic, archive, and alarm can consume, and there is no script maintenance. Reserve Dynamic Dialog for one-off values on a single screen and VBScript for formulas with conditional logic.

Does the scaled internal tag require a WinCC PowerTag licence?

Yes. Every internal tag that is read or written by a graphic, archive, or script consumes one WinCC PowerTag. If the project is sized for 1 024 PowerTags, ten scaled internal tags each consume one of those 1 024 tags. Linear-scaled external tags also consume a PowerTag per scaled tag.

Can the division be done in the PLC instead of WinCC?

Yes - and for performance and licensing reasons it is often the better choice. On a S7-1500 write the scaled value directly into a DB (e.g. L DB10.DBD0 / 300.0 T DB10.DBD4) and configure a single WinCC tag to read DB10.DBD4. This avoids any HMI-side script, frees PowerTags, and makes the engineering value available to every consumer without recalculation.

Back to blog