DL06 Compare Function

betress

Member
Join Date
Aug 2004
Location
Alabama
Posts
5
Does any one know how to compare multiple real numbers in the DL06 and use the results of the compare to turn on multiple outputs?
It is critical that I remain in 32 bit format because the controls of the system require 4 decimal places and math functions use 1000ths of an inch.
 
Look at page 5-85 of the 06 manual on AutomationDirect's website. It explains the CMPR (compare real) instruction. It's pretty straight forward.
 
Use the CMPR instruction to compare the numbers and the associated flag bits (SP60, ...) to drive the outputs.

See page 5-85 of the manual
 
I tried this instruction, but it only can be used once. All CMPR instructions use the same bits sp60, sp61 and sp62. I need a limit of the less than and greater than not just a bit set. I am measuring the height of material and there is a +/- tolerance that I must stay in and I am firing outputs according to where the height is. For example, there is a setpoint of 1.5 and a tolerance of +/- .5 and I have to stay within 2 and 1 and between 1.25 and 1.75 I fire an output. Between 1 and 2 I fire an output and less than 1 and more than 2 I fire another output. My problem with CMPR is I can only use one bit. I have the manual and it is no help.
 
BE THE COMPUTER!!!

Have the computer gather and evaluate the data in the same way that you would if you were doing the same thing with a paper and pencil.

Simply think carefully how you would do the job if you were the controller (computer).

Use multiple Compares to gather situational data. After all situational data is available, then, using standard combinatorial logic, evaluate the situational data and make the appropriate output decisions. You can certainly use multiple outputs in a standard rung (i.e., a rung with no special functions).

You can do all of this in the same scan.

(43)
 
The CMPR will still only compare one v memory at time and once it sets the special relay. It does not matter what the other compare function does unless it sets the opposite bit which I do not want to do. I really understand PLC logic. Can someone give me an example of how to do this compare.
 
betress said:
I really understand PLC logic.

Then what Terry said should be of great help.

Keep track of the result of each compare, immediately following each compare, with regular ol' C bits.

