Hello Guest it is December 10, 2023, 09:19:31 AM

Author Topic: calling subroutines - (corrected post)  (Read 2327 times)

0 Members and 1 Guest are viewing this topic.

calling subroutines - (corrected post)
« 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)
think of the trees-- use both sides of the computer paper

Offline stirling

  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: calling subroutines - (corrected post)
« Reply #1 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.


Re: calling subroutines - (corrected post)
« Reply #2 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.