Skip to content

Programs and the Scan Cycle

Commercial

Included in the public demo Compare editions

A model can carry several PLC programs, with one PLC Program component per node. Like blocks in a real PLC, these can represent individual machine units. All programs scan in the same tick, one after another, as set by their Order field. An output written by two programs is reported as a conflict.

The Laser Welding Assembly Station is controlled this way: eleven programs under the node PLC_Programs — operating modes, transport, the two lifts, the buffer, the entry and the five stations.

What you doStartVariablesTimers and countersRV_FirstScan
DeployColdBack to their start valuesNew, with their start inputsTRUE in the first scan
Reset, or resetting the simulationColdBack to their start valuesBack to their start inputsTRUE in the first scan afterwards
Run after an errorColdBack to their start valuesNewTRUE in the first scan
Stop, then RunWarmKeep their valuesKeep their statestays FALSE

A variable without a start value begins with FALSE or 0; enums use their declared default, member valued 0, or first member as described above. RV_FirstScan is TRUE in exactly one scan after every cold start, so you can run set-up code once:

PROGRAM Main
VAR_EXTERNAL
RV_FirstScan : BOOL;
PartPresent : BOOL; (* @signal: SensorInFeed *)
Conveyor : BOOL; (* @signal: ConveyorStart *)
BatchFull : BOOL; (* @signal: SignalTower_Yellow *)
END_VAR
VAR CONSTANT
BATCH : INT := 10; (* parts per batch *)
END_VAR
VAR
starts : INT := 0; (* counts cold starts *)
parts : INT := 0;
hold : TON := (PT := T#2s); (* start value for the input PT *)
edge : R_TRIG;
END_VAR
IF RV_FirstScan THEN starts := starts + 1; END_IF;
edge(CLK := PartPresent);
IF edge.Q THEN parts := parts + 1; END_IF;
hold(IN := parts >= BATCH); (* PT keeps its start value of 2 s *)
BatchFull := hold.Q;
Conveyor := NOT BatchFull;
END_PROGRAM

RV_FirstScan is not a signal. Declare it in VAR_EXTERNAL like RV_SimulationMode; writing to it stops the deploy with an error. The watch list shows the start inputs of timers and counters as well, for example hold.PT.

Resetting the simulation resets every program’s timers, counters and memory. It also restores ordinary outputs to their captured start values. GVL signals use their declaration values; later library initializer edits take effect on the next Reset.

If a scan runs too long (more than 200 ms, for example an endless loop), uses too much memory or hits an error such as a division by zero, the PLC stops with the status error. Fix the program and click Run again; the PLC restarts with fresh values.