Using a subrutine

I think you are referring to a JSR instruction. Place a JSR in your Main Routine after creating Sub's and you ID the JSR with the name of the Subroutine.
 
Are you looking for specific guidance on how to use the JSR instruction or are you looking for examples of when one may choose to use the instruction and why?

BTW, hello from KY.

Shawn
 
Looking for how to use the instruction. I want to separate the safety rungs from the motor starter sequence.
 
IIRC, you can separate them and not use the JSRs anywhere and the processor will still scan through each sub routine. It is only when you specify it to jump to a certain routine when it would then be used. I myself wouldn't put some safety logic in a subroutine and allowed the program to "jump" to it at certain times in a program, or when its instructed to.

Of course, Im sure it all depends on what your PLC is too.
 
IIRC, you can separate them and not use the JSRs anywhere and the processor will still scan through each sub routine. It is only when you specify it to jump to a certain routine when it would then be used. I myself wouldn't put some safety logic in a subroutine and allowed the program to "jump" to it at certain times in a program, or when its instructed to.

Of course, Im sure it all depends on what your PLC is too.

Sorry Seth350, this is not the case. The PLC must be told to call the Subroutines in some way.

Stu....
 
I'm assuming you are using an AB PLC.

Look at the program in post 5 of this thread
http://www.plctalk.net/qanda/showthread.php?p=260919

The particular problem in that thread isn't relevant to your question, but observe how the program is organized. The program contains two subroutines. In this case each subroutine demonstrates a different way to solve a problem.

Ladder 2, the main ladder, calls two subroutines. Ladder 2 contains only rungs that call the subroutines. No other logic exists in Ladder 2.
Ladder 3 contains one subroutine
Ladder 4 contains the other subroutine.

When someone wants to look at only one part of the program they can quickly find out where that part is by looking at ladder 2 and then selecting the right subroutine.


Subroutines can be a very powerful tool for program organization. A programmer might choose to divide subroutines by zone (Conveyor 1, conveyor 2, Robot1, Robot2, etc.) or he might choose to divide by operation (Fill, Mix, Heat, Drain).

Subroutines can also be created to improve program readability. Its much easier to troubleshoot something if you can go to a short subroutine rather than hunt through a long monolithic program.

I often program a dedicated output subroutine that contains all the actual output points. In my experience when a maintenance tech wants to troubleshoot a particular actuator he will first hunt for the output address. Putting them all in sequential order in one subroutine makes it easier for him to find it. From there he can then back track.

Subroutines also make programming easier by helping you to break a complex process into a series of smaller tasks. As a general rule of thumb I try to break a program into small tasks that can be programmed in twenty rungs or less. If a task can't be programmed in twenty rungs or less then I haven't broken it down enough. In the first example I mentioned (conveyor/robot) the robot might be broken down farther to pick up part, orient part, place part. From time to time I may need to have a longer subroutine but for the most part I try to keep them pretty short.

Unless you are using a bottom dweller like a Micrologix 1000 then you are probably not going to run out of subroutines so don't be afraid of using as many of them as makes sense.


edit to add:
Do a forum search, there are lots of threads on helpful ways to use subroutines.
Here a a couple:
http://www.plctalk.net/qanda/showthread.php?t=61978
http://www.plctalk.net/qanda/showthread.php?t=54275
 
Last edited:

Similar Topics

Hi I'm very new to PLC programming and I'm trying to find out if this library (Tc2_NcFifoAxes) is necessary for our task In our case we need to...
Replies
0
Views
43
I have a project to automate four generator sets. The system will monitor and store the load demand of the factory. Once there's Power outage, the...
Replies
0
Views
93
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
3
Views
149
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
7
Views
273
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
79
Back
Top Bottom