Sutured Text...
You are getting there cwal61!...
I started typing this up late last night and have just found time now to finish it before I head home (I wanted to add the live screenshots).
crawler009 said:
I found today someting interesting in the help for the Limit instruction in Logix 5000 V24.
The example is:
Example 1: Low Limit £ High Limit
Code:
When 0 <= value >= 100, set light_1. If value < 0 or value > 100, clear light_1.
So, it would activate the light only with a value of 100.
But the equivalent ladder diagram is the attached Image.
So they ment:
Code:
When 0 <= value <= 100, set light_1. If value < 0 or value > 100, clear light_1.
The equivalent structured text is
Code:
IF (value <= 100 AND (value >= 0 AND value <= 100)) OR
(value >= 100 AND value <= 0 OR value >= 100)) THEN
light_1 := 1;
ELSE
light_1 := 0;
END_IF;
Here is my question. In the part
Code:
(value >= 100 AND value <= 0 OR value >= 100)
doesn't AND have precedence over OR? So a value > 100 would always turn on the light?
Why so complicated? Did they read the help file after writing it?
You are correct in that there are a couple of typographical errors in that help file, not to mention a great deal of confusion. If we look back over what you have posted above, plus the help page screenshot kindly provided by cwal61, we might make some sense of it all...
Error 1:
Code:
When 0 <= value [color="red"]>[/color]= 100, set light_1. If value < 0 or value > 100, clear light_1.
So,
it would activate the light only with a value of 100.
That would be correct. The highlighted greater than "
>" is of course an error here and should be less than "
<".
Example 1 of error:
Code:
When 0 <= [B]50[/B] [color="red"]>[/color]= 100, set light_1. If [B]50[/B] < 0 or [B]50[/B] > 100, clear light_1.
This is - When 0 is less than or equal to 50 (it is less than) and 50 is greater than or equal to 100 (it is neither), set light_1 - The light stays off.
If 50 is less than 0 (it is not) or 50 is greater than 100 (it is not), clear light_1 - The light stays off.
Example 2 of error:
Code:
When 0 <= [B]100[/B] [color="red"]>[/color]= 100, set light_1. If [B]100[/B] < 0 or [B]100[/B] > 100, clear light_1.
This is - When 0 is less than or equal to 100 (it is less than) and 100 is greater than or equal to 100 (it is equal to), set light_1 - The light is turned on.
If 100 is less than 0 (it is not) or 100 is greater than 100 (it is not), clear light_1 - The light stays on.
Example 3 of error:
Code:
When 0 <= [B]200[/B] [color="red"]>[/color]= 100, set light_1. If [B]200[/B] < 0 or [B]200[/B] > 100, clear light_1.
This is - When 0 is less than or equal to 200 (it is less than) and 200 is greater than or equal to 100 (it is greater than), set light_1 - The light is turned on.
If 200 is less than 0 (it is not) or 200 is greater than 100 (it is greater than), clear light_1 - The light is turned off.
Here the two conditions would be fighting each other.
Example 1 of correction:
So they ment:
Code:
When 0 <= 50 [color="red"]<[/color]= 100, set light_1. If 50 < 0 or 50 > 100, clear light_1.
With the corrected "
<" -
When 0 is less than or equal to 50 (it is less than) and 50 is less than or equal to 100 (it is less than), set light_1 - The light is turned on.
If 50 is less than 0 (it is not) or 50 is greater than 100 (it is not), clear light_1 - The light stays on.
Example 2 of correction:
So they ment:
Code:
When 0 <= 200 [color="red"]<[/color]= 100, set light_1. If 200 < 0 or 200 > 100, clear light_1.
When 0 is less than or equal to 200 (it is less than) and 200 is less than or equal to 100 (it is neither), set light_1 - The light stays off.
If 200 is less than 0 (it is not) or 200 is greater than 100 (it is greater), clear light_1 - The light stays off.
A simple error but well spotted.
Error 2:
crawler009 said:
The equivalent structured text is
Code:
IF (value <= 100 AND (value >= 0 AND value <= 100)) OR
(value >= 100 AND value <= 0 OR value >= 100)) THEN
light_1 := 1;
ELSE
light_1 := 0;
END_IF;
Here is my question. In the part
Code:
(value >= 100 AND value <= 0 OR value >= 100)
doesn't AND have precedence over OR? So a value > 100 would always turn on the light?
What you've missed in the help file, and partly further omitted in your question part, are the correct parentheses, or (<brackets>).
From the help file one parenthesis is omitted (shown in
Red)...
Code:
IF (value <= 100 AND (value >= 0 AND value <= 100)) OR
(value >= 100 AND [COLOR="red"]([/COLOR]value <= 0 OR value >= 100)) THEN
light_1 := 1;
ELSE
light_1 := 0;
END_IF;
From your part quotation two parentheses are missing - the same one, plus its partner near the end (Shown in
Red)...
Here is my question. In the part
Code:
(value >= 100 AND [color="red"]([/color]value <= 0 OR value >= 100[color="red"])[/color])
doesn't AND have precedence over OR? So a value > 100 would always turn on the light?
These parentheses are very important to the structural syntax and order of operation. They allow us to nest or group expressions inside other expressions. The AND operator does indeed take precedence over the OR operator in the order of operation. However, the parentheses around expressions, and their nesting or grouping, hold the highest priority in the order of operation. As such, operators used inside nested expressions with parentheses will be evaluated first, regardless of the normal order of operation for those operators. For instance, and as we know, the AND operator has priority operation over the OR operator. But, when the OR operator is used inside a nested expression, where there is an AND operator outside that expression, the OR expression will be evaluated first. The nested expression with parentheses is determining the order of operation. The order of operation is not necessarily left-to-right, it is parenthesis driven.
Note: This is describing the order of operation for expressions nested within other expressions and how parentheses govern this order. It is not describing or taking into account the higher level order of execution for the Constructs in which the expressions are stated (Example: IF…THEN…ELSE). The Constructs at the higher level dictate if or when the parenthesized expressions are executed, and so on.
So, in this case, the nested OR expression inside the inner parentheses will be evaluated first. The result of the OR expression will then be evaluated against the AND expression inside the outer parentheses.
If we now take the whole Structured Text logic with correction...
Example 1 of correction:
Code:
IF (value <= 100 AND (value >= 0 AND value <= 100)) OR
(value >= 100 AND (value <= 0 OR value >= 100)) THEN
light_1 := 1;
ELSE
light_1 := 0;
END_IF;
Now we have gotten to where you are at, cwal61...
So what are we to make of it? I won't write it all out, but evaluating those two parenthesized expressions would appear to contradict each other. The first suggests that if the value is at 0 to 100 inclusive then light_1 = 1. The second suggests the opposite - if the value is at or below 0 or at or above 100 then light_1 = 1. This would suggests that any value will yield the same result - light_1 = 1?
What I think has happened here is that the author has accidentally entered both standard Ladder LIM types under the same Construct (IF...THEN...ELSE) while trying to convey an option. The OR between the two parenthesized expressions is not part of the overall Construct. It is intended more as a suggestion that you use one or the other of the parenthesized expressions, depending on which type you require, but not both at the same time.
I've typed up and tested a couple of examples of the two standard types of Ladder LIM instruction equivalents in ST. My equivalents are simpler. Then I have outlined how both corrected parenthesized expression "options" from the Help files are valid, once used independently...
Ladder LIM > ST Type 1
Ladder LIM > ST Type 2
Ladder LIM > ST Help File
Another interesting point is the fact that Logix Designer v24, in which you looked that LIM Instruction Help up in, gives an ST LIM "example" with no mention of it being an unsupported instruction in ST. I'm using Logix Designer v30 lately for a project I'm finishing off and under the LIM Instruction Help it states that this instruction is not supported in Structured Text. It does not mean you cannot roll your own as I've just done it, and they attempted in v24, but just that there is no direct ST LIM equivalent.
Going back to the Help in RSLogix 5000 v20 it states that...
"There is no equivalent structured text instruction. Use other structured text programming to achieve the same result."
I've v8 - v30, but I'm not going to go through them all checking for differences. As long as you know how to roll your own then the Help is not too important.
Unless they've attempted the above!
Dang, I've hit the 10,000 word limit again...oops!
Regards,
George