1137
« on: October 03, 2010, 06:11:42 AM »
A sub program can be anything from a single gcode command to a complete multi tool program.
The simplest use is to allow repetition of a series of moves, e.g. you have 10 holes to drill & tap on 10mm centres along the X axis.
%
O0001(DRILL HOLES 10MM CTS)
G21 G40 G00 G80
G91 G28 Z0
N1(CENTRE DRILL)
T1 M6
G54 G00 G90 G43 X0 Y0 Z25. H1 S1000 M3
M8 (COOLANT ON)
G82 Z-2. R2. P250 F75. (DRILL CYCLE WITH A DWELL OF .25 SECONDS)
M98 P0002 (CALL SUB O0002)
G80 (CANCEL CYCLE)
G91 G28 Z0(MOVE TO TOOL CHANGE)
M1
N2(5MM DRILL)
T2 M6
G54 G00 G90 G43 X0 Y0 Z25. H2 S1500 M3
M8
G81 Z-10. R1. F150.
M98 P0002
G80
G91 G28 Z0
M1
N3(TAP M6)
T3 M6
G54 G00 G90 G43 X0 Y0 Z25. H3 S100 M3
M8
G84 Z-12. R3. F100.
M98 P0002
G80
G91 G28 Y0 Z0
M30
O0002(SUB PROGRAM)
X10.
X20.
X30.
X40.
X50.
X60.
X70.
X80.
X90.
M99
%
We call the sub program O0002 three times, this saves writing out the gcode three times in the main program. This makes for less errors easy editing and smaller gcode files.
There are some simple rules to follow when using sub programs
1. The first line of a program with sub programs should be a % sign only
2. The last line of a program with sub programs should be a % sign only
3. Sub programs should be listed after the main program
4. Subs should start with a unique Onnnn number and finish with M99
5. The main program must end with an M2, M30 or M47
6. Subs calling subs can be up to 7 deep.
7. Subs can be called from the subroutines directory within Mach3 by using its file name e.g. M98 (SUB01.TAP)
8. A sub call with an Lnn in the line will call the sub nn times, the value of nn can be in the range of 1 to 99. E.g. M98 P0002 L10
I will add more to this on request.
Regards
Graham