Back to tutorials

PLC Programming Comparison Instructions – MEQ | Masked Equal

Vladimir Romanov
September 24, 2018
Table of Contents


The MEQ, also known as the Masked Equals, is an instruction which will perform a similar function to the EQU (Equals) Instruction, with one key difference: a mask is applied to the compared bits. This instruction will take three operands: two which will be compared and a mask which needs to be applied. A mask is a key element of programming which boils down to selecting which bits need to be processed by the controller. In the case of the MEQ instruction, only the bits which have been masked as HIGH will be compared. Should those bits be the same within the two other operands, the instruction will evaluate to TRUE.

Although a masked comparison is not something you see on a regular basis in production ready code, it’s a great tool for certain situation. However, it must be used carefully as it is confusing to troubleshoot what’s going on unless you are familiar with this type of code. Use the MEQ instruction with caution.

Example & Usage of MEQ

Here’s a real-world scenario of a MEQ instruction:

  1. A Micrologix 1100 Allen Bradley PLC is used to control a process.
  2. In rung 0000, a MEQ  instruction is used to compare an Integer N7:0 to N7:2. A mask stored in register N7:1 is applied to the operation.
  3. The mask N7:1 is set to 0. In other words, 0000,0000,0000,0000 in binary.
  4. Since not a single bit of the mask was set to HIGH, the instruction will always evaluate to TRUE.
  5. The MEQ evaluates N7:0 compared to N7:2 to TRUE because of the specified mask.
  6. In rung 0001, a MEQ  instruction is used to compare an Integer N7:3 to N7:5. A mask stored in register N7:4 is applied to the operation.
  7. The mask N7:1 is set to 007Fh. In other words, 0000,0000,0111,1111 in binary.
  8. Seven first bits of the mask are set to HIGH. Therefore, only those bits will be compared between the two operands.
  9. The MEQ evaluates N7:3 compared to N7:5 to TRUE because of the specified mask. Note that the bits of these integers are exactly the same within the position specified by the mask.

Programming example in RSLogix 500:



The MEQ instruction is much easier to understand in binary form. Therefore, the associated tags are shown in the image above. Looking at the mask, one can easily identify which bits are labeled as “important” for comparison. Each bit set to HIGH within the mask register will be evaluated in the operands. If the bits match, the instruction will evaluate to TRUE regardless of the other bits.

In the first example, the mask is set to 0. Although this is not something you should see in the code, the instruction will be always TRUE since all bits are ignored in the comparison.

In the second example, the first seven bits are set to HIGH through a mask of 007Fh = 0000,0000,0000,0111,1111b. The bits which are set to HIGH are compared within the two operands. Since we’re dealing with two integers which have exactly the same first seven bits, the instruction evaluates to TRUE in this case as well.

Data Types Allowed for MEQ

The MEQ can be used to compare two values of identical types & uses a mask. These value can only be INTs.

  • Integer – You may specify each operand to be of “Integer” type.

Important Notes

  • Note 1 – Both operands will be evaluated within the MEQ instruction is being scanned. In an instance where the value is changed in other locations for only a brief duration, the MEQ comparison may result in unforeseen outcomes.
  • Note 2 – When working with constants, RSLogix 500 will not allow the user to use the constant in the “Operand A” field. The constant must be specified within “Operand B”. This limitation is not present in all software packages.
  • Note 3 – The user may not specify a comparison of two constants within RSLogix 500. In other words, you may not use the MEQ instruction with “Operand A” set to 7 and “Operand B” set to 20. This case will always evaluate to FALSE which should not be used.

Video Tutorial

Back to tutorials

Got a question or comment?

Related Tutorials


Opto 22 groov RIO Getting Started

The groov RIO module from Opto 22 has been released only a few months ago. The groov RIO is a feature packed piece of hardware that is easy to install, configure and deploy for many different field applications. The module comes pre-loaded with an array of software tools used across the industry and is ready to hit the floor running out of the box. Furthermore, the module is equipped with user configurable input and output nodes that have the capability unlike anything else on the market.

August 2, 2020
Vladimir Romanov

Micro800 PLC Programming Getting Started

The Micro800 Control Systems by Rockwell Automation provide a cost effective solution for small to medium automation systems. The controllers within this family are typically used on stand alone machines or small process applications. The family offers five distinct controller types that are further customizable through add-on modules: Micro810, Micro820, Micro830, Micro850 and Micro870.Micro800 Programmable Logic Controllers Getting StartedUnlike the other Rockwell Automation controllers, this line of PLCs is programmed through a dedicated software: Connected Components Workbench. From within this tool, the programmer can flash the firmware, load the program and monitor the state of the controller. Furthermore, Connected Components Workbench (CCW) is often used to program other non-PLC Rockwell Automation devices such as Variable Frequency Drives (VFDs) and certain Safety Relays.

July 26, 2020
Vladimir Romanov

An Introduction to DeviceNet Industrial Networks

In this tutorial you will learn about the DeviceNet industrial network, go over a basic offline configuration, and explore some advanced features.

July 24, 2020
Jacques Venter