Logix 5000 Limit help

crawler009

Member
Join Date
Feb 2012
Location
Planet Earth
Posts
239
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?

Limit.png
 
Last edited:
I just tried this on a sim and I don't know where you got "OR? So a value > 100 would always turn on the light?"

Limit can either be everything inside or outside (pick one) the limit but not both.
 
With the settings in the image you posted the light will be on with a value of 0 to 100 and all values inbetween. If the value is less then 0 the light will be off, if the value is greater then 100 the light will be off. Simple!!

If you want the light to be off when the value is greater then 0 and less then 100 then reverse the settings "Low Limit" at 100 "High Limit" at 0. Simple!!
 
Last edited:
I think the OP understands the LIM instruction. His picture is just not lined up with the first part of his post.

In Example 1: shown below the description does not match the ladder logic.

His question is about the Structured Text example. As Shown in the help file.

Capture.jpg
 
...Simple!!

If you want the light to be off when the value is greater then 0 and less then 100 then reverse the settings "Low Limit" at 100 "High Limit" at 0. Simple!!

Not so simple, Mickey.

The light will always be "on", at the limit values, regardless of whether the high limit is greater than the low limit, or vice-versa.

The instruction sets the output on when the tested value "Is greater than, or equal to, the low Limit, and less than, or equal to, the high limit"

Those "or equal to" statements make what I said earlier correct.

If you want the light to go "off" between 0 and 100, you have to set the Low Limit to 101, and the High Limit to -1
 
Not so simple, Mickey.

The light will always be "on", at the limit values, regardless of whether the high limit is greater than the low limit, or vice-versa.

The instruction sets the output on when the tested value "Is greater than, or equal to, the low Limit, and less than, or equal to, the high limit"

Those "or equal to" statements make what I said earlier correct.

If you want the light to go "off" between 0 and 100, you have to set the Low Limit to 101, and the High Limit to -1


Exactly, that's what I tried to say. Your explanation is much better then mine. Simple.
 
Last edited:
From OP
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?
No, all the statement must be evaluated to be true ELSE false


