Program Control
Flow & Execution
Master the logical flow of your program. From conditional jumps to real-time diagnostic tools, optimize the execution structure of your controller.
What are Program Control Operations in TIA Portal?
Program control operations allow modifying the sequential execution order of networks. They are used to bypass parts of the code (Jumps), create complex branching (Distributors), or manage the internal behavior of the CPU (Stop, Watchdog, Time measurement).
These instructions are powerful but must be used with caution, particularly the WAIT instruction which blocks the cycle, or jumps that can make the program hard to debug if too numerous. TIA Portal also offers modern tools to intercept errors locally in each block.
Jumps and Flow
Program rerouting instructions
JMP / JMPN — Conditional Jumps
JMPWhat it does
JMP interrupts sequential execution and jumps to a label (LABEL) if the RLO is 1. JMPN does the same if the RLO is 0.
When to use it
Bypass a section of code that should not execute in a specific mode, or create simple loops in LAD/FBD.
Pro Tips
The jump destination (LABEL) must be within the same block (FC or FB).
Do not use backward jumps to create loops without an exit condition, as you risk a cycle time overrun.
In SCL, use IF...THEN or CASE...OF structures instead.
SWITCH — Multi-case Distributor
SWITCHWhat it does
Compares an input value to several target values and jumps to the network corresponding to the first verified case. Graphical equivalent of Switch/Case.
When to use it
Managing machine states (simple Grafcet), selecting operating modes, or routing parts according to a type code.
Pro Tips
Cleaner and more readable than a series of == comparators in series.
Use the 'ELSE' input to handle cases where no value matches.
Ideal for menu structures on HMI.
RET — Return
RETWhat it does
Forces the end of execution of the current block (FC/FB) and returns to the calling block.
When to use it
Early termination of a function if an error is detected at the start of the block, or if a safety condition is not met.
Pro Tips
Useful for optimizing cycle time by not processing the rest of the code unnecessarily.
Be vigilant: block outputs not yet processed will keep their last state.
In SCL, use the RETURN; instruction.
Runtime Control
CPU cycle management and performance measurements
RUNTIME — Measure time
RUNTIMEWhat it does
Measures the execution time of a program portion or the entire block in microseconds (µs).
When to use it
Code optimization, diagnosing heavy networks, or machine performance calculations.
Pro Tips
Call RUNTIME once to initialize the measurement, then a second time to get the result.
Use the LReal data type to store the measurement result.
Handy for checking if a complex FOR loop is approaching watchdog limits.
WAIT — Fixed delay
WAITWhat it does
Suspends program execution for a specified duration in microseconds. WARNING: unlike a Timer, WAIT completely blocks the CPU cycle.
When to use it
Waiting a few microseconds to stabilize an electronic signal on an ultra-fast I/O card.
Pro Tips
Use with extreme moderation. A WAIT that is too long will trigger a Watchdog error and stop the PLC.
Never use for process delays (seconds/minutes); use TON Timers for that.
Only available on S7-1500.
STP — Stop CPU
STPWhat it does
Forces the CPU into STOP mode.
When to use it
Fatal error condition where the machine should no longer be controlled, or diagnostic test.
Pro Tips
Stop is immediate. Manual intervention (HMI or switch) will be required to restart.
Prefer alarm management with safe fallback rather than brutal CPU stop whenever possible.
Useful in commissioning projects to 'break' at a specific location.
Error Handling
Local interception of execution faults
GET_ERROR / GET_ERR_ID
What they do
Retrieve information about the first error that occurred inside a block (e.g., access to non-existent array index).
When to use it
Making your blocks robust by intercepting programming errors without stopping the PLC.
Pro Tips
GET_ERROR provides a detailed structure (ErrorStruct), GET_ERR_ID only returns the error number.
Place these instructions at the end of your critical blocks.
Allows creating a custom error log.
Jumps vs Control Structures
Which method to use for program rerouting?
| You need... | Recommended instruction | Why? |
|---|---|---|
| Simple jump in Ladder | JMP | Skip a network |
| Complex multiple choice | SWITCH / CASE | More readable than 10 JMP |
| Measure internal duration | RUNTIME | Performance optimization |
| Immediate stop | STP | Hardware critical error |
| Very short wait | WAIT | Electronic stabilization |
| Local diagnostic | GET_ERROR | Avoid CPU STOP |
Frequently Asked Questions
What is the difference between JMP and JMP_LIST?
JMP is a single jump to a target. JMP_LIST allows defining a list of destinations. Based on a numeric index, the program jumps to the 1st, 2nd, or Nth label in the list.
Is the WAIT instruction dangerous?
Yes, if misused. It suspends execution of the ENTIRE user program. If the sum of your WAITs and your code exceeds the watchdog time (often 150ms), the CPU will go to STOP.
How to measure the total cycle time of the PLC?
You don't need the RUNTIME instruction for that. You can read the information directly in the CPU properties online, or use the system variables of OB1.
Where to place LABEL labels?
LABELs can be placed at the start of any network. In LAD, they appear above the left rail. A label name must be unique within the block.