Learn PLCs free
Comparison OperationsBeginnerIEC 61131-3

PLC Not Equal (NE/NEQ): Ladder and ST Examples

A PLC not-equal comparison returns TRUE when two compatible operands have different values at the moment the instruction executes. In Structured Text the operator is usually <>. Siemens uses CMP <>, while current Studio 5000 documentation uses NE (formerly NEQ). It detects a mismatch—not a change over time unless the program stores a previous value.

The NE not-equal comparison returns TRUE when two compatible operands have different values at the execution of the instruction. It is the logical complement of an exact EQ comparison. NE can expose a current mismatch, but it is not a change detector unless the program stores and compares a previous value. Use a documented tolerance rather than exact inequality for noisy REAL or LREAL process values.

Parameters

Inputs

NameTypeDescription
IN1ANYFirst value
IN2ANYSecond value

Outputs

NameTypeDescription
OUTBOOLTRUE when IN1 <> IN2

How PLC not-equal comparison works scan by scan

Read the waveforms and state table together. The diagram shows the sequence; the table states what the program should observe at each execution.

Not-equal comparison across four task executions

Operand A changes before operand B, then both match; the pattern repeats in the opposite direction. The Boolean result is TRUE only during the two mismatch intervals.

Not-equal comparison across four task executionsOperand A changes before operand B, then both match; the pattern repeats in the opposite direction. The Boolean result is TRUE only during the two mismatch intervals.ABA <> Bunequalequalunequalequal
Blue and green are the two operands; amber is the not-equal result. The result changes when the instruction executes, not continuously between task executions.

State table

MomentInputInternal stateOutputEngineering meaning
Values matchA = 5; B = 5Same type and valueA <> B = FALSENo mismatch exists at this execution. Downstream alarm or permissive logic remains false.
First mismatchA = 6; B = 5Comparison evaluates unequalA <> B = TRUEThe rung or expression reports a mismatch immediately when it executes.
Values match againA = 6; B = 6Same type and valueA <> B = FALSEThe comparison is level-sensitive; it does not latch the earlier mismatch.
Second mismatchA = 5; B = 6Comparison evaluates unequalA <> B = TRUEOperand order does not change the Boolean result for exact inequality.

Ladder and Structured Text examples

Block a batch start when recipe IDs do not match

|----[ NE  ActiveRecipeID  RequestedRecipeID ]----( RecipeMismatch )----|
|----[ StartPB ]----[/RecipeMismatch]----[ OtherPermissives ]----( StartBatch )----|

This is an exact integer comparison. Keep RecipeMismatch visible for diagnostics, and make the start permissive depend on the comparison result. Do not use a raw REAL not-equal check for noisy process values.

Exact mismatch and tolerance-based analog deviation

RecipeMismatch := ActiveRecipeID <> RequestedRecipeID;

PositionDeviation := ABS(CommandedPosition - ActualPosition);
PositionOutOfTolerance := PositionDeviation > PositionTolerance;

Use <> for exact discrete values such as IDs, modes and enumerations. For measured REAL/LREAL values, compare the absolute difference with an engineering tolerance so normal representation error and noise do not create chatter.

Vendor compatibility

A shared mnemonic does not guarantee an identical interface or state machine. Confirm the instruction help for the controller, firmware, language and library version used on the project.

PlatformInstructionWhat maps cleanlyCaveat to verify
Siemens S7-1200/1500CMP <> in LAD/FBD; <> in SCLReturns an RLO of 1 when the two selected operands compare unequalOperand compatibility depends on IEC Check and data type. Siemens recommends a range test for REAL/LREAL and documents special behavior for NaN, strings, dates and structures.
Rockwell Studio 5000NE; legacy mnemonic NEQ; <> in expressionsTests Source A against Source B and produces true when the values differRockwell changed the Logix mnemonic from NEQ to NE in version 36. Language and controller availability, data conversion and floating-point behavior remain platform-specific.
CODESYS V3NE operator box; <> in Structured TextProduces a BOOL comparison result for supported, compatible operandsCODESYS Static Analysis flags equality and inequality comparisons on REAL/LREAL because apparently equal decimal results can have different binary representations.

Failure modes and edge cases to test

Used as a change detector without previous-state memory

A <> B only reports the current mismatch. To detect a change, compare CurrentValue with a stored PreviousValue, act once, then update PreviousValue deliberately.

Two REAL values look identical online

The displayed decimals can hide different binary values. Compare ABS(A - B) with a documented tolerance instead of testing A <> B directly.

Mixed data types or implicit conversions

The editor may reject the comparison or convert one operand. Make the conversion explicit and prove range, signedness and precision at the boundary.

NaN or invalid date/time data reaches the comparison

Results are vendor-specific and can differ from ordinary inequality intuition. Validate the input first and test the exact controller instruction.

Mismatch drives a safety function

A standard comparison is ordinary control logic. A safety function requires the appropriate risk assessment, safety-rated architecture, instructions and validation.

Verification checklist

  1. 1Test equal values, A greater than B and A less than B.
  2. 2Test the minimum, maximum and signed range of every integer operand.
  3. 3Verify explicit conversions at mixed-type interfaces.
  4. 4Test REAL/LREAL logic just inside, on and just outside the allowed tolerance.
  5. 5Trend both operands and the Boolean result on the same task time base.
  6. 6Confirm restart, invalid-value and alarm-latching behavior in the target controller.

Current primary and technical sources

These sources support the behavior summarized here. The exact controller, firmware, instruction and installed-library help remain authoritative for implementation.

Platform-Specific Implementation

S

Siemens (TIA Portal)

Use CMP <> in LAD/FBD or <> in SCL. Confirm operand types and special-value behavior; use a range or tolerance for REAL/LREAL values.

AB

Allen-Bradley (Studio 5000)

Current Studio 5000 documentation uses NE; the legacy mnemonic is NEQ. The <> operator is available in expressions.

C

CODESYS

Use the NE operator box or <> in Structured Text. Static Analysis flags exact REAL/LREAL equality and inequality comparisons.

Common Applications

  • Recipe or mode mismatch detection
  • Command and feedback diagnostics
  • Discrete state validation
  • Previous-value change detection when paired with stored state

Frequently Asked Questions

What is NE (Not Equal) in PLC programming?

Returns TRUE when two compatible operands compare unequal at execution. The NE not-equal comparison returns TRUE when two compatible operands have different values at the execution of the instruction. It is the logical complement of an exact EQ comparison.

What are common applications of NE (Not Equal)?

NE (Not Equal) is commonly used for: Recipe or mode mismatch detection, Command and feedback diagnostics, Discrete state validation, Previous-value change detection when paired with stored state.

How do I use NE (Not Equal) in different PLC platforms?

Siemens: Use CMP <> in LAD/FBD or <> in SCL. Confirm operand types and special-value behavior; use a range or tolerance for REAL/LREAL values. Allen-Bradley: Current Studio 5000 documentation uses NE; the legacy mnemonic is NEQ. The <> operator is available in expressions. CODESYS: Use the NE operator box or <> in Structured Text. Static Analysis flags exact REAL/LREAL equality and inequality comparisons.

Free PLC simulator

Wire this block up and run it

Drop the instruction into a rung, hit Run, and watch it execute in your browser. 12 guided lessons across 8 PLC dialects — free account, no credit card.

Practice PLCs free →