Subroutines in Mitsubishi GXWorks 2

Join Date
Jun 2013
Location
Colorado City
Posts
20
I am trying to do a subroutine using a Q series (Q06UDEH) plc and GXWorks 2. The manual says to use a FEND and then start the subroutines. Each subroutine (started after then FEND statement) has a return statement. Whenever I make a call to a subroutine I get fault 4211 that a FEND was encountered after a CALL and before a return was encountered.

One thing that looks interesting is when I display compile results, my return statements are compiled as JMP P2069, and P2069 is the pointer shown in the compile result of the last line of the last rung of code. It looks like a return statement is not being compiled as a return, but jumping to the end and maybe hitting into a hidden FEND. I have found that I cannot get an error 4212 by putting a return statement near the start of the code (before the FEND), and the manual says error 4212 will result if return is encountered before FEND. It just happily quits scanning that routine, the same as if I had put a FEND there.

Anyone know what I am doing wrong? I am trying to use structured ladder. It needs to not think return and FEND are the same thing.
 
When I type in RET from the keyboard for the instruction, this behavior occurs, but when I drag a RET statement from the function list into the ladder, it behaves as I would expect it to behave. In the PNG file, the first return is what I get when I type "RET" from the keyboard, and acts the same as a FEND. The second RET is what I get when I use the element selection window to insert a "RET" and it works.

return.png
 
I'm not sure how it differs in structured ladder, but in regular ladder to perform a subroutine you have to first call it with a pointer.

X0--------[CALL P1]....for example.

Then, at the end of the ladder, before the END instruction you would have a FEND instruction.
After the FEND instruction, you pointer code is written with the pointer number on the outside of the ladder on the left.
When the subroutine is finished you will need a SRET command to return to the other code. The END instruction comes at the end of everything.
I attached screenshots. The first "subroutine" I have is actually an interrupt pointer but is the same idea.
Hope this helps,

Dave

pointer example1.jpg pointer example2.jpg pointer example3.jpg
 
Thanks. For those quick browsing, the question has been answered. In structured ladder, return is handled differently if typed in vs pulled in from the element selector window. For subroutines, one cannot type in return from the keyboard.
 

Similar Topics

I have been asked to extensively modify a piece of machinery that is very mission critical to the operation, thus not allowed much downtime or...
Replies
4
Views
2,279
We have an application where we need to indicate a piece of machinery needs maintenance. I have created a routine which resets a value of "days...
Replies
12
Views
3,716
Hi all. Please see attached. Tried to google the error with absolutely no results. I did the same at payed version and real PLC so I'm almost...
Replies
7
Views
2,334
hello all is there a rule of thumb as to using or not using subroutines when writing a program ? i am using an Allen Bradley slc 500 thank you...
Replies
5
Views
1,729
All, Using RSLogix 5000. I was wondering if there is a way to quickly check to see if all subroutines are being called by the Main Routine (in...
Replies
3
Views
1,591
Back
Top Bottom