Allen Bradley PLC programming course.
Enroll Today!
Siemens PLC programming course
Register for FREE!
Back to tutorials

PLC Programming Comparison Instructions – MEQ | Masked Equal

By
Vladimir Romanov
Learning Path
No items found.
Table of Contents

Introduction

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:

MEQMaskedEqualInstruction3

Outcome:

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.
Back to tutorials

Ready To Learn More?

Level-up your career with unlimited access to practical, in-depth technical courses taught by industry experts. Explore our courses