A/B subroutines

maintpro

Member
Join Date
May 2003
Location
Osceola, IN
Posts
28
Just a quick question regarding output control via subroutines.

In an Allen Bradley SLC/500 or Micrologix system what is the best way to control outputs when using subroutines since the outputs remain in thier last state when the subroutine becomes inactive?

Also, do the internal relays (bits) remain in the last state as well?
 
I find that calling subroutines in ABs can be a bit unpredictable. I generally organise my program with subroutines but scan them all of the time. To turn off outputs use the MCR instruction.

If you have to call a subroutine then ensure that your program takes care of the outputs and bits outside of the subroutine to ensure that they are in the state you want them to be. What I do is use dedicated bit words for subroutines and when I stop the subroutine then I set the bits in the word to what I want them to be when the subroutine is not scanned. This way I know that bits are not left set if the subroutine is not scanned. If you need to know if a subroutine has completed an operation then latch a bit flag in the subroutine and monitor and re-set it elsewhere in the program.

Bits do not change state in a subroutine that is not scanned. However a latched bit will change state if used elsewhere in the program.
 
You can control the same outputs from different subroutines. Just make sure that only one subroutine is active or else the outputs will
behave in unpredictable fashion.
You can also use unlatch coils in your main program to take care of
outputs turned on in a subroutine that's no longer active.
 
just some basic ideas ...

Greetings, Mike,

this particular question comes up rather often ... usually it means that someone with a background in “structured” programming languages is trying to transfer their familiar “GOTO subroutine” ideas into the PLC’s ladder logic ... this CAN be done but it’s seldom worth the effort ...

many (most?) professional PLC programmer’s use the “subroutine” files simply for ORGANIZATIONAL purposes ... for example, the CONVEYOR logic might be stored in Ladder File (subroutine file) #3 ... the GRINDER logic might be stored in Ladder File (subroutine file) #4 ... the PRESS logic might be stored in Ladder File (subroutine file) #5 ... etc. ...

once the logic has been organized this way, we USUALLY program JSR (Jump to Subroutine) instructions to unconditionally scan the ladder files ...

here’s an example of how the “subroutine” files are NOT often used ...

when the garage door is moving UP, then we’ll jump to subroutine file #3 (named something like “OPENING”) ... when the garage door is moving DOWN, then we’ll jump to subroutine file #4 (named something like “CLOSING”) ...

this type of programming CAN be done, but as you’ve already found out, handling all of the “bits keep the last state” problems can be a lot more trouble than it’s worth ...

when used in the most common manner, the basic idea behind SLC and MicroLogix “subroutines” is a lot like using “chapters” in a book ... again, this is usually done simply for organizational purposes ... it is NOT usually done to “sequence” the step-by-step operation of a machine ... it CAN be ... but it’s not at all common ...

hope this helps ...
 

Similar Topics

I have been asked to extensively modify a piece of machinery that is very mission critical to the operation, thus not allowed much downtime or...
Replies
4
Views
2,281
We have an application where we need to indicate a piece of machinery needs maintenance. I have created a routine which resets a value of "days...
Replies
12
Views
3,721
Hi all. Please see attached. Tried to google the error with absolutely no results. I did the same at payed version and real PLC so I'm almost...
Replies
7
Views
2,335
hello all is there a rule of thumb as to using or not using subroutines when writing a program ? i am using an Allen Bradley slc 500 thank you...
Replies
5
Views
1,733
All, Using RSLogix 5000. I was wondering if there is a way to quickly check to see if all subroutines are being called by the Main Routine (in...
Replies
3
Views
1,592
Back
Top Bottom