Using JSR with no parameters

unsaint32

Member
Join Date
Oct 2012
Location
minneapolis
Posts
365
I found a ladder program that uses JSR instructions with no input or return parameters. And none of the subroutines it calls for have SBR and RET instructions.

I always thought a subroutine has to have SBR and RET for the JSR instruction. I guess I was wrong.

So, without the SBR and RET, the subroutine scan begins at the top and ends at the bottom before returning to the program that called the subroutine, for ladder and SFC?
 
I found a ladder program that uses JSR instructions with no input or return parameters. And none of the subroutines it calls for have SBR and RET instructions.

I always thought a subroutine has to have SBR and RET for the JSR instruction. I guess I was wrong.

So, without the SBR and RET, the subroutine scan begins at the top and ends at the bottom before returning to the program that called the subroutine, for ladder and SFC?

This is how it is for MicroLogix at least (and the other Logix500 controllers too, I bet).
 
Would there be any situations where I want the subroutine scan to cycle more than once then return to the main program that had the JSR instruction? Let's say the subroutine's last rung is a counter, so every scan cycle adds 1 to the counter ACC, and I want to run the subroutine until the count ACC = 5. I guess I can change the main program insead to keep activating the JSR until the counter DN goes high.

Thanks for the replies guys.
 
Since you are talking about parameters I'm assuming that you are using a ControlLogix platform. On a ControlLogix platform there is a FOR instruction, which executes a subroutine a predetermined number of times. It does this in a single scan, which might not be what you want.

If you want to do it across multiple scans then keep in mind that a counter must see a false to true rung transition. It will not count again until the rung goes false, then true again. One way around that is to unconditionally unlatch the .CU bit immediately after the CTU instruction. If you don't do that then the counter is going to stick at one and grbadley is gonna loose his bet.
 
Last edited:
Related:

Performing multiple calls of a subroutine with an incrementing index value is the purpose of the "FOR" instruction in ControlLogix.

I always have to experiment with the Index value to be sure it's doing what I expect, but the FOR instruction is a handy way to do iterative subroutines.
 
For anyone reading this thread later......

Sometimes programmers will include the SBR and RET instructions simply for clarity. So someone looking at the logic will know that this (SBR) is where the subroutine starts scanning, and here (RET) is where it ends and goes back.

Sometimes the RET may also be located mid-routine with a condition ahead of it. When the RET rung is true, then return now, else continue to the END.

OG
 
Since you are talking about parameters I'm assuming that you are using a ControlLogix platform. On a ControlLogix platform there is a FOR instruction, which executes a subroutine a predetermined number of times. It does this in a single scan, which might not be what you want.

If you want to do it across multiple scans then keep in mind that a counter must see a false to true rung transition. It will not count again until the rung goes false, then true again. One way around that is to unconditionally unlatch the .CU bit immediately after the CTU instruction. If you don't do that then the counter is going to stick at one and grbadley is gonna loose his bet.

Yes, my work uses CLGX5K, but the problem is that they don't trust me, a maintenance person, so it's just the Service Edition, which has no program edit capability, so I cannot really practice programming although I'm trying my best to learn.

The first chance I get, I will study the "FOR" instruction and unlatching the CU bit. Thanks.
 

Similar Topics

Hello, I please need your help why I cannot get the return parameter from the RET instruction to go into the return parameter in the JSR return...
Replies
6
Views
2,847
Hi I'm very new to PLC programming and I'm trying to find out if this library (Tc2_NcFifoAxes) is necessary for our task In our case we need to...
Replies
0
Views
38
I have a project to automate four generator sets. The system will monitor and store the load demand of the factory. Once there's Power outage, the...
Replies
0
Views
83
Adding ethernet equipment to an existing panel that has none. We have some solid ethernet cables coming from other remote cabinets that I plan to...
Replies
3
Views
138
I'm trying to control a device via MODBUS RTU and the ModbusRtuMasterV2_PcCOM in Twincat 3. I've configured a device with the right com port and...
Replies
7
Views
260
Back
Top Bottom