Sign in to follow this  
Followers 0
ChrisKozanecki

Stumped on Subroutine

9 posts in this topic

I have an issue with trying to make a subroutine for my program. I want to have the program run normally the way it is, but if a condition exists I want it to stop running its normal program and begin running a different sequence. Basicly I want a mode where functions could be operated manually, but ONLY if its in the manual mode, and none of the automatic funtions will work. I am really kind of stumped on how to make the PLC do this. I can get the two parts to work independently of each other but not in the same program. I tried subroutine, jump and conditional jump commands but it seemed to just break the existing program and not run anything. I know its something simple that I am missing. Any Ideas?

Share this post


Link to post
Share on other sites
First things first. What PLC you are using?

Share this post


Link to post
Share on other sites
Have you actually used the instructions SBS, SBN and RET? Or are you trying to do it without these instructions?

Share this post


Link to post
Share on other sites
Oops.. sorry, I am using a CJ1G-CPU42H I have tried with the following commands: CJP / JME ==> This causes the PLC to error out within about 2 seconds which I assume is the PLC saying that it hit max loops for the jump command, something I read more about last night. SBS / SBN / RET ==> This doesn't seem to respond with the ways I have tried. I have the book with commands on my desk at the moment and I plan on reading into subroutines more because I feel I dont understand how this is supposed to work. What I want to have happen is when the subroutine is called, I want the program to only run the subroutine and nothing else untill it's told to go back out of the routine. If it has to come out of the routine after only one scan, I would like it to go back to the step that called it and return to the subroutine if the condition is still true instead of going through the rest of the program. Edited by ChrisKozanecki

Share this post


Link to post
Share on other sites
Use the task instructions:- TKON(820) and TKOF(821)

Share this post


Link to post
Share on other sites
I just managed to get it to work with making the main program a subroutine and the manual mode a subroutine and having the program go to one or the other. It works but I dont think its the "proper way" to do it (or is it?) I will look into the Task instructions you mention BITS N BYTES. One question I have, is there a way to make the PLC ignore any settings in the part not being used? For instance: if I turn on a solenoid in the manual mode, can I have it ignore that it was turned on when I leave manual mode? I dont want an output that is set to ON in one part of the program to interfere with what the other part is doing.

Share this post


Link to post
Share on other sites
Once an output is set and you either leave a subroutine or turn off a task, the output coil will remain set. If this does not work for you, then you must handle the resetting of the output coil before leaving the subroutine or turning off the task. You might want to look into STEP/SNXT sequences which handles the output setting to similarly to what you are asling. Be sure to search for SNXT in th is forum. There are anumber of threads on the subject. IMHO, since you have a CJ1, task control is what you are desiring. Read on.

Share this post


Link to post
Share on other sites
I agree with Jay BUT with one small difference; "you must handle the resetting of the output coil before leaving the subroutine or turning off the task" I would recommend an alternate approach [used it MANY times] Handle the resetting of the output coils at the BEGINNING of each task by moving 0 to the output word. If you do not wish to reset all outputs then logically AND the output word with a mask and write back to the output word. Use ANDW(034).

Share this post


Link to post
Share on other sites
I have tried both of these methods now and I think I like the method that BITS N BYTES uses because I can trigger the outputs to reset on the same condition that puts me into manual or automatic mode. Thank you everyone once again for your help! This site is amazing!

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
Sign in to follow this  
Followers 0