WinCC: Compare Two Analog Values in Dynamic Dialog Expression

David Krause15 min read
HMI / SCADASiemensTutorial / 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. Problem Statement: Conditional Analog Comparison on a Runtime Screen

Burner control panels on combustion skids, reformer heaters and process furnaces routinely monitor two correlated analog variables: the primary flow tag and a derived back-pressure tag. Operators must react within seconds when these values drift out of the working envelope. A practical field case uses the following engineering limits:

Condition O2 Flow Tag O2 Back-Pressure Tag Required Operator Action
High-pressure trip > 3000 (Nm3/h) > 10 (bar) Popup "BACK PRESSURE NOT MATCHING (HIGH)"
Low-pressure trip > 3000 (Nm3/h) < 2 (bar) Popup "BACK PRESSURE NOT MATCHING (LOW)"
Normal envelope > 3000 (Nm3/h) 2 to 10 bar No popup
Burner idle <= 3000 (Nm3/h) any No popup

The challenge is that both signals are read into the same controller and must be evaluated together against fixed thresholds before a runtime popup is raised. WinCC Dynamic Dialog accepts C-style expressions and can evaluate arithmetic and relational operators, but in practice the cleanest implementation routes the comparison through the controller and exposes the result as a Boolean tag, which the HMI then uses to drive Alarm Logging entries and Dynamic Dialog properties (color, flashing, visibility).

Engineering rationale: Threshold-based comparison is the same logic a hardware analog comparator executes: an input signal is tested against a reference and the output is asserted when the reference is exceeded. Propagation delay in a hardware comparator (typically tens to hundreds of nanoseconds, see the Analog Devices analog-dialogue reference) is irrelevant on a PLC scan cycle, but the same comparator principle — evaluate, latch, drive output — applies to the S7-1500 code shown in section 4.

2. Architectural Decision: Compare in PLC or in HMI

WinCC Dynamic Dialog is a powerful runtime evaluator, but it is not a substitute for control logic. The Siemens documentation treats Dynamic Dialog as a presentation-layer tool: it controls the visual appearance of an object (background color, blinking, fill level, position, visibility). It can fire an event via a C-action or VB-script, but using it as the sole condition engine for safety-relevant alarms introduces four risks:

  1. Scan independence. HMI scripts run on the HMI scan, not the PLC OB1 cycle. A PLC in OB35 (100 ms) can guarantee a deterministic reaction; the HMI may be busy with picture changes.
  2. Connection loss behavior. If the S7 connection drops, the HMI stops evaluating. The PLC retains the last computed alarm bit, which can still drive an audible horn through a hardwired output.
  3. Audit trail. Plant historians and FDA / GAMP reviews require the alarm bit to originate from the validated control layer.
  4. Auditability of limits. The thresholds 3000, 10 and 2 should live as named constants in the PLC project so they appear in the validated source and the change log.

The recommended split is therefore:

  • PLC: threshold comparison, hysteresis, first-up handling, latch bits.
  • WinCC: alarm view, message text, dynamic dialog color/flashing, operator acknowledge.

3. Prerequisites

Item Specification Notes
Engineering software SIMATIC WinCC V7.5 SP2 / SP3 / SP4 OR TIA Portal V17 / V18 with WinCC Professional V17 / V18 Dynamic Dialog syntax is identical; runtime APIs differ
Controller S7-1500 CPU 1515-2 PN (6ES7515-2AM02-0AB0) firmware V2.9 or newer; S7-1200 CPU 1214C DC/DC/DC (6ES7214-1AG40-0XB0) firmware V4.4 or newer; classic S7-300 CPU 315-2 PN/DP (6ES7315-2EH14-0AB0) supported Comparison instructions available in all
Analog input modules SM 531 AI 8xU/I/RTD/TC (6ES7531-7KF00-0AB0) for flow; SM 531 AI 4xU/I/RTD/TC (6ES7531-7QD00-0AB0) for pressure Configure 4 to 20 mA, 0 to 10 V, or HART per transducer datasheet
HMI runtime WinCC Runtime Professional V18 on SIMATIC IPC227G (6ES7647-8BA11-0AA0) or Panel IPC677D Minimum 4 GB RAM, 32 GB SSD
Network PROFINET, CPU and HMI on same subnet, 1 Gbit/s preferred S7 connection handles tags
PLC tags "O2_Flow" (REAL), "O2_BackPressure" (REAL), "BackPressure_High_Alarm" (BOOL), "BackPressure_Low_Alarm" (BOOL) Use symbolic addressing throughout
Hardware scaling reminder: A 4 to 20 mA pressure transducer with a 0 to 25 bar range returns 4 mA at 0 bar and 20 mA at 25 bar. The AI module raw count is 0 at 4 mA and 27648 at 20 mA. Always scale in the PLC (NORM_X + SCALE_X) so the engineering tag carries bar units, never raw counts.

