CASE used with IF THEN logic

heypauly2002

Member
Join Date
May 2017
Location
Santa Clara
Posts
3
Hello PLC group,

Hope you all had a wonderful Father's Day.

Has anyone seen CASE used like this.

CASE DcupLD_Step OF

1: _IO_EM_DO_11 := TRUE; (* turn on output to drive Z down, go to next step *)
DcupLD_Step := 2;

2: IF _IO_EM_DI_12 THEN (* Z down LS on, time to turn on vacuum to pick part *)
_IO_EM_DO_12 := TRUE; (* turn on vacuum *)
DcupLD_Step := 3;
END_IF;

3: IF _IO_EM_DI_17 THEN (* DcupLoad_VacuumOn is TRUE, part is on pick up tool *)
_IO_EM_DO_11 := FALSE; (* send Z up with part *)
DcupLD_Step := 4;
END_IF;

4: IF _IO_EM_DI_11 AND NOT _IO_EM_DI_15 THEN (* DcupLoad_Z_Up AND part removed from singulator *)
_IO_EM_DO_10 := TRUE; (* send Y out with part on tool *)
DcupLD_Step := 5;
END_IF;

5: IF _IO_EM_DI_14 THEN (* Y is out, Y out LS is ON, and ready to send Z down *)
_IO_EM_DO_11 := TRUE; (* send Z down with part on tool into the nest *)
DcupLD_Step := 6;
END_IF;

6: IF _IO_EM_DI_12 AND _IO_EM_DI_16 THEN (* Z is down and part is in the nesting *)
_IO_EM_DO_12 := FALSE; (* turn off the vacuum, drop off the part *)
DcupLD_Step := 7;
END_IF;

7: IF NOT _IO_EM_DI_17 THEN (* no vacuum, part is released, time to send Z up *)
_IO_EM_DO_11 := FALSE; (* send Z up without part *)
DcupLD_Step := 8;
END_IF;

8: IF _IO_EM_DI_12 AND _IO_EM_DI_16 THEN (* Z is up and part is in the nesting, released from tool *)
_IO_EM_DO_10 := FALSE; (* send Y back to home position *)
DcupLD_Step := 9;
END_IF;

9: IF _IO_EM_DI_13 THEN (* Y is at home position, ready for next cycle *)
DcupLD_Step := 0;
END_IF;

END_CASE;

??? I was trying to compact my decision making step/sequence logic IF THEN with my output section. The outputs would normally be a part of CASE. CASE SubStation_Step OF...
 
I do this for many sequential state operations. Easy to follow, debug & this one is well documented.

What's the question?

Ken
 
Ken,

I'm a bit new to Structured Text and have not found any examples/samples of CASE done this way. I very happy to hear someone else has tried this approach. That was what my goal, to create a simple sequence code that could be understood and used over and over.

Thank you for your reply.
Paul
 
I haven't seen it used in PLC code, but I've used it frequently in VB and similar structures, and I imagine it's the same. Looks like you understand the idea: the code checks the value of "DcupLD_Step", and then what follows is a list of what to do in the case that its value is 1, 2, 3....9.

Generally in VB you also have a "Case Else" at the end, which specifies what to do if the value is none of the above values - I don't know if that's possible in the PLC you're using, and if it's well-coded there's technically no need for it - but I'd be putting it in anyway just as a "f***up detector". Perhaps reset the sequence and go back to home position if we find ourselves in an unknown state, or something like that.
 
I use structured text a lot, it is much cleaner for a lot of processes. BUT, I try to be very conscientious of the maintenance staff. If they're extremely low skilled (this might seem counter intuitive) I feel free to use it a lot. They aren't going to be doing online trouble shooting, so I'll program however it suits me. If they're standard skilled, state machines and similar always go in ladder, they'll be much more comfortable trouble shooting issues.
Even if I'm working with highly skilled maintenance I'm leery about doing state machines (especially long/complex ones) in ST. It's just faster to discover the issue with "pilot lights" (green or red highlighting for true).
Regardless, I truly appreciate the people here endeavoring to right clean, consistent logic...
 
