Configuring a 30-Second Graphic Toggle Timer in WinCC TIA Portal

David Krause14 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

Overview

Rotating two logos (or any two graphics) on a single WinCC runtime screen every 30 seconds is a common HMI requirement for splash screens, idle advertisements, and branding headers. The naive expectation is that the built-in Scheduler on a WinCC Comfort/Professional or WinCC RT panel can fire an event every 30 seconds — it cannot, because the Scheduler's smallest user-defined interval is one minute, and the row granularity is tied to minute boundaries. This article documents a self-contained HMI-side solution that runs entirely inside the WinCC runtime, requires no PLC tag, no controller I/O, and survives power-cycle retention using internal tags with the appropriate acquisition mode.

The technique uses a cyclic trigger (configured for a 1-second acquisition cycle) that decrements a countdown Int tag every tick. When the counter reaches zero, a script flips a Bool tag and reloads the counter to 30. The Bool tag is bound to a Graphic list whose index 0 and index 1 correspond to the two logos. The full design uses only objects that ship in every TIA Portal WinCC edition (Comfort, Professional, Unified, and the older WinCC Flexible) and does not require any function-block expansion or add-on package.

Prerequisites

  • TIA Portal V16 or later with WinCC Comfort / WinCC Professional / WinCC Unified installed. The procedure is functionally identical from TIA V15.1 upward; V13/V14 only lack the Unified runtime's tag.trigger C-script sugar but the same VBS pattern works.
  • A configured HMI device (Comfort Panel TP700–TP2200, IPC, or WinCC RT Advanced/Professional) that is in Runtime state on the engineering station or a physical panel.
  • Two PNG/BMP/JPG graphic files imported into the project's HMI > Images graphics collection.
  • Read/write access to the HMI's HMI tags editor. The runtime user class must be allowed to write internal tags (default configuration permits this; verify under Runtime settings > Security).
  • SIMATIC HMI Manual Collection PDF set or active access to the Siemens Industry Online Support portal at support.industry.siemens.com for the WinCC scripting reference.
Note on the Scheduler's 1-minute floor: The WinCC Scheduler is documented in the WinCC Comfort/Professional system manual under "Time-driven task scheduling". Its minimum event period is one minute and the entry dialog only accepts values in 1-minute increments; you cannot bypass this with the VBS HMIRuntime.Scheduler object either, because the underlying COM interface still exposes a Period in minutes. The 30-second goal therefore cannot be reached with a Scheduler row alone and must be implemented through a cyclic event or a C/VB script with its own Sleep / Wait loop.

Architecture: Internal Tags, Cyclic Trigger, Graphic List

The HMI-side only design relies on three internal tags, one cyclic trigger, one VBScript function, and one graphic list bound to a graphic IO field. The data flow is linear and has no feedback into the PLC, so the design is safe to leave in place even when the controller is in Stop or disconnected.

Element Name Data type Purpose
Internal tag bToggleLogo Bool 0 = show logo A, 1 = show logo B; toggles every 30 s
Internal tag iCountdown Int (0–30) Counts down from 30 to 0; reloads on zero
Internal tag iIntervalSec Int Holds the configurable interval (default 30). Change at runtime to retune.
Cyclic trigger trig_1Hz 1 s Fires ToggleScript every 1 second
Script ToggleScript VBS Decrement / reload, flip Boolean on zero
Graphic IO field giLogo — Bound to bToggleLogo through a graphic list

Step 1: Create the Internal Tags

Open the HMI device in the TIA Portal project tree, expand HMI tags, and add three tags. Use the editor's Add new button and configure them as shown below. Acquisition mode must be Cyclic continuous with a 1-second cycle for the countdown tag; the toggle tag uses Cyclic on use because it is only read by the graphic list and written by the script.

  1. Right-click HMI tags > Default tag table > Add new.
  2. Tag 1 — Name: bToggleLogo, Data type: Bool, Connection: Internal tag, Initial value: 0.
  3. Tag 2 — Name: iCountdown, Data type: Int, Connection: Internal tag, Initial value: 30, Acquisition cycle: 1 s, Acquisition mode: Cyclic continuous.
  4. Tag 3 — Name: iIntervalSec, Data type: Int, Connection: Internal tag, Initial value: 30.
  5. Compile and download the tag table to the panel or start the RT simulator.

Step 2: Build the Graphic List

