Sign in to follow this  
Followers 0
dank06

CJ Subroutine Question

4 posts in this topic

In the following program file, I have defined some subroutines. When subroutine 80 is enabled, bit 1001.01 and TIM 1000 within subroutine 80 are enabled. Outside of subroutine 80, bit 1001.01 is supposed to enable bit 3000.03 and TIM 1000 is supposed to enable bit 3000.00 My question is: Why do neither 3000.00 or 3000.03 enable outside of the subroutine when the preceding rung conditions are true? Is there a better way to do it? Subroutines.cxp

Share this post


Link to post
Share on other sites
There probably is a better way to do it, but the correct way will work for what you are trying to acheive. From the manual, W340.E1 pg 784, it states "Place the subroutines in the main program and just before the END instruction in the program for each task. If part of the main program is placed after the subrouting region, that program section will be ignored." Even though I have never used subroutines, I would go one step further, and have a seperate section, right at the end of any other sections, dedicated to 'subroutines'. I have attached a only slightly modified version of you original code. I am assuming that you are aware, but will warn you anyway, as soon as the sub is called, and 'unconditional instructions will be executed, and will not be un-executed, UNLESS you have a seperate condition for the same instructions in another sub, or in the main program somewhere. In the modified example, I have added an execution condition for the subs that you defined. Subroutines.cxp Edited by scottmurphy

Share this post


Link to post
Share on other sites
The SBS instruction is an older OMRON function. I much prefer the flexibility of the newer TKON[820] and TKOF[821] instructions for subroutine processing. Just my 2 cents!

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