WinCC Internal Timer: VBScript Global Script Animation Guide

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

WinCC V7.x (and TIA Portal WinCC Professional) expose a complete project-internal timing and scripting environment that does not require any external PLC variables. An internal timer in WinCC is built from three coordinated elements: an internal (HMI-side) tag that holds the elapsed count, a global action triggered by a configurable user-defined update cycle, and a VBScript (or C) function that increments the tag and writes the resulting value into object properties such as LEFT or TOP. This pattern is the canonical solution for screen animations, periodic housekeeping, blinking fields, sequence timers, and time-based logic that must run independently of the connected automation system.

WinCC V7 supports up to five project-wide user-defined trigger cycles in addition to the two fixed cycles (500 ms and Upon change). The global action editor lets you bind any project function to one of these cycles. Combined with an internal integer tag that is reset on the largest enclosing interval, this gives the engineer a deterministic, tick-based time base without writing a single line of PLC code. The pattern is documented in the Siemens WinCC V7.5 SP2 Programming and Operating Manual and the WinCC V7.5 VBS Reference.

Scope note: This article targets WinCC V7.x with the VBScript global script environment. TIA Portal WinCC Professional (V16/V17/V18/V19) exposes a similar but renamed feature set under Scheduled Tasks and VBScript procedures. The internal-tag and cycle-trigger model is functionally identical; menu paths differ.

Prerequisites

  • WinCC V7.4 SP1 or later installed with the VBScript and Global Script option (default with the standard installer). Verify with Start → All Programs → Siemens Automation → WinCC → WinCC Explorer opening without error.
  • Editor rights for the project (administrator or configured HMI engineer role in the User Administrator).
  • A started runtime test environment or a connected panel with the same firmware generation as the development target.
  • Familiarity with the Tag Management dialog, the Global Script editor, and the Properties dialog of a graphics object.
  • Optional: A reference chronometer or WinCC online trend to verify the elapsed-time behavior after configuration.

Architecture: Internal Tags, Triggers, and Actions

The timing model in WinCC V7 is event-driven, not multi-threaded. A trigger fires a global action at a configurable cadence; the action reads/writes tags and the runtime immediately re-evaluates any object properties bound to those tags. The relevant components are:

Component Type Purpose Default Location
Internal integer tag Unsigned 16/32-bit Holds the elapsed counter or current state index Tag Management → Internal Tags
User-defined update cycle Time cycle Defines the tick rate (e.g., 1 s, 250 ms) Computer Properties → Cycles
Global action (VBScript) Action Increments tag, evaluates state, writes object properties Global Script → Actions
Project function (VBScript) Function Reusable logic called by the action Global Script → Project Functions
Tag-to-property connection Animation Binds LEFT/TOP or dynamic dialog to a tag Object Properties → Properties → Geometry

Unlike a PLC timer (TP, TON, TOF in STEP 7), a WinCC internal timer is a purely software construct. It does not survive a runtime restart unless the tag is configured as Retain in the Internal Tags dialog; for animation work this is normally undesirable because the timer should restart at zero on each screen open.

Step 1: Create the Internal Integer Tag

  1. Open WinCC Explorer → Tag Management.
  2. Right-click Internal Tags and select New Tag.
  3. Configure the tag with the following parameters. The names below are conventions used in the rest of this article; rename to match project naming policy.
Tag Name Data Type Length Initial Value Retain Usage
Anim_Tick100ms Unsigned 32-bit 4 bytes 0 No Master 100 ms counter
Anim_PosX Float 32-bit 4 bytes 0.0 No X position output (0–200 px)
Anim_PosY Float 32-bit 4 bytes 0.0 No Y position output
Anim_State Unsigned 16-bit 2 bytes 0 No Sequence state (0..3)
Anim_Run Binary tag 1 bit 0 No Enable flag from process
Why a 100 ms counter? Coarser ticks (1 s) make 10-step motion look choppy on a 10-second profile. A 100 ms tick combined with integer division yields clean step values; finer ticks (10 ms, 20 ms) are supported but consume more CPU and are rarely needed for visual animation.

Step 2: Configure the User-Defined Update Cycle

  1. In WinCC Explorer, right-click the project node and choose Properties.
  2. Switch to the Cycles tab.
  3. Add a new user-defined cycle with name User_Cycle_100ms and value 100 ms.
  4. Add a second cycle User_Cycle_1s at 1 s for housekeeping tasks.
  5. Add a third cycle User_Cycle_5s at 5 s for the dwell between motion segments.

