IEC STL CASE Statement

LadderLogic

Member
Join Date
Jun 2003
Location
Chicagolandia
Posts
1,486


While working with Omron CX-P writing some code in structured text, I ran into a question for which I cannot seem to find a clear answer. It regards the operation of CASE...END_CASE statement. Here is an example:


CASE A OF
1:X:=1;
2:X:=2;
3:X:=3;
ELSE Y:=0;
END_CASE;


No misteries here: the variable A is evaluated and the program skips to one of the CASE clauses that matches the value of A (if A = 1 then X := 1 and so on). Once that clause is executed, the program flow jumps to END_CASE and then to whatever follows it.

Now consider this:

CASE A OF
1:
X:=1;
A:=2;
2:X:=2;
3:X:=3;
ELSE Y:=0;
END_CASE;


What happens when A equals 1? Obviously, the first clause would be executed, X would be assigned value of 1, A would be assigned value of 2 and then... And then - what? Would the program flow still jump directly to END_CASE and the new value of A will come into effect only on the next program scan or would the second clause (A = 2) would execute immediately?

The first is true for Select Case... End Select construct in Visual Basic. Is IEC STL CASE construct works the same or does it follow a typical ladder code assumption that evaluates every line of code top-to-bottom left-to-right?

P.S. As I mentioned above, I have been working with Omron's version of STL which may not be 100% IEC-compliant.
 
You haven't figured that out in 10 hours?

Sometimes it is best to just try it and see. I don't understand why there are so many post about how this or that function works. It is faster to just try the function than post a question and possibly get a correct answer.

I have the IEC specifications. The IEC specifications are very poor. They only specify the syntax. If Omron doesn't violate the syntax they could do just about anything and still be within specifications. The specs are that poor. The IEC specs must assume you already know how a CASE statement works.

I hate assuming but I would assume it works like any other case, switch or select function. I would base this on Omron not wanting to answer why their CASE statement doesn't work like other case statements.

From what I have seen Omron hasn't done anything that would violate the pitiful specifications.
 
Hello LadderLogic,
Your first answer is correct.
What will happen is...
If A = 1, then when the CASE statement is executed, X will be assigned 1, A will be assigned 2.
X will not be assigned 2 until the next time that the CASE statement is executed.
And you're right Peter, (just to check my understanding) I set this up in a One Shot ST routine, took 5 mins to figure out!
Hope this helps.
 
Without any reference to any particular PLC, only one 'case' of the CASE ststement is executed in one loop, and this is decided in the very beginning. This is what is logically expected. In case of doubt on a particular PLC, run a small program in single scan mode.
 
Peter Nachtwey said:
Sometimes it is best to just try it and see. I don't understand why there are so many post about how this or that function works. It is faster to just try the function than post a question and possibly get a correct answer.

That's the way I usually do it. However, it is the weekend, I am writing (well, was writing at the moment) some code offline, and did not have a connection to a PLC to try it.

So there might be a situation when it makes sense to ask someone more experienced in this area rather that wait till Monday.

The IEC specifications are very poor.
Couldn't agree more.

I hate assuming but I would assume it works like any other case, switch or select function.
I hate assuming too, that is why I prefer not to. If I can, of course.

Thank you everyone for making this little issue clear.
 

Similar Topics

I am trying to deal with fragmented data, and have been getting stuck. So far I am able to command the Fuchs VE Software version correctly and I...
Replies
0
Views
164
Hi all, I am getting back to using IEC for schematics and was wondering about the 81346-2:2019 codes. What does everyone use for a diffuse...
Replies
3
Views
558
I just took a skim through 81346-2:2019 and was wondering which codes you all used for Safety devices like Safety Controllers, EStops, and guard...
Replies
0
Views
559
I know this is a PLC forum but there are many people from around the world that might be able to help me. I have an aspect question (IEC). I am...
Replies
20
Views
1,999
Hi everyone, I'm working on a Mitsubishi Q series PLC whose code was developed in Mistubishi's GX IEC Developer v7.04. I looked online for GX IEC...
Replies
9
Views
1,475
Back
Top Bottom