Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: Fred_evans on May 30, 2012, 11:04:22 AM

Title: calling subroutines - (corrected post)
Post by: Fred_evans on May 30, 2012, 11:04:22 AM

Sorry chaps- something went wrong with the previous post and it posted before i had finished

Here is the correct post


Hi guys.
Mach3 on a lathe
My question is can a subroutine which contains parameters be called more than once but with different parameters

An example would be like tis
#1=10        ( parm 1=10)
m98 p2 l3    ( calls 02 with value of #1=10)
more code   

#1=20        ( parm 1 now reinitialized to a value of 20)
m98 p2 l3    ( same sub called again but with different value of parameter)

( ----eop:test prg--------)

02                    ( subrourine 02)
g0 x#1 z5         (doing something with the parm #1)

M99    ( return to main)
Title: Re: calling subroutines - (corrected post)
Post by: stirling on May 30, 2012, 11:25:04 AM
Hi Fred

Have you tried it?

Yes this will be fine. FWIW you're NOT calling a sub with different parameters here. You're calling a sub where a gcode var which is global has been altered between calls - not the same thing.

If you do a M98 P2 L3 and a M98 P2 L4 - that would be calling o2 with a different L parameter and that's fine also.


Title: Re: calling subroutines - (corrected post)
Post by: BluePinnacle on May 30, 2012, 07:33:18 PM
I frequently use this. Ie, use parametric values to define Z movement during a circular cut, and decrease that value every time the subroutine is called. Result: helical paths for boring, thread milling etc. Parametrics can save you a lot of time and coding.

Remember that a parameter will persist between cycles ... Make sure your program resets the parameters to a safe starting point before they are called for the first time in the movement phases.