Another newbie question of the day :)

EmesiS

Member
Join Date
Oct 2006
Location
New Mexico
Posts
17
How do you repeat a subroutine? I'm able to jump to the subroutine execute it then return. But basically I need to run the same subroutine twice then return to the main ladder. I tried jumping to one subroutine then back to the main ladder then back to another subroutine but any timers or outputs that were duplicated in the 2 subroutines would become true. Which also brings me to the next question...Can 2 separate subroutines have the same timers, inputs, or outputs. For example: U:3 subroutine has an O:0/1 output in it and so does U:5 subroutine. When the output is true in the U:3 subroutine the same output O:0/1 is true in U:5 subroutine. Is there a way to get around that?
The output is going to a pump that needs to be fired at several different times during the batching process.

I hope I explained that where someone could understand it....thanx.
 
If I understand what you're doing you are trying to run separate processes from the same subroutine. This isn't a simple task on most PLC's. I think you're using Allen-Bradley and with them as far as I know you can't call them using seperate memory (for data, timers,etc.). You can repeate call them but you will need to know which instance you're calling (a bit set or step #) to select the timers. You also need to make sure whatever it is keeps on as long as it's representative process is active even if that's not the instance you're calling. Indexing can allow you to use different memory for your data but you still need to seperate timers.
 
Oops sorry....for those that didn't see my earlier post. I'm writing logic for a batching process using RSLogix 500 and a Micrologix 1000. Thanx....
 
DesertDog....I am trying to run the same process from a subroutine but repeating the subroutine in several different placed in my main ladder. Say that the letter "A" is my main ladder and "B" is subroutine U:3 and "C" is subroutine U:5. I want to run "A" then jump to "B", repeat "B" twice, jump back to "A" then Jump to "C" and then back to "A".
I hope that clarifies it a little bit, cause I know I'm confused :)....thanx.
 
To just run it repeatedly should be no problem.
Think of it as running through everything in sequence.
Read inputs - Run logic sequentially - Write outputs - Repeat.
Doing this will be the same as replacing the main routine subroutine calls with the code contained in the subroutine.
If you want to have updated I/O actions mid scan this can be done using IIM (Immediate Input with Mask) and IOM (Immediate Output with Mask).

Hope this helps.
 
DesertDog Thanx again for the reply...but I must say...WHAT?
Your response didn't help me one little bit. As I said in the post title, I am a newbie and the things you are saying are over my head. I appreciate your response and read it 4 or 5 times and still didn't understand what you were trying to say....sorry.
 
EmesiS said:
For example: U:3 subroutine has an O:0/1 output in it and so does U:5 subroutine. When the output is true in the U:3 subroutine the same output O:0/1 is true in U:5 subroutine. Is there a way to get around that?
No, if O:0/1 is true, it's true everywhere in the program. HOWEVER, if U:3 is being called (scanned) and U:5 is not, U:3 is the one controlling the output - U:5 cannot do anything (it virtually does not exist) until it is called and a rung containing O:0/1 as an ouptut is scanned. What you are seeing in U:5 is merely the state of the output as it has been affected by U:3.
 
I'm kind of a noob too, but I think your stuck in a similar spot where I once was.

It sounds like you are trying to put a "loop" in your program, similar to what you would do in C++, VB...or other text based programming languages.

A PLC program, is essentually one giant, constant loop. Always looking at the inputs, always performing the logic, always writing to the outputs. The program never gets triggered, it just runs.

So if you have two areas of the program accessing/writing data to/from the same address.......the last subroutine/ladder/counter/timer that writes to those addresses will overwrite anything previously written to those data areas.

To overcome your output problems: You have the same output O:0/1 appearing in two subroutines. Ideally you only want your output located in a single spot. To get around your problem, use bits. O:0/1 in sub1 becomes B:0/1 in sub1, O:0/1 in sub2 becomes B:0/2, then use contacts from those bit addresses to trigger your single O:0/1 coil.
 
Hey thanx so much...you guys are great. This is really a pretty good forum. Stuff I've been trying to learn on my own for weeks by reading Rockwell literature and what you can find on the net, you guys answer in seconds. Is it just me or do Rockwell learning guides seem kind of vague? It just seems that they don't have enough real world examples. But maybe I'm just stupid and it will make sense after awhile. Thanx again for the replies.
 
EmesiS,
Just a friendly tip: If you are using a Micrologix 1000, then the first User Subroutine would be File 6. Files 3, 4, and 5 are reserved.

To run the SAME subroutine 2 times, you may simply use a Counter to trigger the subroutine 2 times. When C5:0 = 1, JSR to Subroutine. Later, when C5:0 = 2, JSR to Subroutine again.

SUB_TRIGGER2.JPG


Because you have a recipe, or pattern, to control, you can also use Stage Relays, or a Sequencer, to control your JSRs.
 
Last edited:

Similar Topics

Good Morning to all FTV 8.0, RSL5K, I have set up a Multi state indicator. Its just a light, but I need it to change colors with the state of...
Replies
15
Views
4,387
Hi All, I'll looked through the forum and the vastness of google with little luck (which makes me believe what I'm going to ask is not possible)...
Replies
4
Views
3,660
Hi Guys Interesting forum you have here. And some interesting comments to the Newbies. I promise, i'm not here to ask you to do my homework...
Replies
2
Views
4,537
Hi All, I've been using GE and Siemens for a long time and just switched to Allan-Bradley because of one of our customers requirements...
Replies
21
Views
4,595
Hello everyone? I’ve been lurking for some time…This is who I am. I’m 56 I’ve been in plant maintenance for the past 4 years as an electrician...
Replies
8
Views
3,086
Back
Top Bottom