I was experimenting with ST and Codesys last year, and came up with something similar for sequential logic. One routine controlled the transitions, other routines controlled the actual outputs.

Transitions, note that these were just timed steps to work out structure:
Code:
CASE StepEngine[1].Step.current OF
    // ***********************************
    1: // Initialization (required)
    // ***********************************
        // Setup step Timer
	StepEngine[1].Step.timeSP := T#1S;
	StepEngine[1].Step.timeEN := TRUE;
	
	// Step Advance Conditions
	IF StepEngine[1].Step.timer.Q
		OR StepEngine[1].Step.ahead	THEN
		StepEngine[1].Step.next := 10;
		StepEngine[1].Step.end := TRUE;
	END_IF
				
    // ***********************************
    10: // Open Route # 1 Path
    // ***********************************
        // Setup step Timer
	StepEngine[1].Step.timeSP := T#1S;
	StepEngine[1].Step.timeEN := TRUE;
	
	// Step Advance Conditions
	IF StepEngine[1].Step.timer.Q
		OR StepEngine[1].Step.ahead THEN
		StepEngine[1].Step.next := 20;
		StepEngine[1].Step.end := TRUE;
	END_IF
		
    // ***********************************
    20: // Transfer Raw Material #1 - Fast
    // ***********************************
	// Setup step Timer
	StepEngine[1].Step.timeSP := T#30S;
	StepEngine[1].Step.timeEN := TRUE;
	
	// Step Advance Conditions
	IF StepEngine[1].Step.timer.Q
		OR StepEngine[1].Step.ahead THEN
		StepEngine[1].Step.next := 30;
		StepEngine[1].Step.end := TRUE;
	END_IF

Another routine handled the corresponding valve control:
Code:
// *****************************************************************
// Step Valve Activations
// *****************************************************************
//
CASE StepEngine[1].Step.current OF
    // ***********************************
    1: // Initialization
    // ***********************************
	
    // ***********************************
    10: // Open Route #1 Path
    // ***********************************
	// Valve Activations
	SV101.progOn := TRUE;
	SV2101.progOn := TRUE;
	SV2110.progOn := TRUE;
			
    // ***********************************
    20: // Transfer Raw Material #1 - Fast
    // ***********************************
	// Valve Activations
	SV101.progOn := TRUE;
	SV2101.progOn := TRUE;
	SV2110.progOn := TRUE;

I was happy with it, started to give all the code a similar feel.
 
Last edited:
Paully'5.0, AutoMax, thank you for responding. I'm a mechanical engineer who early on, came to appreciate the value of programming. On the other hand I didn't focus on programming, its just not what I am good at. So it was nice to hear I came up with code others are using. There is an ELSE statement. If the step counter got the wrong value in it then something is really messed up so I left it out. Maybe I'll put it back in.

Thanks so much,
Paul
 

Similar Topics

I figured I’d share my story of a Micro830 that I was banging my head on the wall over in case anyone ever runs into a freak fluke like this. I...
Replies
3
Views
2,016
Hi everyone, new user so please forgive any breaches of etiquette. But in RSLogix how can you convert a string in the PLC to all lowercase and...
Replies
4
Views
1,493
Hi all, I am facing issues with communication to the TruOne ATS of ABB via plc. Plc is M251 of SE. Majorly 2 issues: 1- writing to the modbus...
Replies
5
Views
1,613
Hello everyone, I have recently started a new project using ST in Studio 5000. Previously, I have programmed in ST in Siemens. As i was writting...
Replies
4
Views
2,882
Hello everyone, I have recently started a new project using ST in Studio 5000. Previously, I have programmed in ST in Siemens. As i was writting...
Replies
1
Views
1,393
Back
Top Bottom