4. PLC Logic Implementation

4.1 S7-1500 STL Ladder (FBD view)

The classic two-network ladder using the IEC compare blocks. Each block evaluates one relational condition against the engineering tag and produces a BOOL result.


Network 1: BACK_PRESSURE_HIGH
      |  >     |
IN1---| O2_Flow |--OUT       AND
      |  3000 0 |
      |---------|---          |
      |  >     |             |
IN2---|O2_BackP |--OUT        |
      |  10.0  |             |
      |---------|-------------|
                              |
                              Q --- BackPressure_High_Alarm

Network 2: BACK_PRESSURE_LOW
      |  >     |
IN1---| O2_Flow |--OUT       AND
      |  3000 0 |
      |---------|
      |  <     |
IN2---|O2_BackP |--OUT
      |  2.0   |
      |---------|
                              Q --- BackPressure_Low_Alarm

Wire the constant block outputs to 3000.0 (REAL) and 10.0 / 2.0 (REAL). The compare blocks use the IEC 61131-3 standard operators ">" (GT) and "<" (LT) and are typed REAL so no implicit conversion occurs.

4.2 S7-1500 SCL (Structured Control Language)

SCL is preferred for complex comparisons because it is easier to maintain, supports hysteresis and one-shot latches inline, and reads as documentation. Drop the following into a function block named FB_O2_Burner_Alarm and call it from OB35 at 100 ms.


FUNCTION_BLOCK "FB_O2_Burner_Alarm"
VAR
    // Inputs
    O2_Flow           : REAL;          // Nm3/h
    O2_BackPressure   : REAL;          // bar
    Flow_Enable       : REAL := 3000.0; // Nm3/h threshold
    PressHigh_Limit   : REAL := 10.0;   // bar
    PressLow_Limit    : REAL := 2.0;    // bar
    Hysteresis        : REAL := 0.25;   // bar, prevents chattering
    // Outputs
    HighAlarm         : BOOL;
    LowAlarm          : BOOL;
    // Static
    HighAlarm_Latched : BOOL;
    LowAlarm_Latched  : BOOL;
END_VAR
BEGIN
    // High envelope: pressure above PressHigh_Limit + Hysteresis to set,
    // below PressHigh_Limit to clear (Schmitt-trigger behaviour)
    IF (O2_Flow > Flow_Enable) AND (O2_BackPressure > PressHigh_Limit + Hysteresis) THEN
        HighAlarm_Latched := TRUE;
    ELSIF (O2_BackPressure < PressHigh_Limit) THEN
        HighAlarm_Latched := FALSE;
    END_IF;

    // Low envelope
    IF (O2_Flow > Flow_Enable) AND (O2_BackPressure < PressLow_Limit - Hysteresis) THEN
        LowAlarm_Latched := TRUE;
    ELSIF (O2_BackPressure > PressLow_Limit) THEN
        LowAlarm_Latched := FALSE;
    END_IF;

    HighAlarm := HighAlarm_Latched;
    LowAlarm  := LowAlarm_Latched;
END_FUNCTION_BLOCK

The hysteresis of 0.25 bar prevents the alarm from toggling every 100 ms when the back-pressure sits exactly on the threshold — a common nuisance on combustion rigs. Increase it for slow loops, decrease it for fast loops.

4.3 Classic STEP 7 (S7-300 / S7-400)

For older CPUs without SCL (CPU 312, 314, 315-2 AH01 etc.), use STL with the IEC compare instructions:


Network 1
      L     "O2_Flow"            // REAL in MD100
      L     3.000000e+003        // REAL constant
      >R                            // REAL greater-than, sets RLO
      JCN   NOHI                  // jump if RLO = 0
      L     "O2_BackPressure"    // REAL in MD104
      L     1.000000e+001        // 10.0 bar
      >R
      JCN   NOHI
      S     "BackPressure_High_Alarm"
      JU    ENDS1
