Example program · Mill

Rectangular Pocket in Depth Passes Using a Subprogram — G-Code Example

Mills a 40 × 30 mm pocket 9 mm deep in three 3 mm passes by calling an incremental subprogram with M98.

By cnccode · Updated

Mills a 40 × 30 mm pocket 9 mm deep in three 3 mm passes by calling an incremental subprogram with M98.

ItemValue
MachineCNC mill / machining centre (Fanuc-style)
UnitsMetric (G21)
Lines31

Program

G-code
O1008 (POCKET 40 X 30 X 9 DEEP)
G21 G17 G40 G49 G80 G90
T2 M06 (10 MM END MILL)
G54 G00 X20. Y15.
S6000 M03
G43 H02 Z25. M08
Z1.
G01 Z0 F300.
M98 P1108 L3
G90 G00 Z25.
M09
G91 G28 Z0
G90
M30

O1108 (ONE 3 MM LAYER)
G91 G01 Z-3. F200.
G90 G01 X10. Y15. F700.
G03 X10. Y15. I10. J0
G01 X10. Y10.
X30.
Y20.
X10.
Y10.
X5. Y5.
X35.
Y25.
X5.
Y5.
X20. Y15.
M99

▶ Simulate in the G-code viewer

How it works

  • The subprogram steps down 3 mm incrementally (G91) each time it runs.
  • L3 repeats it three times for 9 mm total depth.
  • On Fanuc 0i the alternative format is M98 P31108.
  • The subprogram plunges at the pocket centre: use a centre-cutting end mill or pre-drill a start hole.

Codes used in this program

Always check feeds, speeds, offsets and clearances for your own machine and tooling, and prove new programs with single block and reduced rapid.

More milling programs