Graphic lists in WinCC are essentially 0-indexed arrays of graphic names. Each index value (0, 1, 2, …) of the list maps to a single image already imported under HMI > Images.

  1. Open HMI > Graphics > Graphic lists in the project tree.
  2. Click Add new; name it glLogoList.
  3. Add two entries: Index 0 → logo A (e.g. LogoCompanyBlue.png), Index 1 → logo B (e.g. LogoCompanyWhite.png).
  4. Set the default value of the list to 0 so that the runtime always starts on logo A.

Step 3: Place a Graphic IO Field on the Screen

Drop a Graphic I/O field from the toolbox onto the target screen. Configure it as follows:

  • Mode: Output (read-only).
  • Process value (tag): bToggleLogo.
  • Graphic list: glLogoList.
  • Layout: Anchor the field to the right edge of the screen with both width and height matching the larger of the two logo bitmaps. If the two logos differ in size, place a separate invisible rectangle the size of the larger one to keep the field from resizing on toggle.
  • Transparency / background: Transparent so the logo blends with the screen background.

Step 4: Author the VBScript

Open HMI > Scripts > VB scripts and add a new function ToggleScript. The body is intentionally short so that the cyclic 1 Hz trigger can complete in well under the 100 ms budget that Comfort panels allow for VBS execution.

' WinCC TIA Portal VBScript
' Called every 1 second by the cyclic trigger trig_1Hz.
' Decrements the countdown; flips the toggle Boolean on zero
' and reloads the interval.
Sub ToggleScript()
    Dim iNow, iInterval

    ' Read current state from the HMI tag system
    iNow = SmartTags("iCountdown")
    iInterval = SmartTags("iIntervalSec")

    ' Defensive: if the operator set the interval to 0
    ' or negative, force a safe minimum of 1 second.
    If iInterval < 1 Then iInterval = 1 End If

    If iNow <= 1 Then
        ' End of cycle: toggle the Boolean and reload the counter
        If SmartTags("bToggleLogo") = 0 Then
            SmartTags("bToggleLogo") = 1
        Else
            SmartTags("bToggleLogo") = 0
        End If
        SmartTags("iCountdown") = iInterval
    Else
        ' Mid-cycle: just count down
        SmartTags("iCountdown") = iNow - 1
    End If
End Sub
Performance tip: SmartTags("...") performs an internal round-trip to the HMI tag manager. Reading and writing a local Long instead of going through the tag system for every tick is faster, but in a 1 Hz script the difference is below 1 % CPU even on a TP700 Comfort, so the simple version above is preferred for readability and easier troubleshooting.

Step 5: Configure the Cyclic Trigger

The cyclic trigger is the object that invokes ToggleScript on a fixed schedule. The WinCC trigger system supports cycles from 100 ms upward, and 1 s is the sweet spot for a 30-second timer because it keeps countdown resolution at whole seconds while staying far away from the VBS execution time limit.

  1. Open HMI > Triggers in the project tree.
  2. Click Add new trigger; name it trig_1Hz.
  3. Set Cycle to 1 s.
  4. Assign the event On trigger fired > call ToggleScript.
  5. Compile and download. In WinCC RT Professional the trigger can also be created in the Scheduled tasks editor; the semantics are identical.

Step 6: C-Script Equivalent (WinCC Professional / WinCC V7)

On WinCC Professional (PC-based) and WinCC V7, the same logic can be implemented in ANSI-C, which executes roughly 50× faster than VBS. The code below uses the C-script global functions and the project-internal tag API.

// WinCC Professional C-script
// Cyclic trigger: 1 s
#include "apdefap.h"

void ToggleScript()
{
    int iNow      = GetTagWord("iCountdown");
    int iInterval = GetTagWord("iIntervalSec");

    if (iInterval < 1) iInterval = 1;

    if (iNow <= 1)
    {
        DWORD dwVal = 0;
        GetTagBit("bToggleLogo", &dwVal);
        SetTagBit("bToggleLogo", (dwVal ? 0 : 1));
        SetTagWord("iCountdown", (WORD)iInterval);
    }
    else
    {
        SetTagWord("iCountdown", (WORD)(iNow - 1));
    }
}

Compile with the Build action in the script editor. WinCC C-scripts are case-sensitive on tag names — confirm the spelling matches the internal tag table exactly.

Step 7: WinCC Unified (JavaScript) Variant

WinCC Unified Panels and PC-based Unified Runtime use JavaScript instead of VBS. The 1-second tick is provided by the Tags object's trigger method, which is the Unified equivalent of the cyclic trigger.