NOHI: R     "BackPressure_High_Alarm"
ENDS1: NOP   0

The S7-300 instruction set does not include a single combined compare, so two REAL compares are chained. Use MD100/MD104 as scratch REALs declared in the symbol table; do not reuse them across FBs.

5. WinCC Tag Configuration

Once the PLC writes the two BOOL outputs, register them as WinCC tags under the same S7 connection that carries the analog tags.

  1. Open WinCC Explorer and select Tag Management > SIMATIC S7 PROTOCOL SUITE > TCP/IP.
  2. Right-click the existing connection (for example S7_VERB1) and choose New Tag.
  3. Create four tags as listed:
WinCC Tag Name Data Type PLC Address Length Update
O2_Flow_Raw Float 32-bit IEEE 754 DB201.DBD0 4 bytes 500 ms
O2_BackPressure_Raw Float 32-bit IEEE 754 DB201.DBD4 4 bytes 500 ms
BackPressure_High_Alarm Binary Tag DB201.DBX10.0 1 bit 250 ms (cyclic, with change)
BackPressure_Low_Alarm Binary Tag DB201.DBX10.1 1 bit 250 ms

Set the acquisition mode to Cyclic on change for the two BOOLs so the HMI never has to poll the bit when nothing has changed. For the analog tags, choose a 500 ms cycle: 250 ms burns CPU on the panel without adding value on slow combustion processes.

Address-width reminder: When you create a new tag from the dialog, the default type is "Binary Tag". WinCC will silently truncate if you point it at a DBB or DBW. Always confirm the Length field matches the actual data width, otherwise the tag will read garbage from the neighbouring byte.

6. Alarm Logging: Triggering the Runtime Popup

WinCC Alarm Logging is the correct subsystem for raising operator messages with a popup. Dynamic Dialog is for visual style; Alarm Logging is for the message text, the acknowledge logic, and the audible horn.

  1. Open Alarm Logging from the WinCC Explorer and create a new message class, for example Process alarms with priority 1 (highest).
  2. Add a new single message with the following parameters:
Field Value
Message number 100001
Message text BACK PRESSURE NOT MATCHING (HIGH) - O2 flow @ %d s, Pressure @ %.2f bar
Trigger tag BackPressure_High_Alarm
Trigger bit position 0 (rising edge - "came in" event)
Acknowledgement Required, single ACK
Color Red text on white background
  1. Repeat for message 100002 bound to BackPressure_Low_Alarm with text BACK PRESSURE NOT MATCHING (LOW) - O2 flow @ %d s, Pressure @ %.2f bar.
  2. Add a WinCC Alarm Control to the runtime picture, dock it to the right side, and bind the message filter to message numbers 100001 to 100002.
  3. Enable the Popup Window property on the Alarm Control with a 5-second auto-close if the bit resets before operator acknowledgement.

The two format specifiers %d and %.2f are filled from process value blocks attached to the message. Add an output value field on each message and bind it to O2_Flow_Raw (format "@s%9d@") and O2_BackPressure_Raw (format "@s%9.2f@") respectively. WinCC will substitute the live value when the alarm is raised.

7. Dynamic Dialog Expressions for Visual Feedback

Now that the message is in Alarm Logging, layer Dynamic Dialog on top of the analog value object on the picture to give the operator a glanceable cue before the popup is even shown.

  1. On the process picture, insert an I/O Field bound to O2_BackPressure_Raw.
  2. Right-click the I/O field, choose Properties > Appearance > Background Color > Dynamic....
  3. Select Dynamic Dialog as the trigger and enter the following ANSI C expression:

((GetTagFloat("O2_Flow_Raw") > 3000.0)
   && (GetTagFloat("O2_BackPressure_Raw") > 10.0))   ?  CO_RED
: ((GetTagFloat("O2_Flow_Raw") > 3000.0)
   && (GetTagFloat("O2_BackPressure_Raw") < 2.0))    ?  CO_YELLOW
:                                                    CO_GREEN
  1. Apply the same Dynamic Dialog to the Flashing property with the boolean outputs to make the field blink when an alarm bit is set.

The three-way ternary returns a color constant from the WinCC palette (CO_RED = 255, CO_YELLOW = 65535, CO_GREEN = 65280). At runtime, every change event on either analog tag re-evaluates the expression in the HMI scan and repaints the field.

