BRX PLC Compare Instructions

Compare instruction are often used in PLC programs to test pairs of values. The output of this comparison conditions the logical continuity of a rung. The BRX series of programmable logic controllers has the following compare contact instructions.
= (if Equal contact)
<> (if Not Equal contact)
> (if Greater Than contact)
>= (if Greater Than or Equal contact)
< (if Less Than contact)
<= (if Less Than or Equal contact)
Besides these instruction the BRX PLC will also have compare instructions for the built in real time clock of the system. We will be looking at these instructions along with some programming examples. As a system integrator, this ability can prove very useful to you in the field when commissioning your automation system.
Lets get started with the BRX PLC Compare Instructions.

The best way to learn about the compare contact bits is to look at an example. We will set up a counter that has the system 1 second flag as the count input. Our preset value will be set to 10. The counter will be self resetting by placing the counter done bit into the reset input. Using the contact compare instructions we will now turn on/off the physical outputs as appropriate. Please refer to the post BRX PLC Counters for a review of counters in the PLC.
The accumulator of the counter CT0.ACC will contain the current value of the counter. This will cycle from 0 to 10, 0 to 10 etc. Lets now look at the contact compare instructions.

(CONTACT) – if Equal
When the value of CT0.ACC is equal to 0 then the contact is closed allowing power flow to turn on Y0 output. When the value of CT0.ACC is not equal to 0 then the contacts are open, interrupting power flow.

(CONTACT) – If Not Equal
When the value of CT0.ACC is not equal to 0 then the contact is closed allowing power flow to turn on Y1 output. When the value of CT0.ACC is equal to 0 then the contacts are open, interrupting power flow.

(CONTACT) – If Greater Than
When the value of CT0.ACC (left side) is greater than 5 (right side) then the contact is closed allowing power flow to turn on Y2 output. When the value of CT0.ACC is less than or equal to 5 then the contacts are open, interrupting power flow.

(CONTACT) – If Greater Than or Equal
When the value of CT0.ACC (left side) is greater than or equal to 5 (right side) then the contact is closed allowing power flow to turn on Y3 output. When the value of CT0.ACC is less than 5 then the contacts are open, interrupting power flow.

(CONTACT) – If Less Than
When the value of CT0.ACC (left side) is less than 5 (right side) then the contact is closed allowing power flow to turn on Y4 output. When the value of CT0.ACC is greater than or equal to 5 then the contacts are open, interrupting power flow.

(CONTACT) – If Less Than or Equal
When the value of CT0.ACC (left side) is less than or equal to 5 (right side) then the contact is closed allowing power flow to turn on Y5 output. When the value of CT0.ACC is greater than 5 then the contacts are open, interrupting power flow.

DTCMP – Compare Date / Time
The Compare Date / Time (DTCMP) instruction compares the Date and/or Time fields of two Date / Time structures. The comparison operation subtracts the second date / time from the first date / time.
In our example we will use the system date and time (SDT0) and compare this to the user defined date and time structure. (UDT0) Comparing the date only we will set the bits C0 to C2 according to the compare results.
This instruction can be used to set up a regular maintenance schedule for the equipment that your are programming.

DTDIFF – Difference between two Date / Times
The Difference between two Date / Times (DTDIFF) instruction calculates the number of seconds of time between the contents of two Date / Time structures.
In our example we will use the system date and time (SDT0) and compare this to the user defined date and time structure. (UDT0) The result is the number of seconds difference between the two dates.
This can be used for an indication of the time before the next preventative maintenance that is due on the machine.

You can watch the video below to see how the compare instructions work in the BRX Series PLC.

If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.

First Name:Last Name:Email address:

Leave this field empty if you're human:

Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.