Learn › Getting started
AND, OR and NOT in ladder logic
Every on/off decision a PLC makes is built from three ideas: AND, OR and NOT. In ladder logic they aren't keywords, they're shapes: contacts in series, contacts in parallel, and the XIO contact.
AND: contacts in series
Place two contacts one after the other on the same rung and power has to pass through both to reach the output. The rung is true only when the first condition AND the second condition are true.
| Guard_Closed Start_PB Press |
|------] [-----------] [-------------------( )----|
Press runs only when the guard is closed AND the start button is pressed.Guard_Closed | Start_PB | Press |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
You can chain as many contacts in series as you need. Each one is another condition that must be met. Safety-style permissives often look like this: a long row of "this must be OK" contacts in front of a single output.
OR: parallel branches
Put two contacts on parallel branches and power can take either path. The rung is true when the first condition OR the second (or both) is true.
| Door_Open Alarm |
|------] [------+--------------------------( )----|
| Window_Open | |
|------] [------+ |
Alarm turns on if the door is open OR the window is open.Door_Open | Window_Open | Alarm |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
In the Playground, select an instruction and choose Branch (or press B) to add an empty branch after it, or drag the Branch tool onto the left half of an instruction to put it before. Drop instructions onto the new branch, and drag either end of the branch to change where it starts and joins back. Level (L) adds another level to an existing branch when you need three or more alternatives.
NOT: the XIO contact
An XIO contact, drawn ]/[, passes power when its bit is off. That's NOT. Use it whenever a condition reads "and not this": run the conveyor and not when it's full, open the valve and not if the tank is at high level.
| Run_Request Tank_High Fill_Valve |
|------] [-----------]/[-------------------( )-------|
There's no separate NOT instruction for bits, and you don't need one. Any contact can be inverted by swapping XIC for XIO. In the Playground you can double-click an XIC and type XIO over it to change it in place.
Combining them
Real rungs mix all three. Branches can sit anywhere along a rung, not just at the start, and a branch can contain several contacts in series. Read a rung by following every path from the left rail to the output: the rung is true if at least one complete path has every contact passing power.
| Auto Part_Present Clamp |
|----] [--+------] [------+----]/[---------( )----|
| Manual | Clamp_PB | Fault |
|----] [--+------] [------+ |
Here the branch covers two contacts on each path, and the XIO Fault after the join applies to both paths. Moving that XIO onto just one branch would change the meaning completely: a fault would only block one mode. When a condition must apply to everything, put it in series outside the branch.
Exclusive OR
Sometimes you need "one or the other, but not both", for example a two-position selector that should never report both positions at once. Build it from the pieces you already have: one branch with XIC A and XIO B in series, and a parallel branch with XIO A and XIC B.
| A B One_Only |
|----] [--+----]/[--+----------------------( )-----|
| A | B | |
|----]/[--+----] [--+ |
Try it in the Playground
- Open the Playground and add BOOL tags
A,BandOut. - Build an AND rung:
XIC A,XIC B,OTE Out. Run it and clickAandBin the tag list to fill in the truth table yourself. - Stop, select
XIC A, press B to add a branch around it, and moveXIC Bonto the branch. Now it's OR. Run it again. - Double-click one contact and type
XIOto see how NOT changes the results.
Key points
- Series contacts are AND: every one must pass power.
- Parallel branches are OR: any one complete path is enough.
- XIO is NOT: it passes power when its bit is off.
- Conditions that must apply to every path belong in series outside the branch.
- Read a rung by tracing each path from the left rail to the output.