Dynamic Dialog limitation: The C interpreter inside WinCC 7.x only supports a subset of ANSI C. Ternary operators, logical AND/OR, comparison operators, and the GetTag* family are supported; pointer arithmetic, malloc/free and external headers are not. Keep expressions flat and avoid function declarations inline.

8. WinCC Professional (TIA Portal) Variant

If the runtime is WinCC Professional V17/V18 inside TIA Portal, there is no Dynamic Dialog dialog box; the equivalent is the Animations editor and the PLC code-driven look-and-feel configured in the HMI tag properties.

  1. Open the HMI device, navigate to Screen > IO field > Properties > Animations > Appearance.
  2. Add a new animation of type Dynamic filling / color, bind the trigger to BackPressure_High_Alarm OR BackPressure_Low_Alarm using a script tag, and configure the appearance ranges:
Range Background Color
0 (no alarm) Green, #7FBF7F
1 to 9 (warning) Yellow, #FFFF7F
10+ (critical) Red, #FF4040, with flashing 500 ms
  1. For the popup itself, use the HMI Alarm Control element and bind it to the configured alarm class "Process".
  2. On the PLC side, ensure that the alarm bits are routed through Program_Alarm source so the message text is generated from the PLC code (TIA V17+). This eliminates the duplication between PLC code and HMI message text and is the recommended approach for GAMP 5 projects.

The Program_Alarm instruction in SCL looks like:


IF (O2_Flow > 3000.0) AND (O2_BackPressure > 10.0) THEN
    "Program_Alarm_High" := TRUE;   // raises the alarm and sends text to HMI
END_IF;

9. Runtime Verification Checklist

  1. Download the project to the S7-1500 and put it in RUN.
  2. Start WinCC Runtime and open the burner process picture.
  3. Force O2_Flow = 3500 Nm3/h and O2_BackPressure = 12 bar in the PLC watch table.
  4. Verify that BackPressure_High_Alarm becomes TRUE within one OB35 cycle (100 ms).
  5. Verify that the IO field turns red, starts flashing, and that message 100001 appears in the Alarm Control popup within 1 second.
  6. Acknowledge the message; the popup auto-closes; the field remains red until the bit clears.
  7. Force O2_BackPressure = 1 bar. Verify that BackPressure_High_Alarm stays latched (hysteresis) until the value crosses 9.75 bar (10.0 - 0.25).
  8. Force O2_BackPressure = 0.5 bar. Verify that BackPressure_Low_Alarm goes TRUE and message 100002 fires.
  9. Reset both forctes; verify both alarm bits clear and the field turns green.
  10. Pull the PROFINET cable to simulate a network drop. The PLC should keep both alarm bits at their last state. Reconnect the cable; the HMI should resynchronize within 5 seconds without operator intervention.

10. Troubleshooting Matrix

Symptom Likely Cause Diagnostic Step Corrective Action
Popup never fires even with valid conditions Alarm bit never goes TRUE in PLC Open the PLC online watch table; monitor "BackPressure_High_Alarm" and "BackPressure_Low_Alarm" Verify the compare blocks are inside the OB35 / OB1 scan; check that "O2_Flow" tag is updating (force the value to be sure)
Alarm fires, but no popup Alarm Logging message text not linked to the trigger tag In Alarm Logging editor, right-click message 100001 and confirm Trigger tag = BackPressure_High_Alarm Rebind the trigger tag, save the project, restart WinCC Runtime
Alarm fires continuously, will not acknowledge Alarm bit stays TRUE; PLC logic never resets the latch Check the hysteresis logic in FB_O2_Burner_Alarm; force the analog tag to a safe value Add a manual reset bit wired through HMI acknowledge, or correct the hysteresis direction
Dynamic Dialog color always green Expression not parsing; ternary short-circuits Right-click the Dynamic Dialog and open the expression tester; evaluate with known values Replace && with & if using older WinCC 7.0 build; ensure no stray spaces inside function names
Both high and low alarm active at the same time Wrong compare operator on the back-pressure side Cross-check the ladder: high should be > 10; low should be < 2 Recompile with corrected operator; do not mix GT/LT blocks with NE or EQ
Alarm chatters every 100 ms No hysteresis, or hysteresis too tight Trace O2_BackPressure with the PLC trace; count zero-crossings Increase Hysteresis to 0.5 bar; debounce the analog input if the sensor is noisy
Popup shows wrong engineering units (raw counts) WinCC output value field not formatted Edit the output value format string in Alarm Logging Use @s%9.2f@ for bar, @s%9d@ for Nm3/h
Popup text static, never shows current value Output value fields not enabled in the message Open the message in Alarm Logging; confirm Output Value list is not empty Add both analog tags as output values and tick "Use"

