Using Subroutines in RS Logix 500

studentplc1

Member
Join Date
Feb 2010
Location
Canada
Posts
29
Hey guys,

I have a PLC program in RSlogix500 for one of the machines in my plant area. I was looking through the program for it and saw that many of the subroutines (ex. LAD 3, LAD 4 etc.) do not have the "SBR" (Subroutine indicator in the beginning) and "RET" (Return indicator at the end). I was wondering are these not necessary? Of course the machine runs fine so it seems like it isn't really needed.

(I am just a student and from what I learned, the SBR and RET commands should be used with the JSR command in the "main" routine).

Any comments? Thanks...
 
Subroutines are often used to break a large program into sections. In this case, there would be a JSR instruction for each subroutine in the main program, with no logic preceding it so that it runs every scan. The SBR and RET instructions are not necessary in this case.

For more advanced applications, subroutines can be called conditionally, but this requires caution as certain instructions may not behave as you expect. A good example of this is the OTE coil, which will hold its most recent state if the containing subroutine is not being executed. SBR and RET are still not required, but RET can be used to conditionally exit a subroutine early.
 
as you said, these instructions are not really necessary in order for the Subroutine to work correctly ...

in some (pretty rare) cases, the RET comes in handy because you can put it on a "conditional" rung – and then have the ladder execution "skip" the remainder of the Subroutine file if the condition is TRUE ...

in RSLogix500 the SBR serves no useful function – but my guess is that it's included in the instruction set because some programmers are so used to putting one at the top of every Subroutine file "just because" ... (in other words, it's just a "feel good" thing) ...

going further ...

in RSLogix5 and RSLogix5000 the SBR and the RET instructions can be used to "pass parameters" to and from the Subroutine file – and in those cases the system won't work without them ...

so ...

Question: in RSLogix500 do you NEED the SBR and the RET to make a Subroutine file execute correctly? ....

Answer: no, you do not need them ...

Question: will they "hurt" anything if you include them?

Answer: no ... of course they take up a SLIGHT amount of extra processing time, but nothing that you need be concerned about ...

PS Edit: well, it looks like I've got to type faster if I want to get ahead of my distinguished colleagues ... answer posting time: 1:58 ... 1:58 ... 1:59 ... you certainly can't complain about the service around here ...
 
Last edited:
Yes, definitely cannot complain about the service, that is why I posted it here.

By the way, when you say "pass parameters," do you mean that if I use an OTE (Light 1 - on) in one sub routine and the XIC/XIO (IF light on/off) in the main routine, I should use the return (RET)?

If that is what you mean't then why? Won't it go back to where it left off anyways? So how is the RET useful if the program will go back to where it left off in either case?
 
Or did you guys mean that you use JSR in the main to go to subroutine then get some data, return back to main use that data, the JSR again to that subroutine to complete the routine and then go back to the main to complete the program :S??
 
in simplest terms, to "pass parameters" to a Subroutine, the JSR will list an Input Parameter – and a Return Parameter ...

an example:

suppose that our Input Parameter is F8:0 which contains 212.0 and represents 212 degrees F ...

the value is "passed" to the SBR at the top of the Subroutine file ...

suppose that the Subroutine file then does the math steps required to convert the Fahrenheit reading into its equivalent in Centigrade ...

the RET instruction at the end of the Subroutine then "passes" the resulting value to F8:1 – which will then contain the value 100.0 and represents 100.0 degrees Centigrade ...

one advantage to this approach is that the "math" only has to be programmed ONCE – and then it may be used repeatedly by having numerous JSR instructions "call" the Subroutine file – and having each JSR "pass" a different parameter (value) to be converted ...

specific answer to one of your specific questions:

in general, OTE instructions do not "fit" into the "passing parameter" mold ...

survival tip: don't worry about "passing parameters" until you move onward/upward from RSLogix500 ...
 
Last edited:
alright, thanks Ron and the rest who replied.


Edit: I am thinking about it and I want to know now how it would look..haha

is it possible for someone to show me how a simple program would look to pass parameters? or if there is a link I could go to..
 
Last edited:
You can pass many parameters but not directly to the routine.
To do this set aside some temp bits & words like N7:0-100 etc.
create a routine say a function that controls a valve just before the call move data to the temporary variables used in the sub i.e. time values, i/o bits to temp B bits then call the routine that uses the temps
after the call move the temps back to the bits/words.
i.e.
A I:0/0 = B3:0/0
& so on
Mov N7:100 N7:0
& so on
JSR file 10
A B3:0/1 = 0:1/0
mov N7:11 N7:101
this is only useful if the function contains lots of code say a valve or motor control block
You write only one then call it many times just pass all the variables before for the control then return them afterwards.
I have used this when modifying an existing system where there was virtually no memory left, by creating standard functions where the code had been written many times it reduced the memory enough to allow the additions.
We passed 20 variables most to the fnction & a couple back
The actual function was a few k long so saved a fair bit compared to long hand code.
 

Similar Topics

Hi to all, I have been using Allen Bradley RsLogix 500 software for over 12 years in which, when I change or write programs, I kind of hack at...
Replies
10
Views
4,314
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
2
Views
20
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
6
Views
143
Hi, I'm trying to use the IO Device Library (Product Versions) which is configured to work with the 1756-EN4TR & 1756-EN2TR but my system uses...
Replies
0
Views
48
Hello, As part of our project, we are using an M241 controller. This controller interfaces with an industrial computer and a router via a switch...
Replies
2
Views
91
Back
Top Bottom