Back to tutorials
Beginner

PLC Programming Comparison Instructions – MEQ | Masked Equal

By
Vladimir Romanov
|
September 24, 2018
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.

Video Tutorial

Back to tutorials

Related Tutorials

Intermediate

PLC Programming Example Project - Batching Tank Ladder Logic PLC and HMI Tutorial

Generally speaking, there are two types of processes in manufacturing: discrete and analog. A discrete process is a manufacturing methodology that will produce separate widgets. In other words, a production line may output one item, two items, three items, etc. An analog production process is where the plant will create a quantity of product that is quantifiable by weight. Examples include the production of beverages, sauces, raw ingredients, etc. Although it is possible to design a flow that will continuously output the product, such production is often managed in batches. It is important to note that although batches are considered to be analog or continuous flow, most of them end up being packaged for consumption which converts them into a discrete manufacturing process.

September 14, 2020
|
By
Vladimir Romanov
PLC Programming Career

PLC Programming Certification - Complete Guide

You may choose to pursue a traditional college degree, learn through online tutorials, or take a course that will issue a plc programming certification upon completion. However, what is the best option, and what are the best PLC programming certifications?

August 6, 2020
|
By
Vladimir Romanov
Beginner

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
|
By
Vladimir Romanov