Nesting Subroutines
daba said:
Geospark said:
Also, the JSR instruction should only be used in the MAIN ladder file, as this file is always scanned.
G.
That is incorrect, the JSR instruction
can be used anywhere, in any program file. Subroutine files can call other subroutine files (nesting)...
daba,
While I am aware of the different methods. I just didn't make my point clear enough, and having re-read my statement I can see it as misleading alright.
I was only pointing out to shahid_6673 that for
his program, as it is using the typical method of all the JSR's in the MAIN file, his JSR's should only be placed in the MAIN routine so all the subroutines will be called. I didn't mean it as a general statement, but it could quite easily be read that way.
Thanks for pointing that out to me.
However,
daba said:
...the JSR instruction can be used anywhere, in any program file...
This is 'slightly' incorrect.
Nesting Subroutines...
For RSLogix 5000 (Studio 5000) based controllers, there is no restriction, other than controller memory, on the number of nested subroutines you can have. So you can place a JSR instruction in any subroutine file.
For RSLogix 500 based controllers...
From the MAIN routine file you can JSR to 8 levels of nested subroutines for all SLC and MicroLogix controllers (only 4 for SLC5/01). One could place a single JSR in the MAIN routine to jump to the first subroutine, then place a JSR at the bottom of that subroutine to jump to the next, and so on, with the 8th level nested subroutine's RET (Return) instruction jumping back to the MAIN routine. The order of subroutines scanned need not be sequential to the subroutine file numbers either.
However, you cannot place a JSR instruction in the 8th level nested subroutine file or the PLC will fault for a
Subroutine Stack Overflow error. You must only place a RET in the last nested subroutine file to return to the MAIN routine file.
If using a Selectable Timed Interrupt Subroutine (STI), Discrete Input Interrupt Subroutine (DII), I/O Event-Driven Interrupt Subroutine, User Fault Subroutine, or High Speed Counter Interrupt Subroutine (HSC - ML1000 only), you can only nest up to 3 levels of subroutines. The 3rd subroutine file also being restricted from using a JSR instruction.
I suppose we should all be more careful when making statements without thinking them out fully.
G.