11. Performance and Best Practices

On a Panel PC running WinCC Runtime Professional with 50 000 tags and 30 screens, the Dynamic Dialog engine evaluates at picture-change time and again on every configured change event. Keep the following heuristics in mind for plants with hundreds of analog points:

  • Limit Dynamic Dialog to visible elements. Hidden I/O fields still evaluate unless you tick "Disable dynamic when hidden" in the configuration dialog.
  • Prefer BOOL tags over re-evaluation. A single Boolean tag "O2_Burner_OutOfEnvelope" computed in the PLC drives color, flashing and visibility with one expression. This reduces the HMI scan load.
  • Group related alarms under one message class. Avoid spamming the Alarm Logging archive with one message per tag.
  • Use the Watchdog concept. Add a heartbeat tag toggled every cycle from the PLC; Alarm Logging raises a "Communication failure" message if the heartbeat is missing for more than 3 seconds.
  • Validate the thresholds against P&ID. The numbers 3000 Nm3/h, 10 bar and 2 bar must trace back to the HAZOP and the burner OEM datasheet. Keep them in a single constants block (FC_O2_Limits) so a calibration update is one edit, not a grep-and-replace.
  • Document the hysteresis. Operators will ask why a value above the high limit does not raise the alarm immediately; a comment in the FB is not enough. Add the hysteresis value as a configurable HMI tag visible from the engineering screen.
Safety reminder: Popup messages on an HMI are informational, not safety-rated. If the burner must shut down on back-pressure loss, the trip logic lives in the controller (typically in a SIL-rated PLC or a hardwired safety relay) and the HMI only displays the resulting state. The alarm bit shown in this article is for operator awareness, not for SIS function.

Frequently Asked Questions

Can WinCC Dynamic Dialog compare two analog tags by itself and raise a popup without any PLC code?

In WinCC V7.x the Dynamic Dialog engine can evaluate compound C expressions like (GetTagFloat("A")>3000) && (GetTagFloat("B")<2) and return a color or trigger a flash, but it cannot directly raise an Alarm Logging message. You still need a BOOL tag — either from the PLC or computed in a WinCC global script — bound to the message trigger. The recommended pattern is to compute the boolean in the PLC and let the HMI only render the alarm.

What is the smallest HMI panel that supports Dynamic Dialog expressions and Alarm Logging?

All Comfort Panels from the TP700 Comfort (6AV2124-1GC01-0AX0) onwards support both subsystems in WinCC Comfort / WinCC Advanced V17 or V18. Below that — Basic Panels using WinCC Basic — only the field-level "Look & Feel" range and limited discrete alarms are available, and Dynamic Dialog is restricted to a fixed dropdown of pre-canned conditions.

How fast does the alarm bit reach the HMI after the analog value crosses the threshold?

With a 250 ms acquisition cycle on the WinCC tag and a 100 ms OB35 in the PLC, worst-case latency is approximately 350 ms. To tighten this, drop the HMI acquisition to 100 ms and run the PLC comparison in OB30 at the same period. Going below 100 ms wastes CPU on both ends without operator-visible improvement on a 4-Hz burner loop.

Should the low-pressure threshold be set above zero to detect sensor failure?

Yes — if a 4 to 20 mA transducer loses the loop power, the analog input reads 4 mA = 0 bar. With the current threshold of < 2 bar, the system already raises the low alarm on a dead sensor, but it does not distinguish "no flow" from "sensor failed". Add a second condition: LowAlarm = (O2_Flow > 3000) AND ((O2_BackPressure < 2) OR (O2_BackPressure_Raw < 4000)), where the right-hand side reads the raw mA value to flag a sensor break.

Why does my popup show message 100001 with the correct trigger but the text reads "@s%9d@" instead of the value?

The format string must be wrapped with the at-sign delimiters in the Alarm Logging output value configuration, not in the message text itself. Open message 100001, go to Output Value, and set the value format to @s%9.2f@ for the pressure tag and @s%9d@ for the flow tag. Save and restart the runtime — the popup will now substitute the live values on every alarm event.

Back to blog