| SPx Cx
|---] [-----------( OUT ) (or use SET if you prefer)


Use all these C bits you've collected (AKA 'your notes') to fire the outputs.

beerchug

-Eric
 
Arik,
Thanks for the example it would great if I only needed to use 1 bit from each compare, but I have to use sp60 and sp62 in 4 compare functions and this is a continous process.

For Terry and Eric
How can I keep track of what c bit I am setting when I am using sp 60 to turn on 3 c bits and sp62 to turn on 3 c bits. I have to turn on 3 lights green, yellow and red. It is random in 1 compare I have to use sp60 to turn on the green lite and use sp62 to turn on yellow lite. In another compare in the same scan. I have to use sp62 to turn on the green lite and sp60 to turn on the yellow lite. The other compares are needed to control the red lite and yellow lite same as I just described.
 
Betress,

I think you are missing the point of what Eric and Terry are hinting at. You will notice if you start frequenting this board more that a lot of the regulars will initially hint at what to do so that you as the questioner can learn how instead of just being told; the old "give a man a fish..." parable.

What they told you is correct. The CMPR function can be used multiple times during one scan to turn on many bits. I use it all the time to compare the output from a strain gage indictator. If you need to know when something falls within a range (tolerance) you need to compare for both your High and Low conditions and then check to see both conditions are met.

I am going to assume for this example that you want the Green Light on when between 1.25 and 1.75, the Yellow light is on when you are between 1.00 and 2.00, and the Red Light is on when below 1.00 and above 2.00. If this does not exactly match what you have this should be enough for you to figure the rest out.

Code:
|The Value is LT or GTE 1.00 (V2010)       |
|                                          |
|  SP1                              V2000  |
|--| |-------------------------+----(LDR)--|
|                              |           |
|                              |    V2010  |
|                              +---(CMPR)--|
|                                          |
|  SP60                               C1   |
|--| |-------------------------------(OUT)-|
|                                          |
|  SP61                               C2   |
|--| |--+----------------------------(OUT)-|
|       |                                  |
|  SP62 |                                  |
|--| |--+                                  |
|                                          |
|The Value is GTE 1.25 (V2012)             |
|                                          |
|  SP1                              V2000  |
|--| |-------------------------+----(LDR)--|
|                              |           |
|                              |    V2012  |
|                              +---(CMPR)--|
|                                          |
|  SP61                               C3   |
|--| |--+----------------------------(OUT)-|
|       |                                  |
|  SP62 |                                  |
|--| |--+                                  |
|                                          |
|The Value is LTE 1.75 (V2014)             |
|                                          |
|  SP1                              V2000  |
|--| |-------------------------+----(LDR)--|
|                              |           |
|                              |    V2014  |
|                              +---(CMPR)--|
|                                          |
|  SP60                               C4   |
|--| |--+----------------------------(OUT)-|
|       |                                  |
|  SP61 |                                  |
|--| |--+                                  |
|                                          |
|The Value is LTE or GT 2.00 (V2016)       |
|                                          |
|  SP1                              V2000  |
|--| |-------------------------+----(LDR)--|
|                              |           |
|                              |    V2016  |
|                              +---(CMPR)--|
|                                          |
|  SP60                               C5   |
|--| |--+----------------------------(OUT)-|
|       |                                  |
|  SP61 |                                  |
|--| |--+                                  |
|                                          |
|  SP62                               C6   |
|--| |-------------------------------(OUT)-|
|                                          |
|Turn on Green Light                       |
|                                          |
|  C3    C4                           Y0   |
|--| |---| |-------------------------(OUT)-|
|                                          |
|Turn on Yellow Light                      |
|                                          |
|  C2    C5                           Y1   |
|--| |---| |-------------------------(OUT)-|
|                                          |
|Turn on Red Light                         |
|                                          |
|  C1    C6                           Y2   |
|--| |---| |-------------------------(OUT)-|
|                                          |

I hope this clears it up for you.

Bob
 
Thanks Bob,
I normally figure these things out on my own and this is the first I ever used a forum to find a solution to problem. This problem finally fried my brain and I couldn't think straight. Thanks again. I will try this Monday.
 
Well, Damn, Bob...

Ain't gonna throw it away just because ya beat me...

SP60, SP61 and SP62 HAVE NOTHING TO DO WITH LIGHTS!!!

SP60, SP61 and SP62 are Special bits in a COMPARE Functiuon.

What does that have to do with lights? You are getting the cart before the horse. Do not turn any light ON until you know which light to turn ON!!!

I derived the following from your description of your indicator scheme. It appears that you said...

Out1 = Green
Out2 = Yellow
Out3 = Red


Out3
d 2.00 ---------------
c 1.75 ----- |
Target 1.50 Out1 Out2
b 1.25 ----- |
a 1.00 ---------------
Out3




ORIGINAL RULES:

Out1 (GREEN) = (h >= b) AND (h <= c)

Out2 (YELLOW) = (h >= a) AND (h <= d)

Out3 (RED) = (h < a) OR (h > d)


I derived this from your description. However, in that scheme, if "h" is 1.50 (right on target) then both the GREEN and YELLOW Lights will be ON. I expect, in this case, that you really intend that only the GREEN be ON. If so, then the rules have to change a bit...


Out3
d 2.00 ------
Out2
c 1.75 ------
Target 1.50 Out1
b 1.25 ------
Out2
a 1.00 ------
Out3



MODIFIED RULES:

Out1 (GREEN) = (h >= b) AND (h <= c)

Out2 (YELLOW) = { (h >= a) AND (h < b) } -OR- { (h > c) AND (h <= d) }

Out3 (RED) = (h < a) OR (h > d)


Now, look at the Modified Output rules listed above.

(h < "a") is used in Out3
(h >= "a") is used in Out2
Note: (h >= "a") is equivalent to { (h > "a") -OR- (h = "a") }

(h < "b") is used in Out2
(h >= "b") is used in Out1
Note: (h >= "b") is equivalent to { (h > "b") -OR- (h = "b") }

(h > "c") is used in Out2
(h <= "c") is used in Out1
Note: (h <= "c") is equivalent to { (h < "c") -OR- (h = "c") }

(h > "d") is used in Out3
(h <= "d") is used in Out2
Note: (h <= "d") is equivalent to { (h < "d") -OR- (h = "d") }

This means, in order to properly control your lights, you must know ALL of the relative conditions (<, =, and >) for each of your limits.

This means, ALL of these evaluations must exist BEFORE you consider which light to turn ON.


Consider the following...
You have this particular friend. He is an "idiot savant". He does not know how to tie his shoes nor carry on a conversation but he does have one talent in which he excels. He can take two numbers and immediately tell you if the second number is "less than", or "equal to", or "greater than" the first number. He can do this as quickly as you can throw numbers at him.

Now, your friend might simply tell you that "h" (the second number) is "greater than" "x" (the first number). However, additional information is implied in what he does not say. That is, in saying that "h is greater than x", directly implies the following:

"h is NOT EQUAL to x"
and...
"h is NOT LESS THAN x"


The Compare Instruction:

Now, this particular type of Compare Instruction does not leave any information unspoken, that is, nothing is implied; it is explicitly indicated.

When the instruction indicates, "h is greater than x", it also indicates the following...
"h is NOT EQUAL to x"
"h is NOT LESS THAN x"

It does not matter which condition you are interested in; you are going to get them all.

I do not know how your compare bits are assigned so I will just assume the following...

C60 = (h < "x")
C61 = (h = "x")
C62 = (h > "x")



...where "x" is the "first number" and "h" is the "second number".

If the instruction "sees" that "h > x" then the instruction will produce the following outputs:


C60 = (h < "x") = "0"
C61 = (h = "x") = "0"
C62 = (h > "x") = "1"



You make one request and you get three bits of information.

NOTE: The information contained in all three bits is relative to the most recent compare effort. That is, there is no residual information left over from previous compare operations.


Now, going back to my earlier statement...
"...ALL of these evaluations must exist BEFORE you consider which light to turn ON."

How can you gather all of the required information?

You simply need to throw a bunch of numbers at your friend and then "record" his responses.

Of course, you need to "throw" these numbers in an organized manner. Looking back at the Outputs vs. Limits Chart, you see that you have four limits: a, b, c, and d.

You need to acquire the condition of "h" relative to each of the limits. You need to make four compares: h & a, h & b, h & c, and h & d.

Now, your "friend" (the Compare Instruction) will give you the information you need. However, he can only provide information relative to a particular set of numbers. You need to set aside some places to hold the results of each compare.

You need to make four compares: a, b, c, and d.


C100 = h < "a"
C101 = h = "a"
C102 = h > "a"

C200 = h < "b"
C201 = h = "b"
C202 = h > "b"

C300 = h < "c"
C301 = h = "c"
C302 = h > "c"

C400 = h < "d"
C401 = h = "d"
C402 = h > "d"



OK, so now you have places to keep the data. Now you need to "gather" the data.
Your limit values can be hard-coded in ladder, or variable through an HMI... up to you.

You need to determine when this operation occurs. You might use one particular bit (one-shot?) to activate the following section of code for one scan. If you want, you can run it continually, however, that might produce more confusion than not.


Now, assuming that...

C60 = h < "x"
C61 = h = "x"
C62 = h > "x"

---COMPARE h & x (where x = a)---( C60, C61, C62)

h<x
C60
---| |---( C100 ) h < a

h=x
C61
---| |---( C101 ) h = a

h>x
C62
---| |---( C102 ) h > a


---COMPARE h & x (where x = b)---( C60, C61, C62)

h<x
C60
---| |---( C200 ) h < b

h=x
C61
---| |---( C201 ) h = b

h>x
C62
---| |---( C202 ) h > b


---COMPARE h & x (where x = c)---( C60, C61, C62)

h<x
C60
---| |---( C300 ) h < c

h=x
C61
---| |---( C301 ) h = c

h>x
C62
---| |---( C302 ) h > c


---COMPARE h & x (where x = d)---( C60, C61, C62)

h<x
C60
---| |---( C400 ) h < d

h=x
C61
---| |---( C401 ) h = d

h>x
C62
---| |---( C402 ) h > d





The previous results are then used, immediately, in the next section of code which controls the Outputs.

Now, let's develop the code for the Output logic...

MODIFIED RULES:

Out1 (GREEN) = (h >= b) AND (h <= c)

Out2 (YELLOW) = { (h >= a) AND (h < b) } -OR- { (h > c) AND (h <= d) }

Out3 (RED) = (h < a) OR (h > d)



OUT1 GREEN

h >= b ==> (h > b) -OR- (h = b)
C202 C201
-AND-

h <= c ==> (h < c) -OR- (h = c)
C300 C301


OUT2 YELLOW

h >= a ==> (h > a) -OR- (h = a)
C102 C101
-AND-

h < b ==> C200

-OR-

h > c ==> C302

-AND-

h <= d ==> (h < d) -OR- (h = d)
C400 C401


OUT3 RED

h < a -OR- h > d
C100 C402



There are several different ways to maintain your light status. The method depends on what you need to have happen. Since you did not describe that portion, I will simply assume that a particular status is maintained until there is cause to change.



Out1 (GREEN) = (h >= b) AND (h <= c)

h>b h<c
C202 C300
---| |---+---| |---+---+---( SET ) OUT-1 GREEN
| | +---( RST ) OUT-2 YELLOW
h=b | h=c | +---( RST ) OUT-3 RED
C201 | C301 |
---| |---+---| |---+


Out2 (YELLOW) = { (h >= a) AND (h < b) } -OR- { (h > c) AND (h <= d) }

h>a h<b
C102 C200
---| |---+---| |---+---+---( RST ) OUT-1 GREEN
| | +---( SET ) OUT-2 YELLOW
h=a | | +---( RST ) OUT-3 RED
C101 | |
---| |---+ |
|
h<d h>c |
C400 C302 |
---| |---+---| |---+
|
h=d |
C401 |
---| |---+


Out3 (RED) = (h < a) OR (h > d)

h<a
C100
---| |---+-------------+---( RST ) OUT-1 GREEN
| +---( RST ) OUT-2 YELLOW
h>d | +---( SET ) OUT-3 RED
C402 |
---| |---+




----End of Single Scan Operation----


You need to figure out how you are going to handle status at power-up, at re-start with an item at the inspection area, and at restart without an item at the inspection area.

There are many ways to accomplish this stuff...
 
Terry Woods said:
Well, Damn, Bob...

Ain't gonna throw it away just because ya beat me...



Hehe,

Since I started working on weekends to make up for the time lost during the week, I am getting up at 5:30 am and had time to crank this out when I got here.

There is another aspect of using the CMPR bits. I do it using the NOT bit available for the 250/260. I think it also works with the 06. Not sure about the 05.

Code:
|                            |
|  SP60                 C0   |
|--| |----+-----------(OUT)--|
|         |                  |
|         |             C1   |
|         +-{NOT}-----(OUT)--|

Now C0 would represent Less Than and C1 would represent Greater Than/Equal to. It also works with the SP62 bit for LTEQ and GT. I did not want to confuse the issue with that one just yet. I am always looking at ways to get rid of bits to improve scan time, when I can.

Bob
 

Similar Topics

Hi, Mostly AB guy here with a little Koyo experience, but all of its digital. I get handed three analog I/O cards and asked to prove that they...
Replies
6
Views
499
Hi all, I am making a test rig to be able to wire in any DL06 (or DL05) And create a HMI in red lions crimson 3.1 to test all the inputs and...
Replies
4
Views
931
I have a Cmore screen which is communicating to the DL06 in BCD and need to create a timer that works in real numbers for a test, I simply need to...
Replies
3
Views
2,138
I have a client that has many Automation Direct DL06 PLCs for a municipal water/wastewater system. When there is a power outage, one of the sites...
Replies
4
Views
2,441
Hey everyone, Working on a system with a Koyo DL06 processor and it's my first experience with them. I have DirectSoft 6 and we got the program...
Replies
5
Views
2,335
Back
Top Bottom