Need help with SCL REPEAT structure

chauvinhloi

Member
Join Date
May 2012
Location
Ho Chi Minh City
Posts
10
Hello everybody ^^ I'm programming a FESTO MPS with PLC S7-300 (315-2DP) using the SCL and I have a problem here. When I'm using the loop structure like REPEAT, WHILE... the PLC has fault and STOP. But If I change that loop structure... by IF statement (different structure but it has the same meaning), everything is OK and the PLC has no fault. Here is the code:

//----USING REPEAT STRUCTURE-----
FUNCTION reset_all: VOID
REPEAT
arm_release:=TRUE;
UNTIL release_pos=TRUE
END_REPEAT;
END_FUNCTION
//-----------------------------------

//----USING IF STATEMENT----------
FUNCTION reset_all: VOID
IF release_pos=FALSE THEN
arm_release:=TRUE;
ELSE
arm_release:=FALSE;
END_IF;
END_FUNCTION
//-----------------------------------

In the first one, I used the REPEAT structure and the PLC had fault. In the second one, I used IF statement and it has no fault at all.

I think it cause the PLC scan the program by cycle and when the scanning "meet" the loop structure, it's catch by the loop (like catch in the cyclone when moving on the river). The scanning can not move forward although the loop will end when its condition is satisfied so the PLC has fault.

I tried to insert the OB 80, OB 85, OB 121 to the block but it can not fix the problem :(

Does anyone have the solution for it or help me find out the reason for this fault? :(
 
This is bad practice in PLC programming.

In this case your loop will keep on going until the end of time.
Why?
Because this will never ever ever happen: UNTIL release_pos=TRUE


As long as you're in the loop, the PLC won't update it's IO-table and therefor it'll never see the change in status from any input.
As long as you're in the loop, you won't be setting any outputs either, meaning ALL the outputs retain their state.
Which can be very very very dangerous.

The reason the PLC faults is because the Scan cycle has crossed the Scan cycle monitoring time.
 
Wow, I see that, that's a big mistake and thank Jeebs has shown me that. So we can use the loop only for processing the "internal" variable which is independent of IO, is it right?
Now I know the reason why the loop has never been used in the Conveyor example of HANS BERGER.
PS: I'm just the beginner in SCL Programming, I hope I could learn more and I really love this forum ^^
 
Last edited:
It still depends.
The variable that triggers the end of the loop should be processed within the loop.
If not then the loop will continu forever.
 

Similar Topics

Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
267
Hey guys, Before of all, congratulation for this wonderful forum. The comunity have help me a lot in the last months so I have decided to post...
Replies
6
Views
4,878
Hello, I am programming in S7-1500, V17. I have some blocks from a drive manufacturer that are not compiling and giving me an error "Invalid...
Replies
2
Views
273
Hi all, I’m new to programming and want to write a simple routine. Push start button, turns on sensor. 2 second delay before anymore logic read...
Replies
1
Views
289
Back
Top Bottom