How-to
Why a WinCC Unified live bit needs two scheduled tasks
Short answer
A live bit pair proves the partner's code is executing, not just that the link is up: each side increments an integer counter and the partner checks it changed within a window at least twice the increment period, for example 1 s increments against a 2 s or longer evaluation. In WinCC Unified the HMI half is two time-triggered scheduled tasks, one to increment and one to evaluate.
On this page
A live bit pair gives each side proof that its partner's program is still executing, which a connection status flag cannot: the transport can be up while the far-side block is no longer called. The scheme is one integer counter per direction. The sender increments its counter; the receiver compares it against the value stored one window earlier and sets an OK bit on change. In the PLC this fits a single block; in WinCC Unified the HMI side is two separate time-triggered scheduled tasks, one to increment and one to evaluate, so each period stays independently adjustable. The evaluation window must be at least twice the increment period, or a healthy partner reads as failed.
The HMI-watching-PLC half through a script and alarm is covered in the live article on monitoring a PLC lifebit heartbeat in WinCC with an alarm; this article builds both directions with the Unified scheduled-task mechanism.
Why a changing integer proves execution #
A static bit proves nothing, because the last written value persists in the PLC memory or the HMI tag cache after the writer dies. A value that must change on a schedule can only come from code that is executing. The receiver does not care what the counter's value is, only that the current value differs from the one sampled one window earlier. Comparing for inequality also makes the scheme rollover-proof: a counter that wraps from its maximum back to its minimum still counts as a change.
The receiver's watchdog is a sampled comparison: at each evaluation tick, compare the counter against the stored previous value, then store the current value, and assign the OK bit both ways every tick. Setting it on change but never clearing it hides a stalled partner.
The timing rule for the window #
Three timings interact: the sender's increment period, the tag acquisition cycle of the transport, and the receiver's evaluation period. The rule: the evaluation period must be at least twice the increment period, then confirmed against the measured tag update time under load.
Worked example. Increment period 1 s, tag acquisition cycle 1 s, evaluation period 2 s. Worst case, an increment lands just after an evaluation samples the counter, and the tag update costs up to its full 1 s cycle, so the change is visible to the next evaluation 2 s later: the counter differs at every second evaluation at worst, and the OK bit never drops. If you set the evaluation to 1 s with the same chain, a 2 s worst-case arrival means one evaluation can sample an unchanged counter and clear the OK bit on a healthy partner. That is the flicker row in the table below, and doubling the window removes it.
Do not evaluate every scan in the PLC. A scan of a few milliseconds against a 1 s increment period would report a stall on every scan between increments; put the comparison in the cyclic block on a timer basis at your chosen window.
Failure patterns and what each one means #
| Observed pattern | Likely cause | Discriminating check |
|---|---|---|
| Connection good, OK bit FALSE | Partner block not running: hung runtime, disabled task, block not called, CPU in STOP | Watch the counter; a frozen value means the sender stopped |
| Connection and OK bit drop together | Network, cable, switch or connection configuration fault | Read the connection diagnostic in the engineering tool |
| OK bit flickers | Window shorter than increment period plus tag transfer delay | Compare the window against the increment period and acquisition cycle |
| Counter changes, OK bit never sets | Wrong tag compared, or compared in the wrong direction | Trace which tag the receiver reads versus which the sender writes |
| OK bit TRUE with the CPU stopped | Counter written by a context that survives the application, or the bit is not cleared | Force STOP and confirm the OK bit falls within the window |
Building both directions #
Names below are example names; use your own tag naming. Declare PLC_LiveCounter and HMI_LiveCounter as integers, initial value 0, one written by each side. Declare PLC_Alive_OK (evaluated in the HMI) and HMI_Alive_OK (evaluated in the PLC) as booleans, initial value FALSE.
- Create the two integer counters on the PLC connection and expose both to the HMI.
- In the PLC, build one block called from the same cyclic context whose health you want to prove. It increments
PLC_LiveCounterand, on a timer at the evaluation period, comparesHMI_LiveCounterwith a stored previous value, then assignsHMI_Alive_OKTRUE on inequality and FALSE on equality. - In WinCC Unified, open the Scheduler, add a task and select the required cycle as its trigger (the documented example of the cycle naming is
T250msfor 250 ms; for this plan pick a 1 s cycle). Give it a script that incrementsHMI_LiveCounter. - Add a second time-triggered task at the evaluation period (2 s in the example) with a script that compares
PLC_LiveCounterwith its previous value and assignsPLC_Alive_OKboth ways, then stores the current value. - Drive an alarm, a screen indicator and any interlock that should degrade when the partner is lost from the OK bits.
The evaluation script logic, with prev a script-internal integer initialised to 0:
// runs in the 2 s evaluation task
if (Tags("PLC_LiveCounter").Read() !== prev) {
Tags("PLC_Alive_OK").Write(true);
} else {
Tags("PLC_Alive_OK").Write(false);
}
prev = Tags("PLC_LiveCounter").Read();
The function names above are illustrative; use the read and write calls your Unified scripting reference documents. Two tasks rather than one keep each direction's logic separate and each period independently adjustable, which is why the sample splits them.
Increment the counter from the same logic whose health you want to prove, never from an independent background context: a heartbeat written by something that survives an application hang reports health you do not have.
Bench verification with expected readings #
Run these on an isolated bench before deployment:
- Both systems running: each counter changes at its 1 s period, both OK bits TRUE.
- Disable the HMI increment task:
HMI_Alive_OKin the PLC goes FALSE within the 2 s window, whilePLC_Alive_OKstays TRUE. - Re-enable the task: the OK bit returns TRUE on the first evaluation after the counter moves again.
- Remove the call to the PLC live bit block:
PLC_Alive_OKin the HMI goes FALSE within its window and the tied alarm activates. - Pull the network cable with both programs running: both OK bits go FALSE and the connection diagnostic reports the fault too.
- Restore the link: both OK bits return TRUE without operator action.
- Preset a counter near its maximum and let it wrap: the OK bit stays TRUE across the rollover.
The counter does not report RUN or STOP #
Read the CPU operating mode through its own diagnostic path rather than inferring it from the counter: a stopped CPU does stop the counter, but counter loss alone cannot tell you whether the cause is STOP, a hung block or a broken link. Combine the mode diagnostic with the live bit when the distinction matters.
One safety note: the live bit is monitoring logic in ordinary program code, not a safety function. When a lost partner must drive the machine to a defined state, that action belongs in the interlock or safety design, with the OK bit as one input to it.
Questions asked
Why compare the counter for inequality instead of checking that it grew?
A counter that wraps from its maximum back to its minimum is still a change produced by running code. A greater-than test reads that wrap as a stall and drops the OK bit on a healthy partner. Comparing current value against the stored previous value for inequality survives rollover with no extra logic.
Can I put the evaluation in a screen script instead of a scheduled task?
No. A script on a screen runs only while that screen is open, so the OK bit freezes the moment the operator changes pages, and the PLC sees a false stall. A time-triggered scheduled task in the Scheduler runs independently of which screen is displayed, which is what monitoring requires.
How do I set the cycle of a time-triggered task?
In the Scheduler, add the task and select the required cycle as its trigger; the documented example is T250ms for a 250 ms cycle. Pick the cycle that matches your timing plan: the increment task gets the increment period, the evaluation task gets a window at least twice as long.
Is a lost live bit a safety signal?
No. The live bit is monitoring logic implemented in ordinary program code, and it carries no diagnostics or redundancy. When the partner's absence must put the machine into a defined state, that action belongs in the interlock or safety design, with the live bit as one input to it, not as the protective function itself.