Compare (input instruction)

EXPR: Expression

A whole boolean expression in one contact, for conditions that would otherwise take a row of instructions.

Also called: boolean expression contact, compare expression.

EXPR(expression)

What it does

EXPR holds a written condition rather than a drawn one: EXPR(Tank_Level > 800 AND NOT Pump_Fault) is a single contact that passes power when that sentence is true. It understands comparisons, AND, OR, XOR and NOT, arithmetic, and brackets to group them.

It earns its place where the drawn form gets unwieldy. A condition that mixes arithmetic with logic, or one that needs brackets a straight line of contacts cannot express, is clearer as one expression than as a rung of six instructions and a branch.

It is worth being disciplined about, all the same. Contacts in series and in parallel are the thing you are learning to read, and they are the thing every other engineer on the site will expect. An expression collapses that into text, and while it is shorter, it is not ladder logic any more.

A rung you can run

One condition that would take a branch to draw

RUNG 1EXPRf(x)Tank_Level > 800 AND NOT Pump_FaultPump_RunRUNG 2EXPRf(x)Tank_Level < 200 OR Pump_FaultPump_Stop_Lamp
EXPR(Tank_Level > 800 AND NOT Pump_Fault)OTE(Pump_Run)
EXPR(Tank_Level < 200 OR Pump_Fault)OTE(Pump_Stop_Lamp)

Two expressions covering the high and low ends of the same tank, each mixing a comparison with a bit. Set Tank_Level from the tag panel and toggle Pump_Fault: the pump runs only above 800 with no fault, and the stop lamp comes on below 200 or on any fault at all.

Run this rung in the simulator

What it is called on other controllers

PlatformEquivalent
Rockwell (Studio 5000)CMP, which takes a whole expression
Siemens (TIA Portal)No LAD equivalent: the same thing is written as a condition in SCL
Mitsubishi (GX Works)No direct equivalent
CODESYS and IEC 61131-3An expression in structured text

Common mistakes

  • Reaching for it too early. If the condition can be drawn as contacts, draw it: a rung you can see is a rung you can troubleshoot, and hiding the logic in text is a habit that makes your programs harder for the next person.
  • Forgetting that you cannot watch inside it. Contacts light up individually while the program runs, so you can see which one is false. An expression is one contact and one answer, and when it is false it will not tell you which term let you down.

Practise it

Interactive exercises that use EXPR. Each one checks your ladder against a real scan.

Related instructions

All ladder logic instructions