machinebuilder

Subroutine

13 posts in this topic

HI, I am trying to use a subroutine but can not get it to work properly, of course there is no example in the manual.

I tried many times in the past but gave up and now it is about time I learn how to make it work.

I want to jump to a subroutine. The subroutine will activate a air cylinder,(Plunger), for a second then retract and go back to the program. I get it to go to the subroutine and the plunger comes out and stays out. That is it. There are sensors on the extend and retract. If it extends to full lenght then go back to program and move on. If the plunger does not extend to meet the sensor, that is an error and do something else like go to alarm or something. Not sure yet. I would love to know why I can not get it to work. For now it will extend fully out make the sensor and return to the program. IF I can get that far, I can do the error thing later.

This is using RS 500 software on a Micrologix 1400. One thing I wish AB would do in the software is high light the programs if they are active. I can not really tell if it is hung up in the subroutine or not. I put a latch bit on the last rung of the subroutine along with a RET element and it never goes high.

 

Please some kind of example or logic!

Share this post


Link to post
Share on other sites

Why don't you post your program so we can have a look.

1 person likes this

Share this post


Link to post
Share on other sites

Logix500-based processors, like the Micro 1400, are I/O-based with a single routine (LAD x) that is the main routine.  Any other routines will need a JMP or JSR to send control to that routine.  If your new routine or the whole program is not functioning as expected, you are encouraged to put Nanny code that will track execution, such as counters with one shot bits.

Refer to Chapter 17  http://literature.rockwellautomation.com/idc/groups/literature/documents/rm/1766-rm001_-en-p.pdf

https://www.courses.psu.edu/e_met/e_met430_jar14/prgflo/jsr.html

You have a subroutine that must not send control back to the main program if it does not fully complete.  For myself, a robust control program starts with a concise flowchart.  Chart the process and your inefficiencies should be glaringly obvious.  The system will only do what you tell it to do.

Share this post


Link to post
Share on other sites

Are you trying to do an conditional JSR, i.e., you have logic to allow the JSR or inhibit it?  Rarely is that required and if its not require then don't do it.  Most PLC programmers I know in the SLC use JSR's for program organization.  Then use the logic in the routine itself to handle any conditions for outputs to be on or not.  Keep in mind that if the routine is not scanned then the outputs will be left in their last state.  Finally how did you place that latch.  If you branched around the return then the routine will return without operating the latch.  just put the latch on a rung before the return.  Also you really don't need the return. 

Share this post


Link to post
Share on other sites

Are there any REAL examples somewhere. I hate reading vague answers or reading vague manuals. I just need a real example. Also in the jmp command, once i go to the label how do I get back to the instructions after the jump command? It tells me to jmp then doesn't explain how to go back to the program to resume.

 

I gave up on the subroutine, I can not get it to operate properly.  If I could see an example how these things work, it would be so much better. Most of this sounds like bla bla bla to me.

Sorry not to insult anyone. Just live in a world where I need to see examples.

 

Share this post


Link to post
Share on other sites

If you had posted you program like we asked, we would have walked you through it.  I'd say all of us are around 90% certain of you are doing wrong, but without seeing your work it is hard to be sure how to guide you.  Vague questions will always lead to vague answers.  I'd consider editing your last post.  Most of these guys are going to less like to help you after they read it.

1 person likes this

Share this post


Link to post
Share on other sites

To TW's point, there are differences between a JMP and LBL vs. JSR and RET.  Please just post the program and someone will take a look and help you out.

Edited by pcmccartney1

Share this post


Link to post
Share on other sites

Not to mention that the #1 rule with JMP and LBL is don't use them.  Well - very rarely.  Like most high level languages that have goto statements.k

Now as to examples.  You didn't even ask for alternative ways to do what you are trying.  You asked about why what you were doing didn't work.  To do what you want a simple rung with a timer instruction would work by using the TT bit from the timer to activate your plunger.  PLC programs are not really designed to hang around on one task.  They are designed to look at a lot of things simultaneously and handle them all at once.  To lock out the rest of the program while you operate a plunger is not very useful in the long run.

Share this post


Link to post
Share on other sites

Sorry if i upset any of you. I get so frustrated using AB software. I did post what i was trying to do. I found some you tube videos. I see that i needed to cause the rung that calls the routine to go false. I was going to the routine but on return, the programs was scanning and seeing that the rung to go to the subroutine was still  true so it was runned it again. So in my sub routine i latch a bit to say it was completed and move on. Also I put an unlatch rung to the output that was being used in the subroutine. I think I got it. I do have several subroutines running continuously, ie, motor, HMI, etc. they are in rung 2. This particular subroutine works a cylinder that acts like a plunger and is needed several times in the program. I wanted to call it anywhere in the program as needed. If anyone has used the D0-More Software  this would have been so much easier. But this one machine I have to use AB software using RS500 and it has limited features compared to others. But that is another story.

 

Again sorry, I did not mean to insult anyone. You guys are great. Wish I knew as much about AB software as you do. I guess that comes with experience.

Share this post


Link to post
Share on other sites

Forgive me, you are comparing The DO system (platform/hardware and software) to Micrologix system.  That's like comparing the DO system to the Direct Logix.  If you want DO like functionality, you might want to consider the CompactLogix L16 or L18 series and use RSLogix5000 or Studio5000.  If your price point can't afford that, then I don't have anymore bright ideas for you.

Share this post


Link to post
Share on other sites

It would take much more than that to get me upset.  Now if there was a political thread here...  

It really doesn't sound to me as if you get the whole PLC/ladder mentality.  You don't need to call a subroutine to activate a device.  You put it one place in your program and have multiple conditions that cause the device to be active.  There is no need to have conditional JSR's throughout your program.  As far as capabilities go, turning on and off a device or activating a piston is exactly the type of activity they are designed for.  You do have to understand the mentality of ladder logic.  

1 person likes this

Share this post


Link to post
Share on other sites

There are solid fundamentals with every control platform that are required to provide working solutions.  A-B has very good literature, in my opinion, that seldom is vague (you might have to hunt for it, but the information is out there and readily available).  Often, the answer is like communicating with an autistic person...it is all in how you phrase the question.

A web forum or a video will not replace slowing down, reading the literature, understanding how the system is functioning, taking a FREE online class, going to a FREE on-the-move lab, or attending a paid classroom instruction.

One should never expect A results with C effort.

Share this post


Link to post
Share on other sites
On ‎9‎/‎21‎/‎2017 at 8:50 AM, kaiser_will said:

There are solid fundamentals with every control platform that are required to provide working solutions.  A-B has very good literature, in my opinion, that seldom is vague (you might have to hunt for it, but the information is out there and readily available).  Often, the answer is like communicating with an autistic person...it is all in how you phrase the question.

A web forum or a video will not replace slowing down, reading the literature, understanding how the system is functioning, taking a FREE online class, going to a FREE on-the-move lab, or attending a paid classroom instruction.

One should never expect A results with C effort.

I completely agree but I also like to look over other peoples programs and see how they did "things". And of course sometimes I scratch my head and wonder why they did "things" :)

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now