MicroLogix --JMP, LBL, and RET instructions

Skidood

Member
Join Date
Oct 2016
Location
Ontario
Posts
215
Hi everyone,
I have a series of 8 or 9 subroutines that are not in the main program file (File 2)..they are all consecutively placed in Ladder 11.
As the machine does what its supposed to, in File 11, one subroutine, then the next, then the next become active processes. Currently I have an archaic way of ensuring the subroutines that are not needed do not execute (all rungs in these subs are conditional based on one bit assigned to that subroutine...(ie for example Tank Fill Active) So the processor has to scan thru all subroutines, one after the other, even though only one is going to make the machine do something at any given time.
I did it this way because I was in a hurry, did not have time to research, I was taught that conditional subroutines are a bad idea, so I chose not to put a controlling bit in front of each and every subroutine, i wanted them all to get scanned.
Now, of course, I wish to make this program scan more streamlined. Within each subroutine, I looked at putting a XIO and a RET on the first rung, (the XIO is on the bit that enables/disables the whole subroutine) but apparently according to the help files, this will cause the scan to go back to the previous subroutine. Only if the series of subroutines are actually in the main file (File 2) will a RET cause the scan to jump to the NEXT subroutine, which is what I want. Is this correct?
Also, it seems that if I use JMP and LBL, (JMP on the first rung based on the enable bit, and LBL on the last rung), that looks like it would work but LBL is an input instruction and RS500 wants me to at least put some dummy coil on that LBL rung as an output instruction just to make it happy. Is this a dumb idea even though it would seemingly solve my issue?
Any tips would be appreciated!

Untitled1.jpg
 
The XIO and the RET on the first rung of the subroutine doesn't seem more streamlined to me as opposed to a condition ahead of the JSR. I guess I don't subscribe to the thought of not having conditions ahead of the JSR. Unless "more streamlined" is referring to appearance instead of performance. But in the end, either method should work just fine. If the XIO condition is true, it would return and none of the logic below it would execute. That is probably cleaner than using the JMP/LBL combo.

As for the JMP and LBL, yeah that works too. On the last rung I would place the LBL with another RET instead of a dummy coil.

OG
 
Last edited:
The XIO and the RET on the first rung of the subroutine doesn't seem more streamlined to me as opposed to a condition ahead of the JSR. I guess I don't subscribe to the thought of not having conditions ahead of the JSR. Unless "more streamlined" is referring to appearance instead of performance. But in the end, either method should work just fine. If the XIO condition is true, it would return and none of the logic below it would execute. That is probably cleaner than using the JMP/LBL combo.

As for the JMP and LBL, yeah that works too. On the last rung I would place the LBL with another RET instead of a dummy coil.

OG

Thank you. The Instruction Set manual clearly indicates that after a RET the scan will move on to the NEXT subroutine, which is not exactly what the online help file in RS500 said. And yes this was for performance not appearance. Cant stand the idea of the processor evaluating maybe 80 rungs for nothing when it could be just looking at literally one.
 
It would be easier if you posted the code in a pdf

But let me see if I understand
1. The main routine (LAD 2) has a JSR to call the "wrapper" subroutine LAD 11
2. The wrapper subroutine comprises several rungs, each with a JSR that calls one of the other subroutines.
3. Each of the other subroutines should either have it's rungs evaluated, based on the value of a bit assigned to that subroutine.

You are concerned that a RETurn statement from those other routines, two JSR calls below LAD 2, will return to the "main" routine i.e. to LAD 2, because the help says "main"

Am I close?


Thank you. The Instruction Set manual clearly indicates that after a RET the scan will move on to the NEXT subroutine, which is not exactly what the online help file in RS500 said.


See this:
Untitled1.png
 
Thank you. The Instruction Set manual clearly indicates that after a RET the scan will move on to the NEXT subroutine, which is not exactly what the online help file in RS500 said.

First, subroutines always return to the next instruction after the calling JSR. Doesn't matter if you use a RET or the scan reaches the end of the ladder. The only exception to this is an an instruction called a Temporary End (TND) which causes nested subroutines to return back to the main ladder. I am looking at the Nov 2008 Instruction Set Reference Manual and I am not seeing what you say it says. Perhaps there is a different version that says differently.

When a RET is not in a nested subroutine, the scan will return to the next instruction after the calling JSR in the main ladder (LAD 2).

When in a nested subroutine the scan will return to the next instruction after the calling JSR in the previous subroutine. So if LAD 2 calls LAD 11 and then before reaching the end of LAD 11, LAD 11 calls LAD 12, and then a RET is encountered within LAD 12, you would return to LAD 11. It would not return to LAD 2.

OG
 
I used conditional subroutines with my train project. Each subroutine is a train operation and depending on what I select on the HMI, it jumps to that routine. Now I have what I call two types of operations. One is endless, the other is single run. Endless operations will execute until either an alarm condition pops up, or I select a different operation on the HMI. Once I select a different operation, a flag is set to tell the endless routine to end so the next one will execute.


Mike

Capture.JPG
 
First, subroutines always return to the next instruction after the calling JSR. Doesn't matter if you use a RET or the scan reaches the end of the ladder. The only exception to this is an an instruction called a Temporary End (TND) which causes nested subroutines to return back to the main ladder. I am looking at the Nov 2008 Instruction Set Reference Manual and I am not seeing what you say it says. Perhaps there is a different version that says differently.

When a RET is not in a nested subroutine, the scan will return to the next instruction after the calling JSR in the main ladder (LAD 2).

When in a nested subroutine the scan will return to the next instruction after the calling JSR in the previous subroutine. So if LAD 2 calls LAD 11 and then before reaching the end of LAD 11, LAD 11 calls LAD 12, and then a RET is encountered within LAD 12, you would return to LAD 11. It would not return to LAD 2.

OG

Yes, thanks so much OG...all is good...I got confused by the help text in RS500 referring to nested SRs and not knowing exactly what nested subroutines are. I only focus on PLC stuff sporadically and I'm not as sharp as I used to be. My program calls up LAD 11 from Lad 2, then in LAD 11 that is where the series of consecutive JSRs are. Appreciate your help, I know you have helped me in the past too.
 

Similar Topics

Hello again, Happy New Year. If the bit controlling this subroutine switches off, causing the JMP and LBL instructions to take effect, will the...
Replies
3
Views
328
Hey all, first time poster here. I am wondering if anyone has tried using a Keyence SR-X300 barcode scanner to a Micrologix 1400. Keyence sent...
Replies
0
Views
34
I have been working on this for a while now and I can't seem to get it. I was finally able to view the 1500 on the PanelView under the serial...
Replies
1
Views
85
I'm using a SLC typed write from the ControlLogix5572 to the MicroLogix 1400, with path: 2, (MicroLogix IP). The ControlLogix equipment has a...
Replies
0
Views
97
"Hello! Good day! Excuse me, I have a question regarding the 1761-NET-ENI. RSLinx has already detected it but it's not connecting to the PLC...
Replies
4
Views
134
Back
Top Bottom