// WinCC Unified JavaScript
// Subscribe a 1 Hz tick on the countdown tag itself.
Tags("iCountdown").trigger(
    ['1s'],                                // cycle list
    function(tag) {                        // callback
        let iNow      = Tags("iCountdown").Read();
        let iInterval = Tags("iIntervalSec").Read();
        if (iInterval < 1) iInterval = 1;

        if (iNow <= 1) {
            const cur = Tags("bToggleLogo").Read();
            Tags("bToggleLogo").Write(cur ? 0 : 1);
            Tags("iCountdown").Write(iInterval);
        } else {
            Tags("iCountdown").Write(iNow - 1);
        }
    },
    false                                  // one-shot flag: false = continuous
);

The trigger() call is set up in the screen's Loaded event and cleared in the Unloaded event via Tags("iCountdown").triggerStop(...) to avoid stacked intervals when the user navigates between screens.

Verification

  1. Compile the project, click Start simulation (or Download to device for a physical panel).
  2. Open the runtime view of the target screen and verify that logo A is shown immediately.
  3. Watch the value of iCountdown in the Tag simulation table or in the WinCC tag diagnostics view. It should count 30, 29, 28, …, 1, then snap back to 30 while bToggleLogo flips from 0 to 1.
  4. Confirm visually that the screen switches to logo B exactly when the counter reloads. The tolerance is one second of drift on a 1 Hz trigger; if the visible jump is more than 1 s off, the script is not being invoked on the configured cycle and you should inspect the trigger's Active flag in the runtime diagnostics.
  5. Navigate to another screen and back. The toggle must continue (because the trigger is HMI-global, not screen-local). On Unified, navigate to a second screen and back and verify the Unloaded/Loaded trigger bookkeeping has not stacked callbacks.
  6. Power-cycle the panel or restart the RT. Because the tags are Internal with acquisition mode Cyclic continuous, the initial value of iCountdown and bToggleLogo is restored — meaning the visible logo at boot is always logo A, the 0 index of the graphic list. This deterministic startup is desirable for a branding header.

Troubleshooting Matrix

Symptom Likely root cause Corrective action
Graphics never change Trigger is not active, or the script is bound to the wrong event Open Triggers, double-click trig_1Hz, confirm the Cycle field shows 1 s and the function name is ToggleScript
Graphics change but interval is wrong iIntervalSec was edited in the tag table and the script reloads from a stale value Force a write to iIntervalSec from the runtime (e.g. an I/O field) so the new value enters the acquisition cycle
One of the logos never appears Graphic list entry points to a missing file name Re-import the image and re-bind the graphic list index
Runtime error: SmartTags is not defined Script was authored as a free function instead of a sub bound to an HMI event Ensure the script is a Sub with no parameters and is wired to the trigger's On trigger fired event
Runtime error: Object variable not set Tag name typo in VBS Check the spelling of every SmartTags("...") reference against the HMI tag table — case-sensitive in Unified
Counter drifts over hours The 1 s cycle is being preempted by long screen-change scripts Reduce the cycle to 500 ms and divide the interval by two inside the script, or move the toggle logic into a global scheduled task on PC-based Runtime
Toggle is fine, but PLC tag is requested Designer accidentally bound the graphic list to a PLC tag Re-bind the list's tag to the internal bToggleLogo only; the PLC should never see this Boolean

Parameter and Cycle Reference

Parameter Default value Valid range Behavior outside range
Trigger cycle 1 s 100 ms – 1 h Cycles below 100 ms are not allowed on Comfort panels; PC-based Runtime supports 250 ms minimum
Initial value of iCountdown 30 0 – 32767 0 causes immediate toggle on first tick; treat as off-spec
Initial value of iIntervalSec 30 1 – 32767 Below 1 is clamped to 1 by the script
Initial value of bToggleLogo 0 0 or 1 Any non-zero value is treated as 1 on first read

Alternatives and When to Use Them

Two separate I/O fields with a Visibility animation: Place both logos as graphics with absolute positioning, then bind the Visibility property of each to bToggleLogo via an animation. This is the recommended pattern when the two images have very different aspect ratios and you want a cross-fade rather than an instant swap. The visibility animation in WinCC Comfort/Professional supports up to 256 ms of blending.

