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...