Structured text example from AB help file.
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;
It looks to me like there is a missing ( in the OR statement.


The Structured Text converted to Ladder looks like this and works correctly. Only numbers 0 thru 100 will turn on the light.

Limit 101.jpg
 
I stand corrected I missed the 2nd OR in the statement.
maybe I put the ( is in the wrong spot. But the OP is correct values > 100 turn on light.
Now I have a ladder that looks like this:
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;

Or my ladder does not match statement.

Limit 101.jpg
 
Last edited:
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...

Lim%20Help.jpg


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
LIM%20-%20ST%20Equivalents%20-%20Type%201.bmp


Ladder LIM > ST Type 2
LIM%20-%20ST%20Equivalents%20-%20Type%202.bmp


Ladder LIM > ST Help File
LIM%20-%20ST%20Equivalents%20-%20Help%20File.bmp


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
 
How about the # of posts you have made is scaled to how many words are in an answering post, then Geospark could get to 10,000 quicker than Mickey and then he might retire.🍻
Not that l want that to happen, its to entertaining.
 
LIM - an any language....

The instruction sets the output on when the tested value "Is greater than, or equal to, the low Limit, and less than, or equal to, the high limit"

Those "or equal to" statements make what I said earlier correct.

'nuff said.

Of course if you want to "negate" a LIM, you can always drive a temporary bit, then "negate" it on the next rung or statement... that is not the same as swapping the low/high limits.
 
I entertain you?...

PLCnovice61 said:
How about the # of posts you have made is scaled to how many words are in an answering post, then Geospark could get to 10,000 quicker than Mickey and then he might retire.🍻
Not that l want that to happen, its to entertaining.

Entertaining? I entertain you? Like I'm funny?...

"...You mean, let me understand this cause, ya know maybe it's me, I'm a little f***ed up maybe, but I'm funny how, I mean funny like I'm a clown, I amuse you? I make you laugh, I'm here to f***in' amuse you? What do you mean funny, funny how? How am I funny?..."

Hopefully you weren't born less than 10 klicks South of Millennial Hill? (1990). If you were, then give Goodfella's Pizza a call and quote the above. You'll get free pizza for life. I swear!

I don't really pay much attention to my post count. It's not a number that particularly interests me. It is what it is. I post when, where and what I can but I focus more on making my posts count, as opposed to counting my posts.

I believe in quality over quantity. I don't tend to shoot from the hip with lots of quick two-liner brainfarts, which quite frankly I read a lot of here. Some people just don't think things out fully or bother to look stuff up and double-check. Perhaps some just want to add five quick posts to their count for the day. I don't know? "Something is better than nothing" works for some and "Alternative Facts" sit well with others. But I prefer the garden variety. Still, even if their "somethings" turn out to be "nothings", and their "alternate reality" bubbles are burst, they've still gotten that post count up - "Who the man!?".

I'm sure those with PTCD (Post Traumatic Count Disorder) have fits reading some of my posts? "That's a whole year's worth of brainfarting gone up in smoke, just for one post count! I could've hit that next milestone and kept on truckin' at that rate!".

Post counts count for nothing when there's nothing in them that counts.

Regards,
George
 
As ST was the main "question part" here for the OP...

daba said:
LIM - an any language...

The instruction sets the output on when the tested value "Is greater than, or equal to, the low Limit, and less than, or equal to, the high limit"...

Did someone just f.art? (Just kidding!)

This is just another sweeping statement where all of the possible options have not been fully considered. A bit like the RSLogix 5000/Logix Designer exception in that other thread. We all fall foul to these from time to time, including myself.

The LIM instruction, as we know it in Ladder or Function Block Diagram, does not exist for the Structured Text language. As such, ST is not bound to any predefined rules for a user-defined limit construct. That's the advantage ST has here over the other languages. There is nothing to dictate that an ST limit construct must include "or equal to". That predefinition would only apply to the LD and FBD languages as they do have LIM instruction equivalents which evaluate as you've described.

My equivalent ST examples were just to demonstrate the traditional two types of LIM that most are used to in Ladder, in particular. But they are not definitive for ST.

I had earlier thought that you were just describing to Mickey the evaluation of the LIM instruction when used in LD. But now that you have extended that description to any language, it would not strictly be true to say.

To take your earlier example...

...If you want the light to go "off" between 0 and 100, you have to set the Low Limit to 101, and the High Limit to -1

For LD or FBD yes, the above example values would be necessary to evaluate a LIM instruction false for a value between 0 and 100. But for ST, you do not have to change the values or even evaluate the limit statement as false. To express a limit in an ST statement, that would require a false result for a value between 0 and 100, but not 0 or 100, we can simply change the comparison operator "greater than or equal to" to just "greater than" and likewise "less than or equal to" to just "less than". Then simply change the required boolean result to false...

Code:
IF value > 0 AND value < 100;
THEN light_1 := 0;
ELSE light_1 := 1;
END_IF;

Here when the statement is true the result is false. The "or equal to" comparison is optional in ST, depending on what you wish to achieve. Also, as shown, you can choose which boolean result you require -

Confirm:
Statement is true...
THEN light_1 := 1...

...or...

Negate:
Statement is true...
THEN light_1 = 0...

...or whichever combination you like. This makes ST far more versatile in these situations. Might I even say "limitless"? You are essentially creating your own user-defined ST instructions.

Now, if Wikipedia, or some other profound resource, states that a traditional "limit instruction" must contain "or equal to" or be damned, then I won't argue with that. As long as I know that, when I might want to implement less limited limit logic while programming, ST is my friend.

The above is a simple example of when ST may be a better option to achieve what the other languages cannot as easily, or at all. If you have it at your disposal, that is.

Regards,
George
 
Help file should read:

Code:
IF (low <= high AND (value >= low AND value <= high)) OR
    (low > high AND (value <= high OR value >= low)) THEN
    light_1 := 1;
ELSE
    light_1 := 0;
END_IF;

For the specific example of low = 0, high = 100, it should read:

Code:
IF (value >= 0 AND value <= 100) THEN
    light_1 := 1;
ELSE
    light_1 := 0;
END_IF;

I have an unhealthily strong dislike of the LIM instruction, and suggest a LEQ and GEQ pair are used in its place, for clarity.
 

Similar Topics

Does anyone know how to set the background colors of instuction blocks (TON, MOV, etc)?
Replies
1
Views
83
Hello all, I have a question in regards to RSlogix 5000. I am having issues with the program force closing when I try to make online edits. We...
Replies
0
Views
95
Greetings ... someone sent me a request for some student handsouts that I developed ... turns out that I had this hosted on my business website...
Replies
0
Views
109
This may be something obvious that I could learn if I sat down to understand the topic in detail with tutorials and manuals. But sometimes it's...
Replies
0
Views
117
Thank you for any and all responses/help. I have an RSLogix 5000 v20 and a Cognex In-Sight v5.9 spreadsheet (8502P). I can not figure out how to...
Replies
0
Views
101
Back
Top Bottom