Sign in to follow this  
Followers 0
nednor

The Case-statement in STL

3 posts in this topic

I'm trying to implement a state machine in STL in a CJ2, but I'm having a hard time debugging my code as I'm not especially good at STL. I'm using the CASE statement to switch states, but the program won't switch to the 3rd state, and only jumps between 1st and 2nd state.

CASE iStateVekt OF
	(*Prefill*)
10: IF (rVektAvlest < iPrefill) AND (bVektLukket = TRUE) THEN
			bHurtig := TRUE;
			iStateVekt := 20;
			iStateOut := iStateVekt;
	END_IF;
	
	
		(*Stopper prefill*)
  20: IF (rVektAvlest > iPrefill = TRUE) THEN
	  bHurtig := FALSE;
	  iStateVekt := 30;
	  iStateOut := iStateVekt;
	END_IF;


(* Fyller vekt*)
30: IF bNykasse = TRUE THEN
	IF (rVektAvlest < rTarget - 5) = TRUE THEN (*Fast fill *)
		bHurtig := TRUE;
		bSakte := FALSE;
	END_IF;
	IF (rVektAvlest > rTarget - 5) AND rVektAvlest < rTarget = TRUE THEN (*Slow fill*)
		bSakte := TRUE;
		bHurtig := FALSE;
	END_IF;
	
END_IF;
iStateVekt := 40;
iStateOut := iStateVekt;


40: IF rVektAvlest >= rTarget AND bBufferFull = FALSE AND bBufferLukket = TRUE THEN
		bSakte := FALSE;
		bÅpneVekt := TRUE;
		IF rVektAvlest < 1 AND bVektÅpen = TRUE THEN
			bÅpneVekt := FALSE;
			bBufferFull := TRUE;
			iNtøm := iNtøm + 1;
			iStateVekt := 50;
			iStateOut := iStateVekt;
		END_IF;
END_IF;
                          
50: IF iNtøm >= iNtare THEN
	bTare := TRUE;
	iStateVekt := 10;
	iStateOut := iStateVekt;
ELSE
	iStateVekt := 10;
	iStateOut := iStateVekt;
END_IF;
	
ELSE 
	bWaiting := TRUE;
END_CASE;

CASE iStateBuffer OF
	
	10: IF bBufferFull = TRUE AND bKasse = TRUE THEN
		bÅpneBuffer := TRUE;
		IF bÅpneBuffer = TRUE AND bBufferÅpen = TRUE THEN
			bÅpneBuffer := FALSE;
			iStateBuffer := 20;
		END_IF;
	END_IF;
	
	20: IF bBufferLukket = TRUE THEN
		bBufferFull := FALSE;
		iStateBuffer := 10;
	END_IF;
	
END_CASE;
	
		

 

casestatement.thumb.JPG.14de5a558b83da41

As the picture shows the variable rVektAvlest is +5 and the iStateVekt is 20. If I increase the rVektAvlest to 196 or more it should as far as I can see set iStateVekt to 30. But this does not happen, instead it changes to 10. and is stuck there until it gets lower than 195.

Does anybody have any idea whats wrong here?

Share this post


Link to post
Share on other sites

The circled portion is not inside any IF statement, so as soon as you go to state 30, it immediately goes to state 40. And per the symptoms you've described, it seems from state 40 it also goes straight to state 50, which sets it back to state 10. And all this happens way too fast for you to see.

20180331_202859.png

Edited by strantor_

Share this post


Link to post
Share on other sites

I have tried to puter it inside the OF-statement with no luck. That was the way I did it in the first place. The prosess is supposed to wait for input at stage 30.

I have also tried to experiment with paranteses in the conditions for the IF-statments.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0