In RSLogix 5000, comparison instructions are used to compare two values and make decisions in a PLC program. They help control program flow by checking whether a certain condition is true or false. These instructions are essential in ladder logic when working with numerical values, sensor readings, counters, timers, and process limits.
Comparison instructions in RSLogix 5000 are essential tools for decision-making in PLC programs. They allow you to evaluate process values, machine states, and sensor readings to trigger specific actions based on defined conditions.
In this article, we will cover the following RSLogix 5000 comparison instructions:
We will not cover the LIM (Limit Test) instruction in this article, as it will be discussed separately.
By understanding these comparison instructions, you can create more intelligent and flexible PLC programs in Allen Bradley ControlLogix and CompactLogix systems.
The CMP instruction in RSLogix 5000 is used to evaluate complex comparison expressions within a single instruction. You can define the CMP expression using operators, tags, and immediate values. Parentheses ( )
can be used to group parts of the expression for proper evaluation order in more complex logic.
One key advantage of the CMP instruction is that it allows you to perform multiple comparisons and calculations together, without breaking them into multiple rungs or instructions. This makes the logic more compact and easier to read.
When evaluating a CMP expression, all non-REAL operands will be automatically converted to REAL if any of the following conditions is true:
In simple terms, the CMP instruction processes an expression consisting of tags and/or immediate values separated by mathematical or comparison operators, and returns a result that can be used to control the program flow.
Example 1 – Simple Comparison:
CMP MotorSpeed > MaxSpeed
Checks if the current motor speed is greater than the maximum allowed speed.
Example 2 – Average Calculation:
CMP ((Temp1 + Temp2) / 2) > Setpoint
Calculates the average of two temperature readings and checks if it exceeds a setpoint.
Example 3 – Mixed Operations:
CMP (Pressure * 1.5) <= SafeLimit
Multiplies the pressure value by 1.5 and verifies if it is less than or equal to the safe operating limit.
The EQU instruction in RSLogix 5000 checks whether two values are exactly equal. It is commonly used to trigger actions when a specific value, count, or measurement matches a defined target. If both operands are equal, the EQU instruction returns TRUE, otherwise it returns FALSE. This instruction works with integers, floating-point numbers, and other numerical data types.
Example 1 – Counter Check:
EQU Counter.ACC 100
Activates an output when the accumulated count in Counter
is exactly 100.
Example 2 – Sensor Match:
EQU SensorValue TargetValue
Turns on an alarm when a sensor reading exactly matches the set target value.
Example 3 – Mode Selection:
EQU Mode 3
Executes specific logic when the Mode
tag is set to 3.
The GEQ instruction in RSLogix 5000 checks if the first value is greater than or equal to the second value. It is useful for starting or stopping operations when a process variable reaches or exceeds a certain threshold. If the first value is greater than or equal to the second, the instruction returns TRUE; otherwise, it returns FALSE.
Example 1 – Tank Level Check:
GEQ TankLevel 80
Triggers a pump shutdown when the tank level reaches or exceeds 80%.
Example 2 – Temperature Control:
GEQ TempReading HighLimit
Activates a cooling fan if the temperature is at or above the high limit.
Example 3 – Production Count:
GEQ ProductionCount TargetCount
Signals batch completion when production count meets or exceeds the target count.
The GRT instruction in RSLogix 5000 checks if the first value is strictly greater than the second value. It is often used for process control, monitoring, and safety interlocks where action is required only when a value exceeds a specific limit. If the first value is greater, the instruction returns TRUE; otherwise, it returns FALSE.
Example 1 – Pressure Safety:
GRT PressureValue MaxPressure
Triggers an alarm when the pressure exceeds the maximum safe limit.
Example 2 – Motor Load Monitoring:
GRT MotorLoad 75
Stops the motor if the load goes above 75% capacity.
Example 3 – Speed Check:
GRT ConveyorSpeed RequiredSpeed
Signals a warning if the conveyor runs faster than the required speed.
The LEQ instruction in RSLogix 5000 checks if the first value is less than or equal to the second value. It is commonly used for maintaining safe operating ranges, process control, and triggering actions when a value drops to or below a specific limit. If the first value is less than or equal to the second, the instruction returns TRUE; otherwise, it returns FALSE.
Example 1 – Low Temperature Alarm:
LEQ TempReading MinTemp
Activates a heater when the temperature is at or below the minimum limit.
Example 2 – Material Stock Monitoring:
LEQ StockLevel ReorderLevel
Generates a reorder alert when stock level is less than or equal to the reorder point.
Example 3 – Flow Rate Check:
LEQ FlowRate SafeFlow
Stops a process if the flow rate drops to or below the safe minimum.
The LES instruction in RSLogix 5000 checks if the first value is strictly less than the second value. It is useful for activating processes, alarms, or control actions only when a value falls below a specific limit. If the first value is less than the second, the instruction returns TRUE; otherwise, it returns FALSE.
Example 1 – Low Pressure Warning:
LES PressureValue MinPressure
Triggers a warning when the pressure is lower than the minimum safe limit.
Example 2 – Temperature Control:
LES TempReading TargetTemp
Turns on a heater if the temperature is below the target temperature.
Example 3 – Speed Monitoring:
LES MotorSpeed SafeSpeed
Activates an alert if motor speed falls below the safe operating speed.
The MEQ instruction in RSLogix 5000 compares specific bits of two values using a mask. The mask determines which bits are considered in the comparison, allowing selective bit checking instead of comparing the entire value. The instruction returns TRUE if all the masked bits are equal; otherwise, it returns FALSE. This is especially useful in digital input status checks and communication data verification.
Example 1 – Digital Input Status Check:
MEQ InputWord ReferenceWord Mask
Verifies that specific input bits match the reference pattern defined by the mask.
Example 2 – Machine State Verification:
MEQ MachineStatus RequiredStatus 16#0F
Checks if the lower 4 bits of MachineStatus
match RequiredStatus
.
Example 3 – Communication Data Validation:
MEQ DataFromPLC ExpectedData 16#FF00
Confirms that only the high byte of incoming data matches the expected pattern.
The NEQ instruction in RSLogix 5000 checks if two values are not equal. It is often used to detect changes, mismatches, or abnormal conditions in process values, counters, or sensor readings. If the two values are different, the instruction returns TRUE; otherwise, it returns FALSE.
Example 1 – Sensor Fault Detection:
NEQ SensorReading ExpectedValue
Triggers an alarm if the sensor reading is different from the expected value.
Example 2 – Mode Change Detection:
NEQ CurrentMode PreviousMode
Executes logic when the machine mode changes from its last known state.
Example 3 – Product Mismatch:
NEQ ProductCode ScannedCode
Stops the conveyor if the scanned product code does not match the expected code.