Hello Guest it is March 02, 2021, 09:52:08 AM

Author Topic: Subroutines  (Read 2939 times)

0 Members and 1 Guest are viewing this topic.

« on: December 04, 2009, 03:33:26 AM »
     I'm new to Mach3, but have had some CNC experience in the late 80's using the BOSS6.1 control.     Writting a subroutine with this control was quite straight foreward.   A routine was designated by the # sign, so a routine would be called #1 #2 #3 etc the routine was closed with % and the routine placed at the top of the programme.    The routine was called by simply inserting =#1        I can't seem to find any thing in the manual about subroutines, other than the letter address is "o"  and the routine is called using the canned cycle G codes.     Can any one let me know the rules concerning writting and calling sub routines with the Mach control.

Offline Graham Waterworth

  • *
  •  2,274 2,274
  • Yorkshire Dales, England
    • View Profile
Re: Subroutines
« Reply #1 on: December 04, 2009, 06:08:14 AM »
Have a look in the g-code section of the forum there are lots of subroutine examples in there.

Without engineers the world stops
Re: Subroutines
« Reply #2 on: December 06, 2009, 05:52:56 PM »
Below is an example of simple subroutine based parameterized Mach compatible macro I use.

(Filename: DrillSimple.tap)
(Drills a continuous hole at the current X, Y location to the specified depth)
(Z must be set at zero on top of workpiece)
(If desired depth can be compensated for tip length)

G20 (Units: Inches)
G40 G90 G94

(Set Editable Parameters)
#1=1.0      (Set Depth)
#2=2500      (Set RPM)
#3=3.0       (Set Feed Rate)
#4=0.1      (Set Rapid Height)

#5=0.0      (Set to 1.0 to add tip length comp, 0.0 not to)
#6=0.250   (Drill diameter, required for tip length comp)

(Internal Parameters)
#10=[[#1/-1] - #5 * #6 * 0.3]     (Drilling Depth)

S#2 F#3
G0 Z#4      (Raise to Rapid Height)
M3       (Spindle On)

(Make any required X,Y move)
(G0 X1 Y1)
M98 P1024 L1 (Call Simple Drill subroutine)

M5 M9      (Spindle, Coolant Off)
M30       (Program End)

O1024 (Subroutine to Simple Drill)
G90      (Set Absolute)
G0 Z0.02   (Rapid to just above workpiece)
M8       (Coolant On)
G1 Z#10      (Drill)
G0 Z#4      (Raise to Rapid Height)
M9      (Coolant off)
M99       (Subroutine Return)
Re: Subroutines
« Reply #3 on: December 11, 2009, 05:46:20 AM »
    Sorry I haven't got back sooner, but thanks for your help.    I'm sure this forum will be a useful tool in the months to come.