Start and Return from Subroutine

Scott01

Member
Join Date
Apr 2007
Location
San Diego, CA
Posts
10
Hello all and happy new year,
its been awhile since i was here last (if at all). i'm still new to programming PLC's. i've gotten the opportunity to program an Allen Bradley MicroLogix 1000 for use in a water softener system. I've got most of the program written and tested but need to program some subroutines for certain alarm conditions. how does one start a subroutine? i already have the JSR's in place but what next? they appear to all point to "U3". any and all replies or suggestions are welcome.
 
You can use IF (Condition) THEN Subroutine, thusly:

XIC Alarm1_condition JSR 5; where Subroutine 5 contains the alarm code.

Inside the routine 5, you can use a conditional RET instruction to return to the calling routine, ignoring the rest of the routine (e.g. Alarm2 dealt with, return before checking rest of alarms), or you can place it at the end of the routine.

If you don't put a RET, the END will return control to the calling routine anyway.
It's good practice to put it there, though - not all PLCs will return automatically - they may just continue executing the next routine.
 
Hello all and happy new year,
its been awhile since i was here last (if at all). i'm still new to programming PLC's. i've gotten the opportunity to program an Allen Bradley MicroLogix 1000 for use in a water softener system. I've got most of the program written and tested but need to program some subroutines for certain alarm conditions. how does one start a subroutine? i already have the JSR's in place but what next? they appear to all point to "U3". any and all replies or suggestions are welcome.

Just remember that when you stop calling the subroutine, any bits (including outputs!) that were set remain set until you enter the subroutine again and change them. Just because the subroutine is not being scanned doesn't mean that those bits are "off". And, it follows from this that you don't want to use a coil, timer or counter in the subroutine, and then use the same coil or timer or counter again somewhere else in the program.

Sorry if you already figured that out, but those are a couple of the classic questions that come up the first time somebody uses subroutines... and then finds out that the program is no longer working!
 
Ok, so lets asume that the RET instruction is conditional also, i.e. "reset" push button. can all the bits set in the subroutine be "cleared" and then return to the main program file? (that kinda the plan)
 
You can have a conditional return in order to return from a subroutine "early".

With a ML1000 if you omit the return at the end of the file, no harm is done, the (END) rung is assumed to be a RET when encountered in any file except for LAD2.

IMHO you shouln't use conditional subroutines for actual control. They have their place for sorting routines, data manipulation and other functions, but they will be a headache for controlling real outputs...
 
I second Paul don't use them for I/O control. I usually have 1 Sub-routine for all of my alarms. All the acknowledge, clear, silence, etc. Is in that routine.
 

Similar Topics

Hello all, I am currently trying to program a PowerFlex 525, version 7.0. We had a power outage recently and when the power was restored, the...
Replies
10
Views
290
How to fix if appears code “$115 plc-restart running” on the screen OP17
Replies
5
Views
253
Hello everyone, I'm new here. First of all I just want to say that you guys are very knowledgeable and reading your posts on here has saved my...
Replies
4
Views
182
can anyone has a good program to learn plc programming online. i have the basic looking into improve my skills thanks
Replies
1
Views
149
Hi guys! I'm working in Studio 5000 and have a bunch of armorstarts there (+- 40). I need to set up parameters for each of them, mostly just same...
Replies
0
Views
97
Back
Top Bottom