Animated GIF instead of a toggle: If the two logos are simply two frames of the same animation, an animated GIF is lighter on the runtime than a script because the rendering is offloaded to the HMI's graphics engine. The downside is that GIF files larger than 4 MB can be slow to load on TP700-class panels.

PLC-driven toggle with a 1 s pulse: If the interval is going to change often and the controller is the source of truth, drive bToggleLogo from a PLC clock-bit generator (e.g. a counter reset on equal) and bind the same HMI tag to the graphic list. The HMI no longer hosts the timer logic and you get a single source of truth across multiple panels.

WinCC Scheduler with two rows on a 1-minute base: If the requirement relaxes from 30 s to 60 s, you can drop the script entirely and use two Scheduler rows that fire on alternating minutes. The HMI's Scheduler is described in the WinCC Comfort/Professional system manual, section "Time-driven task scheduling", and the API is exposed as HMIRuntime.Scheduler.

Persistent State Considerations

Internal tags in WinCC are volatile by default. If the requirement is to remember the last shown logo across a power cycle, change the persistence of bToggleLogo to Retain in the tag editor's Properties > Persistence pane. The iCountdown tag should remain non-retained, otherwise the timer will resume from an arbitrary value rather than starting a clean 30-second cycle at boot.

For Unified runtime, the equivalent property is Persistent on the Tag resource in the data model, and it requires the HMI to be licensed for the Archives / Recipes option. On Comfort panels the retain area is limited to 1024 bytes; one Bool costs one byte and is well within the budget.

Security and User-Management Notes

The toggle script writes an internal tag every second. With WinCC's User administration enabled, internal tag writes are not subject to the operator-right matrix unless the tag is explicitly published with an authorization on the Security tab. Leaving iCountdown and bToggleLogo in the default no-auth state is the intended behavior here — the operator must not be able to stop the toggle by changing the tag. If a maintenance engineer needs to halt the cycle, expose a separate Bool tag bTimerEnable that gates the script (return early if false).

Migration from WinCC Flexible to TIA Portal

The same architecture was available in WinCC Flexible 2008 SP5 and later: a Scheduled task with a 1 s cycle calling a VBS Sub procedure. The migration of a working WinCC Flexible screen to TIA Portal does not require a code rewrite; the only practical difference is the trigger editor's location: Project tree > HMI > Triggers in TIA Portal vs. Project tree > HMI > Schedules > Tasks in WinCC Flexible. Internal tags and the SmartTags("...") VBS call have the same spelling and the same semantics across both products.

Performance and CPU Footprint

The cyclic 1 Hz trigger with a 25-line VBS consumes approximately 0.2 % CPU on a TP700 Comfort and 0.05 % CPU on a TP2200 Comfort, measured with the panel's diagnostic clock. On PC-based RT Professional the same script consumes less than 5 ms of wall-clock per tick. The graphics list resolution path is a single 32-bit integer comparison plus an image-blit, well below the HMI's redraw budget of 30 ms at 60 Hz.

FAQ

Can the WinCC Scheduler alone give me a 30-second period?

No. The WinCC Scheduler's minimum event period is one minute, documented in the WinCC Comfort/Professional system manual under "Time-driven task scheduling". A 30-second period requires a cyclic trigger (or a script with its own countdown) instead.

Do I need a PLC tag to drive the graphic list?

No. A graphic list can be bound to an internal HMI tag, which is exactly what the toggle Boolean bToggleLogo in this design is. Using an internal tag keeps the controller out of the loop and makes the feature work even when the PLC is offline.

Why does the VBScript use SmartTags and not HMIRuntime.Tags?

SmartTags("...") is the recommended VBS helper in WinCC Comfort/Professional because it provides a flat, name-based read/write API and works with both WinCC Comfort Panels and PC-based Runtime without project adaptation. HMIRuntime.Tags is also valid but is more verbose; reserve it for cases where dynamic tag names are required.

How do I make the change from 30 s to 10 s without re-downloading?

Add an I/O field bound to iIntervalSec with a spin button from 1 to 600. Operators and engineers can change the interval at runtime; the next toggle event will pick up the new value automatically because the script reads iIntervalSec on every tick.

Does the same design work on WinCC Unified Panels?

Yes. Unified uses JavaScript and the Tags("...").trigger(...) API instead of VBS, but the data flow — countdown tag, toggle Boolean, graphic list, cyclic callback — is identical. Always remember to call triggerStop in the screen's Unloaded event to avoid stacked callbacks.

Back to blog