Help - Search - Members - Calendar
Full Version: Subroutine Instructions
Forums.MrPLC.com > PLCs and Supporting Devices > Allen Bradley
kevinprior
Hello,
Is the subroutine instruction really necessary? obviously the JSR is required but what is the real purpose behind putting a subroutine at the start of the subsequent ladders, is this just good practice. I have used programs with this being used and also other programs with this not in at all.
Also having an unconditional coil at the start of each subroutine is another one, the ladder normally goes a subroutine instruction and then a coil say B99:.. is there any real reason behing this. apart from having this as an always true to be used later in the program. Or is this a difference between programming methods on logix 5 and logix 500?
shrug.gif
Spedley
I havn't used SBR in years. I remember that it caused problems with online edits and as far as I can tell it has no explicit use.
Sleepy Wombat
Some programers use the SBR to break up there code into sections, that is the first section will have some initialiastion code and then call the SBR's in the order they want the program to run.

Secondly, the use of the B99 coils was one, it is way out of the way and is used to enable you to provide a rung comment and a point to search to. There is no easy navigation when jumping between sections of SBR's therefore if you allocate a descritptive name to the coil that relates to the SBR then you can search for this coil and how there's the code... Very useful on large programs.

I have mainly seen this done in a large program for an SLC.

These methods allow you to over come certain restrictions where as in later models and other brands you don;t neeed to do this....
Alaric
If you want to pass some parameters to the subroutine, then the SBR and RET instrucitons are required. Otherwise they are not necessary.

In the SLC500 you cannot pass parameters to your subroutines, so the SBR instruction serves no purpose, and the RET only gives you a method to exit the routine before the END rung.

In PLC/5 and ControlLogix processors the instructions are required if you are passing values into a routine and/or returning values from the routine. If you are not passing values then they are optional. Subroutines with parameters are ueful for object oriented and reusable code.


Spedley
That would make sense Alaric. I never thought of that but then again, I've only ever used PLC5's once.
Chris Elston
I agree with Sleepy. I only use them to break up my code so I can find a section of the machine faster. I use them no other way.

See an example of my code here:
http://forums.mrplc.com/index.php?act=Downl...s&CODE=02&id=19

It breaks up each of the stations I have on an index table.
Spedley
I searched your code chakorules but could not find any SBR instructions? Do you mean JSR?
jstolaruk
From RSLogix Help on the SBR instruction:

"Use a subroutine to store recurring sections of program logic that must be executed from several points within your application program. A subroutine saves memory because you program it only once.

Update critical I/O within subroutines using immediate input and/or output instructions (IIM, IOM) especially if your application calls for nested or relatively long subroutines. Otherwise the controller does not update I/O until it reaches the end of the main program (after executing all subroutines.)
"

"Placed as the first instruction in a subroutine file, the SBR instruction identifies the file. This is the file number that is used in the JSR instruction to identify the target to which the program should jump.
This instruction has no control bits. It is always evaluated as true. The instruction must be programmed as the first instruction of the first rung of a subroutine. Use of this instruction is optional, but recommended."
Alaric
Here is an example of a SBR instruction used in a control logix processor. There is a UDT defined to create an object for each of the press's several dozen hydraulic solenoid valves. This subroutine exists only once in the program but it is called multiple times. Each solenoid valve object is passed to the routine, which processes it, then passes it back out to the main program. If you are only familiar to the SLC then this might seem a little strange to you, as well as the way the ladder is arranged, especially the serial rung outputs instead of parallel outputs.
Chris Elston
Spedley,

Crap...your right. sorry about that. Didn't have my monday morning mountain dew yet...I mean TUESDAY...

But still I use JSRs to make "sub-routines" to seperate code.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.