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
| Name | Type | Description |
|---|---|---|
| IN1 | ANY | First value |
| IN2 | ANY | Second value |
Outputs
| Name | Type | Description |
|---|---|---|
| OUT | BOOL | TRUE 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.
State table
| Moment | Input | Internal state | Output | Engineering meaning |
|---|---|---|---|---|
| Values match | A = 5; B = 5 | Same type and value | A <> B = FALSE | No mismatch exists at this execution. Downstream alarm or permissive logic remains false. |
| First mismatch | A = 6; B = 5 | Comparison evaluates unequal | A <> B = TRUE | The rung or expression reports a mismatch immediately when it executes. |
| Values match again | A = 6; B = 6 | Same type and value | A <> B = FALSE | The comparison is level-sensitive; it does not latch the earlier mismatch. |
| Second mismatch | A = 5; B = 6 | Comparison evaluates unequal | A <> B = TRUE | Operand 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.
| Platform | Instruction | What maps cleanly | Caveat to verify |
|---|---|---|---|
| Siemens S7-1200/1500 | CMP <> in LAD/FBD; <> in SCL | Returns an RLO of 1 when the two selected operands compare unequal | Operand 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 5000 | NE; legacy mnemonic NEQ; <> in expressions | Tests Source A against Source B and produces true when the values differ | Rockwell 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 V3 | NE operator box; <> in Structured Text | Produces a BOOL comparison result for supported, compatible operands | CODESYS 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
- 1Test equal values, A greater than B and A less than B.
- 2Test the minimum, maximum and signed range of every integer operand.
- 3Verify explicit conversions at mixed-type interfaces.
- 4Test REAL/LREAL logic just inside, on and just outside the allowed tolerance.
- 5Trend both operands and the Boolean result on the same task time base.
- 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.
- CMP <>: Not equal, STEP 7 V20
Siemens — Operand rules, RLO behavior, floating-point caveats and supported data types
- Not Equal To (NE), Logix Designer V38
Rockwell Automation — Current NE instruction, <> expression and the version-36 mnemonic change
- Operator: NE
CODESYS — CODESYS not-equal operator and supported IEC data types
- SA0054: REAL/LREAL equality and inequality
CODESYS Static Analysis — Why direct floating-point equality and inequality checks are flagged
- IEC 61131-3:2025 publication record
IEC — Current programmable-controller language standard record
Continue with the practical guide
Platform-Specific Implementation
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.
Allen-Bradley (Studio 5000)
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.
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.
Related Function Blocks
EQ (Equal)
Returns TRUE when both inputs are exactly equal.
View Reference →GT (Greater Than)
Returns TRUE when first input is strictly greater than second input.
View Reference →LT (Less Than)
Returns TRUE when first input is strictly less than second input.
View Reference →GE (Greater Than or Equal)
Returns TRUE when first input is greater than or equal to second input.
View Reference →LE (Less Than or Equal)
Returns TRUE when first input is less than or equal to second input.
View Reference →