The Cycles tab enforces the limit of five user-defined cycles. Names appear in the global action trigger dropdown. Confirm that the runtime has loaded the cycles by viewing them under Computer → Properties → Cycles after the first start.

Step 3: Author the VBScript Global Action

  1. Open Global Script → Actions.
  2. Right-click the Global Actions container and choose New Action → VBS Action.
  3. In the trigger column, select User_Cycle_100ms from the dropdown. Do not use Upon change; for an internal timer you need a deterministic periodic trigger.
  4. Paste the reference implementation below. Replace tag names to match your project.
Option Explicit ' WinCC V7 Global Action - Internal Timer for screen animation ' Trigger: User_Cycle_100ms (100 ms) Dim oTick, oPosX, oState, oRun Set oTick = HMIRuntime.Tags("Anim_Tick100ms") Set oPosX = HMIRuntime.Tags("Anim_PosX") Set oState = HMIRuntime.Tags("Anim_State") Set oRun = HMIRuntime.Tags("Anim_Run") oTick.Read oRun.Read oState.Read oPosX.Read If oRun.Value Then Dim t : t = CLng(oTick.Value) + 1 oTick.Write t Dim s : s = CLng(oState.Value) Dim x : x = CDbl(oPosX.Value) Select Case s Case 0 ' Ramp 0 -> 200 over 10 s (100 ticks of 100 ms) If t <= 100 Then x = (t / 100) * 200 Else s = 1 t = 0 End If Case 1 ' Dwell 5 s (50 ticks) If t >= 50 Then s = 2 t = 0 End If Case 2 ' Continue ramp 200 -> 400 over 10 s If t <= 100 Then x = 200 + (t / 100) * 200 Else s = 3 t = 0 End If Case 3 ' Pause 2 s and loop If t >= 20 Then s = 0 t = 0 x = 0 End If End Select oState.Write s oPosX.Write x End If

Save and compile the action. WinCC VBScript supports the standard HMIRuntime.Tags(...) object for tag access. Call Read before evaluating and Write after computing; batched reads are not required for this volume.

Step 4: Bind the Tag to the Object Position

  1. Insert a Rectangle (or any object) on the target screen.
  2. Open Properties → Geometry → Position X.
  3. Right-click the value and choose Dynamic dialog (preferred for simple linear mapping) or Tag connection.
  4. For Dynamic dialog: select Anim_PosX, type Direct, range 0..400. The runtime converts the float tag value directly to pixels.
  5. For Tag connection: select Anim_PosX as a Process link and enable Update on tag change. This avoids the dynamic-dialog intermediate expression engine.

Position Y is static (zero offset). The shape will now move horizontally from 0 to 400 pixels under the control of the global action, with a 5 s dwell between the two 10 s motion segments and a 2 s terminal pause, exactly as specified in the source scenario.

Step 5: Multi-Segment Motion Profile and 10-Step Quantization

The original requirement asked for a 10-step motion over 10 s. Quantize by adding a step index that updates every 10 ticks:

Case 0 If (t Mod 10) = 0 Then Dim step : step = (t \ 10) ' 0..10 x = step * 20 ' 0..200 in 20 px increments End If If t >= 100 Then s = 1 : t = 0

This produces a piecewise-constant motion of 10 distinct positions. For smoother visual motion, use the linear interpolation shown in the previous section; the choice depends on whether the application must mirror discrete PLC states (quantized) or represent a continuous process (smooth).

Advanced Patterns: Conditional Triggers and State Machines

Triggering a global action only when a condition is true is supported by gating the action body, as shown with oRun.Value. The same gate can be combined with the standard Upon change trigger on a binary tag, which is more efficient than running a 100 ms tick solely to inspect a flag:

' On-change action: Anim_Run rising edge starts the sequence If HMIRuntime.Tags("Anim_Run").Value Then HMIRuntime.Tags("Anim_Tick100ms").Write 0 HMIRuntime.Tags("Anim_State").Write 0 HMIRuntime.Tags("Anim_PosX").Write 0 End If

For projects that require many concurrent timed sequences, use a single multiplexed global action that maintains an array of states in a WinCC user archive or a structured tag (UDT). This avoids the 64-action soft cap that some legacy panels exhibit.

C-Script Alternative

WinCC V7 also supports ANSI-C global actions. They execute faster and avoid the COM overhead of HMIRuntime.Tags by using GetTagDWord, SetTagDWord, etc. A 100 ms C action equivalent is:

