Tuesday, October 22, 2019

PLC Compare Instruction

In data handling we also have Logical functions like comparison which helps us to compare our results or any data. By this function we can set the value for any operation. When result meets the criteria (Greater, Lesser or Equal) with the set value then it can be controlled by PLC.  For example





Fig: Example of comparison


The above example shows an equal (EQU) function that compares two floating point numbers. If the numbers are equal, The output bit B3:5/1 is true, Otherwise it is false.
In this case when value of A and B is equal, Output B turns on.


Other equal functions are listed below:

EQU (value, value) – equal
NEQ (value, value) – not equal
LES (value, value) – less than
LEQ (value, value) – less than r equal
GRT (value, value) – Greater than
GEQ (value, value) – greater than r equal
CMP (expression) – Compare two values for equality
MEQ (value, mask, threshold) – compare for equality using a mask
LIM (low limit, value, high limit) – check for a value between limits



Now we are using above compare functions in program and check the outputs with inputs.




FIG : Comparison Functions

In above figure we use six comparison functions and using different outputs for each of them. When any of the function gets true, The respective output turns on.

Inputs and outputs applied in above program:

Inputs
Outputs
N7:3
N7:2
O:012/0 = 0
O:012/1 = 1
O:012/2 = 0
O:012/3 = 0
O:012/4 = 1
O:012/5 = 1
N7:3
N7:2
O:012/0 = 1
O:012/1 = 0
O:012/2 = 0
O:012/3 = 1
O:012/4 = 0
O:012/5 = 1
N7:3
N7:2
O:012/0 = 0
O:012/1 = 1
O:012/2 = 1
O:012/3 = 1
O:012/4 = 0
O:012/5 = 0
  



Lets use above problem using CMP (compare) function only. CMP function need expression.
For equal we use:                      =
For not equal we use:              < >
For lesser we use:                     <
For lesser or equal we use:      <=
For greater we use:      >
For greater or equal we use:      >=

 Below program gives same result as above figure shows.



FIG: Equivalent statement using CMP function

First compare is for Equal, Second for not equal, Third for lesser, Fourth for lesser or equal, fifth for greater and last one is for greater or equal.

Now we do some complex comparison where we discuss about LIM and MEQ.
The first three functions (LIM), shown in figure below, will compare a test value to high and low limits. If high limit is above the low limit and the test value is between or equal to one limit, then it will be true.




FIG: Complex Comparison Function

If the low limit is above the high limit then the function is only true for test values outside the range.

Now the mask equal will compare the bits of two numbers, but only those bits which are true in mask. First we should understand masking. We cover some data to operate and the rest is useless, then the covered data is called mask and process is masking. Let us have a data 0,1,2,3,4,5,6,7,8,9 and now we mask 4,5,6,7 then remaining numbers are useless for masking operations. In other way we can mask lower bits ( 0,1,2,3,4) then the higher bit (5,6,7,8,9) are unmasked and useless for masked operation.

Now the output turns on when operation is true.

We have some change in data in memory location after operation. For example:

Address
Before(Decimal)
Before(Binary
After (Binary)
N7:0
1                           0000000000000001
0000000000000001
N7:1
5                           0000000000000101
0000000000000101
N7:2
11                         0000000000001011
0000000000001011
N7:3
15                         0000000000001111
0000000000001111
N7:4
8                           0000000000001000
0000000000001000
N7:5
0                           0000000000000000
0000000000001101

Here the change in output address (N7:5) is random but it change during process. It is not necessary till this address is used for another process too.

No comments:

Post a Comment

Logical Gate, Symbols, Truth Table and functions

Electric Logic •Logical values can easily be expressed by electrical circuits. •“True” or “1” can be defined as voltage on a wire whil...

Smart Chapter