Sign in to follow this  
Followers 0
Damica

Subroutines

10 posts in this topic

If I have a simple program, let's say with just 4 rungs, each rung compares an analog input, and depending on the analog reading each rung might jump to subroutine. So if the first rung jumps to the programmed subroutine, is the main program still being scanned, or does the scanning process go along to the subroutine and not come back until the return to main program. Thanks

Share this post


Link to post
Share on other sites
When it scans a JSR it completes a scan of that subroutine then it returns and continues scanning after the JSR that was just called. Edited by Giarc

Share this post


Link to post
Share on other sites
Just to make sure I understand, While the program is in the subroutine, the main program is NOT being scanned. Is this correct???

Share this post


Link to post
Share on other sites
Yes, when its done with the subroutine it will return where it left off and continue scanning. FYI "JSR" instruction can be called from anywhere not just the "Main Control Program", not a good idea (IMHO) but it can be done. I also don't like conditional subroutines. Let them run, use logic to prevent something from happening. Easier to troubleshoot. Edited by Mickey

Share this post


Link to post
Share on other sites
You said that it compares analog inputs and depending on the reading it will jump to the other subroutine, that is conditional. It will only jump to the other subroutine if certain conditions are met, in your case if the analog readings are a certain number. Edited by hboyer90

Share this post


Link to post
Share on other sites
So I should try to stay away from using a subroutine when called by a conditional jsr?? If that is the case, what would you be using subroutines for? (MATH computation), I can see - but what else?

Share this post


Link to post
Share on other sites
At my company we just use subroutines to help separate different stages of the process. We are a lead die cast facility, so for example we have out main routine where most of the steps are, close the die, shoot the lead into the die, open the die, robot enter the die, etc, we have another subroutine just for the furnace that heats the lead, another just for the camera logic, etc. At the end of the main routine we jsr to the furnace, at the end of the furnace we jsr to the cameras, etc. It just breaks up the whole program and makes it easier when searching for certain logic. I'm sure there is a better reason for subroutines than this, but this is just how we use them. Howard Edited by hboyer90

Share this post


Link to post
Share on other sites
Conditional subroutines are fine as long as you understand their use. One error often made is that an output turned on by an OTE within a subroutine will not turn off simply because the subroutine is no longer being called. Plan for what happens when the subroutine execution stops.

Share this post


Link to post
Share on other sites
Thanks everybody, I have learned a lot!!

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