#include "apdefap.h" void User_Cycle_100ms(void) { DWORD tick = 0, state = 0; double x = 0.0; DWORD run = 0; GetTagDWord("Anim_Tick100ms", &tick); GetTagDWord("Anim_State", &state); GetTagDWord("Anim_Run", &run); GetTagFloat("Anim_PosX", &x); if (run) { tick += 1; if (state == 0 && tick <= 100) x = (tick/100.0)*200; if (state == 0 && tick > 100) { state = 1; tick = 0; } SetTagDWord("Anim_Tick100ms", tick); SetTagDWord("Anim_State", state); SetTagFloat("Anim_PosX", x); } }

For motion work, VBScript is the more common choice because of the easier debugging and integration with object property access. Use C only when the tick frequency is below 50 ms or when thousands of tags are processed per tick.

Diagnostics and Verification

  1. Open the picture with the bound object in Graphics Designer and start the runtime with File → Runtime → Start.
  2. Add a Input/Output field linked to Anim_Tick100ms to observe the counter visually. It should increment by 10 every second.
  3. Open the WinCC Tag Logging online view or use WinCC Diagnosis → Performance to confirm the action is firing at the configured cadence. A firing interval that drifts more than 5% indicates a system load issue.
  4. Force Anim_Run = 1 via the tag simulator. The shape must begin motion within one tick (100 ms).
  5. Use the Microsoft Script Debugger (WinCC option) to step through the action: enable it under Computer → Properties → Startup, then trigger a breakpoint inside the action.

Common Pitfalls

Symptom Likely Cause Resolution
Counter does not increment Action trigger set to Upon change on a tag that never changes Switch trigger to a defined user cycle (e.g., User_Cycle_100ms)
Counter resets unexpectedly Tag configured as Retain with initial value that overrides runtime Uncheck Retain for animation tags
Motion is choppy or one step behind Dynamic dialog in Trigger by mode with a 2 s default Change trigger type to Tag change on the float tag, or use Direct
Tag write returns "permission denied" Tag name mismatch or external tag without connection Verify tag exists in Internal Tags and is not PLC-side
Action does not run in runtime Global action has no trigger or wrong cycle selected Open the action and re-select the user cycle; recompile
Counter increments but object does not move Object property bound to a different tag or wrong property Inspect Properties → Geometry → Position X and re-link
Multiple actions conflict Two actions writing the same tag Consolidate into one multiplexed action

Performance and Retention Notes

Each global action adds roughly 0.3–0.6% CPU on a typical Core-i3 panel per 100 ms tick. Keep the body of high-frequency actions under 200 lines of VBScript. For projects with dozens of animated objects, prefer a single dispatcher action that updates an array of positions and let the runtime's tag-change evaluation push values to the bound properties.

Internal tags by default do not retain across runtime restart. To make a sequence resume from the last position, enable the Retain option in the Internal Tags dialog and ensure the UserArchive or TagLogging service is running. For most HMI animations, however, restart-from-zero is the correct behavior and Retain must remain disabled.

How many user-defined update cycles can I configure in WinCC V7?

WinCC V7 supports exactly five user-defined update cycles per project, in addition to the two fixed cycles (500 ms and Upon change). They are defined under Computer → Properties → Cycles and become selectable as triggers for any global action.

What is the difference between a WinCC internal timer and a STEP 7 PLC timer (TP/TON/TOF)?

A PLC timer runs deterministically in the controller scan cycle and survives HMI restart; a WinCC internal timer is a software construct inside the HMI runtime, triggered by a configured cycle, and resets when the runtime restarts unless the underlying tag has Retain enabled. Use PLC timers for process safety logic; use WinCC internal timers for visualization, animation, and non-safety housekeeping.

Can I trigger a global VBScript action only when a condition is true?

Yes. The recommended approach is to gate the action body with an If check on a binary tag such as Anim_Run, as shown in the reference implementation. For higher efficiency, bind the action to the Upon change trigger of that binary tag and run the initialization only on the rising edge.

Why is my counter incrementing but the object is not moving?

The dynamic link between the tag and the object is misconfigured. Open Object Properties → Geometry → Position X, right-click the value, choose Tag connection, and select Anim_PosX. Ensure Update on tag change is enabled. If you used Dynamic dialog, verify the expression type is Direct with the correct value range.

Is the VBScript pattern supported in TIA Portal WinCC Professional?

Yes. TIA Portal WinCC Professional (V16/V17/V18/V19) retains VBScript global actions and the user-defined cycle concept, although the UI has been renamed to Scheduled Tasks and the configuration moved to HMI Tags → System → Cycles. The internal-tag and trigger model described in this article applies without modification.

Back to blog