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.
Mills a 40 × 30 mm pocket 9 mm deep in three 3 mm passes by calling an incremental subprogram with M98.
| Item | Value |
|---|---|
| Machine | CNC mill / machining centre (Fanuc-style) |
| Units | Metric (G21) |
| Lines | 31 |
Program
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
- Face Milling Program (Zig-Zag Passes)
- Outside Contour with Cutter Compensation (G41)
- Circular Pocket with Helical Entry
- Bolt Hole Circle with Polar Coordinates (G16)
- Peck Drilling a Hole Grid (G83)
- Rigid Tapping Program (M8 × 1.25)
- Internal Thread Milling M12 × 1.75
- Machining Multiple Parts with G54–G57
- Counterbore Holes for M6 Socket Head Screws
- Fine Boring a Precision Bore (G76 on a Mill)
- Milling a Slot with Ramping Entry
- Chamfering an Outside Edge with a Chamfer Mill
- Parametric Bolt Circle Macro (WHILE Loop)
- Spindle Warm-Up Program
- Setting a Work Offset Automatically with a Probe (G31)
- GRBL Router: Rectangle Cut-Out in Depth Passes
- GRBL / LinuxCNC Touch Plate Z Probe (G38.2)
- Haas G12 / G13 Circular Pocket in One Line
- Haas M97 Local Subprogram for Repeated Features
- High-Speed Peck Drilling in Aluminum (G73)
- Helical Boring a Ø20 Hole with a 10 mm End Mill