Based on the G code the gear wizard generates, I managed to write what is below to cut a 108 tooth gear. Never written any G code before and chuffed it works even though it's simple!
Ah, a slippery slope into g-code addiction. :-)
Next stop, parametric. :-)
Ideally I would like to have 5 passes of cut depth 0.05mm, and rather than put each one in as separate lines in the code, can a sub program be entered to do these passes then move the A axis and repeat and how would I do it?
Yes. You can do it using incremental mode, but that can be tricky to debug. Alternately, go parametric, which is easy.
ASSUME X=0 is on the gear axis (This is different from your code)
ASSUME radius of blank is R (you need to substitute real values of course)
ASSUME cut depth is C (=0.05 in your case)
ASSUME number of cuts is N (=5 in your case)
ASSUME gear blank left side is Y=-1
ASSUME gear blank right side is Y=+1
Note: Mach uses defined parameters as set up in the first few line below.
Program:
#1=R % you have to insert real values here!
#2=C
#3=N
#4=[0-#1] % This starts at the surface of the blank, south of X=0
m3
f50 S4000
G64
G00 x[#4-5] A0 % clearance of 5 units south of gear
M98 P0001 Q108 % number of teeth
M5
M30
% cut one tooth
O0001
#5=#4 % reset X start position - crucial!
m98 p0002 Q#3 % make N passes for this tooth
g0 x[#1-5]
G91 A3.3333 % next tooth
m99
% do single cut
o0002
G0 X[#5-5] % clearance
G0 Y-1.5 % start 0.5 to the left of the blank
G0 X#5 % move to face of gear blank (but offset to left)
#5=[#5-#2] % move in one cut depth - key to whole idea
G1 Y1.5 % cut to right of gear blank
G0 X[#5-5] % get clear again
G0 Y-1.5 % go back to left side
m99
CAUTION: you will need to set the gear blank up and do all the prelim stuff yourself. Correctness of code NOT garranteed!
Cheers