Posted 24 Sep 2015 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
Posted 25 Sep 2015 (edited) 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 25 Sep 2015 by Giarc Share this post Link to post Share on other sites
Posted 25 Sep 2015 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
Posted 25 Sep 2015 (edited) 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 25 Sep 2015 by Mickey Share this post Link to post Share on other sites
Posted 25 Sep 2015 What do you mean by "Conditional"? Share this post Link to post Share on other sites
Posted 25 Sep 2015 (edited) 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 25 Sep 2015 by hboyer90 Share this post Link to post Share on other sites
Posted 25 Sep 2015 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
Posted 25 Sep 2015 (edited) 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 25 Sep 2015 by hboyer90 Share this post Link to post Share on other sites
Posted 25 Sep 2015 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
Posted 26 Sep 2015 Thanks everybody, I have learned a lot!! Share this post Link to post Share on other sites