Subroutines

manoj

Member
Join Date
May 2003
Posts
1
Can anyone tell me how to be in a subroutine continously till an external input is activated? I am able to enter the subroutine, but after single execution of the subroutine, it goes back to the main ladder program. When I use jump instruction in the subroutine to the first rung, it gives watchdog error. Can anyone help?
 
The thoery of what you are trying to do is flawed. If you stay in a subroutine continuously the program will never finish 1 scan so as you found the watchdog timer will fault the processor. Since the scan never gets finished no outputs can get set (I assume this is not an AB control logix with asynchronous IO scan) nor can inputs get read so therefore if you wish to exit the subroutine with an input it will never see the input (there are ways around this).
Read up on the theory of scan in phils book. I dont think the method you described is what you need. Regards Alan Case
 
Assuming you have a SLC500....

Stay in the "main ladder program"(LAD2) until the "external input" is activated. Then jump to another. In the first rung of LAD2, when the "external input" is activated, put a <JMP> instruction and a [LBL] right before your JSR to the conditional SUB.

This will work as long as you ony wanted to stay in one sub conditionally.

What you are trying to do is usually not necessary and will be very confusing for a troubleshooter down the road.


:cool:
 
Sounds like you need to

a) Rethink what you are trying to do,
b1) (if PLC Supports it) make a new task to run async from main ladder
b2) (if PLC supports it) Use interrupts to determine transition states
b3) (if PLC Supports it) use a transitional language (SFC)
c) (Strongly not advised) Manually continue to reset the watchdog timer in your subroutine.
 
rdrast said:
Sounds like you need to

c) (Strongly not advised) Manually continue to reset the watchdog timer in your subroutine.

Do not do that!
Like Alan says, it seems that manoj has a misunderstanding of how a PLC scans. Resetting the watchdog timer wouldn't solve anything and the program won't do what manoj wants anyway.

Manoj- follow Alan's advice. Remember, a PLC program is a continuous loop. It has to finish the loop to update the real-world I/O. The watchdog time makes sure you finish it. You seem to be writing a program that never does. You seem to be in the linear thinking of a computer programmer. I remember having trouble with the transition, too.

I find it helpful to think of each rung as almost it's own task.
Unfortunately, I am being called away, that's as much as I can say now.
 
manoj,

Usually when people ask this type of question, they are trying to sequence the operation of a machine - for example:

... now the door is moving downward - I need to keep the door moving downward until the “door closed” limit switch comes on - then I need to ...

Is this the type of thing that you’re trying to do? If it is, then “staying in a subroutine” is not the correct way to go about it.

If I’ve guessed wrong, then why don’t you tell us what you’re trying to accomplish? I’m sure that some of the guys here can offer some excellent advice on how to get the job done.

And if you’re a student who is just experimenting with subroutines - that’s ok too - but it would be a good idea to tell us so. There are a lot of “wild and crazy” things that can be done for educational purposes - as long as there are no safety concerns or “lost production” issues involved. Right now we’re mostly just guessing about how to help you out. More information would certainly make it easier on all concerned.

And exactly what type of processor are you using? That makes a big difference.
 
haha.. I **DID** say Strongly Not Advised.

It really sounds like he needs to use a language like SFC (AB) or APT (Simatic/TI), or at least add an MCR zone in the main program until [some condition] is met.

It's very difficult to give advice not knowing the process, or PLC.
 
Hi there,

I am not sure what type of plc it is but if it is an AB PLC5 i reckon the FOR/NEXT Loop would work in this circumstance.
 
Details please!

Hi Manoj,
There are many ways of approaching a problem. I suggest you try implementing some other logic. Maybe we can help if you tell us exactly the nature of your problem and the PLC (make and model)that you are working on.
 
The easy way to stay in one subroutine is to just inhibit the jump into other subroutines.

If you pre-condition the jumps to all of your subroutines in ladder file 2 with contacts, you can definetely control which subroutines you will scan, and for how long.

Of course you will always be scanning file 2 also. If file 2 only has subroutine jumps and house keeping, then you have no watch dog concerns.
 

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,287
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,727
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,336
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,735
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