Category Archives: G Code

G Code

How can I use subprograms to increase productivity on my machining center?

How can I use subprograms to increase productivity on my machining center?

Generally speaking, subprograms do not increase throughput for a machining operation. The real benefit of using subprograms is to decrease setup time and NC file size.
Subprograms allow you to repeat a portion of a program many times. For instance, if you had a particular section of a program that needed to be repeated several times, instead of copying that section of the program over and over (and ending up with a very large NC file), you could use a subprogram. You would write the subprogram section once, then refer to it as many times as you need to.

For example, suppose a very sophisticated design needs to be cut into a piece of steel with a 0.050” end mill. The total depth of the cut needs to be 0.125”; a much deeper cut than the small end mill can make.
Through experience we know that the deepest we can cut at any one time is 0.005”. Therefore we can calculate that we need to make 25 passes on the X,Y plane to reach the final depth of 0.125”. Let’s assume that the code required to make just one of these passes is 2000 blocks. If we used a CAM package to generate a program with the 25 passes, we would end up with an NC program with 50,000+ blocks.

The alternative is to use the CAM package to generate a program that provides one pass in the XY plane. We could then manually add the subprogram codes necessary to “call” that section 25 times (incrementally moving the Z axis down 0.005” each time). Not only would this save considerable disk space, but we would end up with a program that machines the same part in only 2010 blocks, a considerable savings.
For information on building and utilizing subprograms, refer to your User’s Guide.

See Also:

Subprogram Block Numbers, O Code
Call to Subprogram, M98 Code
Return from Subprogram, M99 Code
Subprogram Reference Number, P Code


(Sub Program: This is for Educational Purposes only.)


(PROGRAMMMER: ______ ___)
(THURSDAY, NOV __ /09)

N10 G17 G20 G40 G49 G80 G90 G98
N20 G28 G91 Z0
N30 G28 X0 Y0

N40 T13 M6 (#3 C’DRILL)
N50 G0 G54 G90 X1.2 Y1. S5454 M3 (#01)
N60 G43 Z2. H13 M8
N70 G99 G81 Z-.21 R.1 F4.8
N80 M98 P5000
N90 G28 G49 G91 Z0 M5
N100 M1

N110 T14 M6 (5/16″ DRILL)
N120 G0 G54 G90 X1.2 Y1. S1920 M3 (#01)
N130 G43 Z2. H14 M8
N140 G99 G83 Z-.8188 R.1 Q.15 F9.6
N150 M98 P5000
N160 G28 G49 G91 Z0 M5
N170 M1

N180 T18 M6 (1/2X82″ C’SINK)
N190 G0 G54 G90 X1.2 Y1. S354 M3 (#01)
N200 G43 Z2. H18 M8
N210 G99 G82 Z-.2291 R.1 P.508 F1.9
N220 M98 P5000

N230 G28 G49 G91 Z0 M5
N240 M1

N250 T20 M6 (3/8-16″ TAP)
N260 G0 G54 G90 X1.2 Y1. S373 M3 (#01)
N270 G43 Z2. H20 M8
N280 G99 G83 Z-.875 R.3 F23.3125
N290 M98 P5000
N300 G28 G49 G91 Z0 M5
N310 G28 X0 Y0
N320 M30

N340 X1.7 (#02)
N350 X1.2 Y1.5 (#03)
N360 X.7 Y1. (#04)
N370 X1.2 Y.5 (#05)
N380 X2.55 Y1.5 (#06)
N390 X3.05 (#07)
N400 X2.55 Y2. (#08)
N410 X2.05 Y1.5 (#09)
N420 X2.55 Y1. (#10)
N430 X4. Y1.25 (#11)
N440 X4.5 (#12)
N450 X4. Y1.75 (#13)
N460 X3.5 Y1.25 (#14)
N470 X4. Y.75 (#15)
N480 G0 G80 Z2. M9
N490 M99

Disclaimer, not 100% sure this is right, use at your own risk. the author, school, staff, students, do not take any responsibility for your actions with what is found here.

This is for Educational Purposes only.

List of New Posts #2


CNC Program: #Part 00023

N10 G17 G20 G40 G49 G80 G90 
N20 G28 G91 Z0
N30 G28 X0 Y0
N40 T10 M6 (1 1/5 – TFEM)
N50 G0 G54 G90 X0 Y4. S640 M3
N60 G43 Z2. H10 M8 
N70 Z.1 
N80 G1 Z-.25 F6.72
N90 G2 J-4.05 F13.44
N100 G0 G80 Z2. M5
N110 G28 G49 Z0 M5
N120 M1
N130 T4 M6
N140 G0 G54 G90 X0 Y.3 S2560 M3
N150 G43 Z2. H4 M8
N160 Z.1 
N170 G1 Z-.1 F10.24
N180 X.695 Y-.9 F20.48
N190 X-.695
N200 X0 Y.3
N210 G0 Z.1
N220 X-1.750 Y1.2
N230 G1 Z-.1 F10.24
N240 G3 X1.15 Y1.8
N250 G1 X-2.316
N260 G0 X2.0
N270 X2.316
N280 Z.1
N290 G1 Z-.1 F10.24
N310 X1.5 F20.48
N320 G3 X1.75 Y1.2
N330 G0 Z2. M9
N340 G28 G49 G91 Z0 M5
N350 M1
N360 T2 M6 (1/4 TFEM)
N370 G0 G54 G90 X-2.457 Y-.85 S3840 M3 
N380 G43 Z2.0
N390 Z.1
N400 G1 Z-.1 F11.52
N410 G3 X-1.4 Y-2.144 I2.457 J.85 F2.144
N420 G2 X1.47 I1.47 J-1.356 
N430 G3 X-3.457 Y-.85 I-1.47 J2.144
N440 G0 Z2. M9
N450 G28 G49 G91 Z0 M5
N460 G28 X0 Y0
N470 M30


Download now or preview on posterous

MillGandMCard.pdf (116 KB)

Note: These G and M codes are useful reference information, on a desk, or at the machine.
They’re great to have laminated with G codes on one side and M codes on the other.
As a suggestion; get some white 90lb. cardstock and print G-codes on one side and M-codes on the other.

Posted by Jane Campus