Ladder logic (LAD) in TIA Portal
LAD is Siemens’ name for ladder logic, the contact-based language. In the international standard IEC 61131-3 it is called LD (Ladder Diagram), and in German-speaking countries KOP (Kontaktplan). It is the most widely used language on machines because it looks like an electrical schematic: any technician who can read schematics can follow a ladder program, which makes troubleshooting on the plant floor much easier. This topic explains its basic instructions as they are used in TIA Portal with the S7-1200 and S7-1500.
How to read a network
A ladder program is divided into networks (also called rungs). Each network starts at a vertical bar on the left, which represents the “power supply”, and ends in one or more output instructions, such as a coil. You read it like a circuit: if there is a path that “conducts” from the bar to the coil, the coil is energised. The result of evaluating the path is called the RLO (result of logic operation).
Remember what you saw in the scan cycle: networks are executed from top to bottom and each network from left to right, once per scan.
Contacts
- Normally open contact
-| |-: “conducts” if its operand is 1. - Normally closed contact
-|/|-: “conducts” if its operand is 0.
Contacts in series make an AND function; contacts in parallel, an OR function. It is the same old Boolean logic, drawn.
Coils
- Coil
-( )-: writes the RLO to its operand every scan: 1 if power arrives, 0 if not. - Negated coil
-(/)-: writes the opposite value. - Set
-(S)-: sets the operand to 1 when power arrives, and leaves it alone when it does not. - Reset
-(R)-: sets the operand to 0 when power arrives, and leaves it alone when it does not.
With S and R, the value is stored between scans. If an S and an R on the same operand both run in the same scan, the last one executed wins, as with the double coil.
SR and RS flip-flops
TIA Portal also has flip-flops as a single instruction, where the priority is clear:
- SR: if both inputs are 1, the reset wins (input R1).
- RS: if both inputs are 1, the set wins (input S1).
For a motor it is usually preferable for stop to have priority, that is, a reset-dominant flip-flop: if start and stop are pressed at the same time, the motor does not start.
Edges
A positive edge contact -|P|- conducts only in the scan in which its operand goes from 0 to 1; the
negative edge contact -|N|-, in the scan in which it goes from 1 to 0. Each one needs its own memory
bit to remember the previous state. There are also the R_TRIG and F_TRIG instructions, which store that state in
their own instance data block.
IEC timers
Timers have an input IN, a preset time PT (for example T#5s), an output Q and the
elapsed time ET. Each timer needs its own instance (a data block where it stores its state). The three most
used:
- TON, on-delay: Q turns on when IN has been at 1 for the time PT. If IN drops earlier, it resets and Q does not turn on. Typical use: waiting for a signal to be stable, or allowing some time before moving on.
- TOF, off-delay: Q turns on as soon as IN goes to 1 and stays on for PT after IN drops. Typical use: keeping a fan running for a while after a machine stops.
- TP, pulse: when IN goes to 1, Q gives a pulse lasting PT, whether IN lasts longer or shorter. Typical use: switching a blow-off solenoid valve on for a fixed time.
- TONR: like TON, but it accumulates time even if IN is interrupted, until it is reset. It is used, for example, to count running hours.
IEC counters
- CTU (count up): adds 1 on each rising edge of CU. Q turns on when the current value CV reaches the preset value PV. Input R resets it to zero.
- CTD (count down): subtracts on each edge of CD; Q turns on when it reaches 0 or less.
- CTUD: counts in both directions, for example parts entering and leaving a buffer.
Counters count edges, not levels: even if CU stays at 1 for many scans, it only adds one.
Compare, move and calculate
- Comparators (
==,<>,>,<,>=,<=): they are placed like a contact, which conducts if the comparison is true. For example, “temperature > 80.0”. - MOVE: copies a value from one variable to another.
- Maths operations (ADD, SUB, MUL, DIV) and conversions between types.
Tags, addresses and data types
Every signal has an address: %I0.0 is bit 0 of input byte 0, %Q4.1 bit 1 of output byte 4,
and %M10.0 an internal memory bit. In TIA Portal you do not program with bare addresses, but with named
tags, defined in the PLC tag table: "Start" instead of %I0.1. The program is much easier
to understand and, if a terminal changes, only the address in the table needs changing.
| Type | What it stores | Example |
|---|---|---|
| Bool | One bit: 0 or 1 | State of a sensor |
| Int | 16-bit integer, from −32768 to 32767 | Raw value of an analog input |
| DInt | 32-bit integer | Large part counter |
| Real | Number with decimals | Temperature in °C |
| Time | Duration | T#2s500ms |
Blocks
- OB (organisation block): called by the operating system. OB1 is the cyclic program.
- FC (function): reusable code with no memory of its own between calls.
- FB (function block): reusable code with its own memory, stored in an instance DB. For example, a “Motor” FB called once for each motor, each with its own instance.
- DB (data block): stores data. Global DBs can be read from anywhere in the program.
Typical mistakes in LAD
- Writing the same output with two coils in different networks.
- Using a normally closed contact for a stop that is already wired normally closed.
- Using the same instance for two different timers.
- Counting on a level instead of an edge, or using an addition instead of a counter.
- Scattering S and R of the same variable all over the program, until nobody knows what turns it on.
- Networks with no title or comment, and tags with names like
M10_3.
Summary
- LAD reads like a schematic: series is AND, parallel is OR, and the coil receives the result.
- A normally open contact conducts with 1; a normally closed contact conducts with 0. The program contact is not the physical contact.
- Normal coil: writes every scan. S and R latch; if both run, the last one executed wins.
- SR gives priority to reset; RS, to set.
- TON delays switching on, TOF delays switching off and TP gives a fixed-length pulse.
- Counters count edges. Each timer and counter needs its own instance.
Test what you have learned
43 practical questions with explained answers. Free, no sign-up.
Start the test