Structured Text Case Function Question

travisroberts88

Lifetime Supporting Member
Join Date
Aug 2017
Location
Navarre, Ohio
Posts
34
I am curious on something with a Case Statement in Structured Text. I am not the greatest at it so I want to know if my assumption is wrong or not.

I have an issue with a tank not aborting and I feel like I know why, but I could be incredibly wrong.

//Issue Phase Complete Command
CASE Tank1234PhaseOwner OF

1:
Tank1234PhaseOwner:=0;
PSC();

12:
Tank1234PhaseOwner:=0;
PSC();

123:
Tank1234PhaseOwner:=0;
PSC();

1234:
Tank1234PhaseOwner:=0;
PSC();

12345:
Tank1234PhaseOwner:=0;
PSC();

0:
Tank1234PhaseOwner:=0;
PSC();

END_CASE;

In my head my Phase Complete [PSC();] command will never execute and trigger the END_CASE; because the last on having a Case for 0: Tank1234PhaseOwner: =0; PSC(); will never get to PSC because as it looks at the case it will always see a Case for 0 to set it to 0 and just loop forever. Is this thinking wrong? I don't have much details on why my abort function doesn't exit but this was the only thing that looked odd to me. Without having someone try to Abort and see what it actually does I am speculating and want to see if I'm understanding it correctly or not. Thanks!
 
I am curious on something with a Case Statement in Structured Text. I am not the greatest at it so I want to know if my assumption is wrong or not.

I have an issue with a tank not aborting and I feel like I know why, but I could be incredibly wrong.

//Issue Phase Complete Command
CASE Tank1234PhaseOwner OF

1:
Tank1234PhaseOwner:=0;
PSC();

12:
Tank1234PhaseOwner:=0;
PSC();

123:
Tank1234PhaseOwner:=0;
PSC();

1234:
Tank1234PhaseOwner:=0;
PSC();

12345:
Tank1234PhaseOwner:=0;
PSC();

0:
Tank1234PhaseOwner:=0;
PSC();

END_CASE;

In my head my Phase Complete [PSC();] command will never execute and trigger the END_CASE; because the last on having a Case for 0: Tank1234PhaseOwner: =0; PSC(); will never get to PSC because as it looks at the case it will always see a Case for 0 to set it to 0 and just loop forever. Is this thinking wrong? I don't have much details on why my abort function doesn't exit but this was the only thing that looked odd to me. Without having someone try to Abort and see what it actually does I am speculating and want to see if I'm understanding it correctly or not. Thanks!


What PLC are you using? This might be platform dependent. That said:



My understanding is that case only evaluates the tag once, and then jumps to the appropriate chunk of code. It doesn't evaluate the tag again until the next PLC scan. Also, only one case can be executed each time. If you have:



Case tag of:
1:

0-4:


if the tag=1, you don't get both blocks executed, only for 1.
 
In my head my Phase Complete [PSC();] command will never execute and trigger the END_CASE; because the last on having a Case for 0: Tank1234PhaseOwner: =0; PSC(); will never get to PSC because as it looks at the case it will always see a Case for 0 to set it to 0 and just loop forever. Is this thinking wrong? I don't have much details on why my abort function doesn't exit but this was the only thing that looked odd to me. Without having someone try to Abort and see what it actually does I am speculating and want to see if I'm understanding it correctly or not. Thanks!




Not that my codesys skills even exist, but I am pretty sure that a CASE-END_CASE construct is a once through, not a loop.


So if some other code sets Tank1234PhaseOwner to 1 or 12 or 123 or 1234 or 12345, then those paths would be taken, then the END_CASE.


Note that the lines executed for whichever CASE is true are limited to those between that N: and the next NN:, without [break]s as used in e.g. C, without which C code would drop through to following NNN:s until a break is hit.



That said, all of the CASEs execute exactly the same code (set Tank1234PhaseOwner to 0 and execute the PSC() command, so this entire CASE-END_CASE construct could be replaced with just one instance of those two lines.
 
Given you are using the PSC command, I'm guessing this is a Control Logix program using Phase Manager for controlling equipment phases. You will need to provide additional detail.



Once the PSC is executed, the phase state which was active will transition based on the predefined state model of Phase manager (hint ISA-88) if you were in "running" it will transition to the "resetting" state. Once the state transitions, your "running" logic is no longer executing and the "resetting" routine will be active, waiting for another PSC command to end the "resetting" state, which then transitions back to idle.



If your case statement is in the running routine, once the PSC is triggered, the case statement will no longer evaluate the running state is no longer active. Phase manager only executes the routine of the active state. (Less any non-state routine you call via jsr in prestate routine).



I would recommend that you don't clear your phase owner tag until the resetting state is active. Use resetting to handle housekeeping duties before placing the phase back to idle.
 

Similar Topics

Good morning. I'm doing a rehab and I need to recycle some part of the old code that won't change and that I need. This is a calculation that...
Replies
22
Views
1,165
I'm writing some structured text that's handling a data structure that comes from a PC. The PC structure is in the "new" LREAL 64-bit floating...
Replies
3
Views
438
Trying to put these equations in structured text program in a Micro 830. when I run the verify I get this error. ;:expected before this new...
Replies
4
Views
394
Hey all, Studio v20.05 Background. We are piggy backing another system to record attributes for product travelling down the line and several...
Replies
21
Views
3,418
Hi, In our company (programming mainly Beckhoff PLCs) we are establishing internal coding guidelines for ST. Until now, the conventions were...
Replies
5
Views
1,017
Back
Top Bottom