LadderLogicOnline

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_ClosedStart_PBPress
000
010
100
111

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_OpenWindow_OpenAlarm
000
011
101
111

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 |
 |------] [-----------]/[-------------------( )-------|
Fill while requested AND NOT at high level.

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                |
 |----] [--+------] [------+                        |
(Auto AND Part_Present) OR (Manual AND Clamp_PB), and in every case NOT 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     |                              |
 |----]/[--+----] [--+                              |
XOR built from contacts: true when exactly one of A and B is on.

Try it in the Playground

  1. Open the Playground and add BOOL tags A, B and Out.
  2. Build an AND rung: XIC A, XIC B, OTE Out. Run it and click A and B in the tag list to fill in the truth table yourself.
  3. Stop, select XIC A, press B to add a branch around it, and move XIC B onto the branch. Now it's OR. Run it again.
  4. Double-click one contact and type XIO to see how NOT changes the results.

Key points