CNC Programming Examples - Peck Drilling-Mill

CNC Mill Subprogram Example Joining Multiple Arcs G02 G03 G41

* Best ebooks for CNC programming: 
CNC Programming Basics 
G-Code and M-Code 
CNC programming 
G-Code Reference 
CNC Machine Tutorial 

CNC milling program to describe how two or more radii can be joint together in a cnc mill program.

CNC Mill Subprogram Example

CNC Part Program

N10 T1 H1 M6 G43 M3
        N20 F150 S250
        N30 G0 X-21 Y50 Z0.5
        N40 G0 Z0
        N50 M98 P040050
        N60 G49
        N70 G0 Z50
        N80 M30


        N10 F160 S400
        N20 G0 Z-2.5 G91
        N30 G1 G90 X5 Y50 G41      (P1)
        N40 G2 X22 Y85.23 I45 J0   (P2)
        N50 G3 X78 Y85.23 R45      (P3)
        N60 G2 X78 Y14.77 R45      (P4) 
        N70 G3 X22 Y14.77 R45      (P5)
        N80 G2 X5 Y50 R45          (P1)
        N90 G0 G40 X-21
        N100 M99

G M S T Codes Explanation

Code Description
G00 Rapid traverse
G01 Linear interpolation
G02 Circular interpolation CW
G03 Circular interpolation CCW
G40 Cutter compensation cancel
G41 Tool nose radius compensation left
G43 Tool length compensation + direction
G49 Tool length compensation cancel
G90 Absolute command
G91 Increment command
M03 Spindle start forward CW
M06 Tool change
M30 End of program (Reset)
M98 Subprogram call
M99 End of subprogram
T Tool
S Speed
F Feed


CNC Pocket Milling Program Example – Peck Milling

CNC milling program example which shows how a cnc program can be made to machine Pockets on a cnc mill.
This program example uses Peck milling to cut material to machine a rectangular and one round pocket.
  • CNC Pocket Milling Program Example
    • Main Program
    • Subprogram
    • Explanation

CNC Pocket Milling Program Example

Main Program

Milling cutter diameter: 10mm
N05 G55
            N10 M6 T2 H3 G43 M3
            N15 S1000 F60
            N20 G0 X9 Y9 Z1
            N25 G1 Z0
            N30 M98 P030035
            N35 G0 Z1 G90
            N40 X42 Y38
            N45 G1 Z-2 F30
            N50 X47 F300
            N55 G3 X47 Y38 I-5 J0
            N60 G0 Z100
            N65 G49
            N70 M30


            N05 G1 Z-2 G91 F30
            N10 X10 F100
            N15 Y36
            N20 X-10
            N25 Y-36
            N30 M99


Although this cnc mill program is self explanatory
M98 P030035
this code mean call Subprogram No. 0035 three times.


Fanuc G68 Coordinate Rotation – Subprogram Example

CNC program example code to show how Fanuc G68 Coordinate rotation g-code can be used in a subprogram to take most benefit from it’s functionality.
  • G68 Coordinate Rotation Example
    • Main-program
    • Subprogram

G68 Coordinate Rotation Example


N5 G54
                N10 G43 T10 H10 M6
                N15 S2000 M3 F300
                M98 P030100   ; Subprogram call
                N25 G0 Z50
                N30 M30


                N10 G91 G68 X10 Y10 R22.5
                N15 G90 X30 Y10 Z5
                N20 G1 Z-2
                N25 X45
                N30 G0 Z5
                N35 M17-------------------

CNC Mill Contour Pecking – Fanuc Subprogram Repeat Example

A very simple cnc programming example which shows
how a contour can be repeated multiple times with the added benefit of pecking.
So like peck drilling this time cnc machinists are pecking a specific contour of cnc mill.
What is Fanuc Sub programming read Fanuc Sub Programming
  • CNC Mill Contour Pecking
  • Fanuc Subprogram Repeat Example

CNC Mill Contour Pecking

The subprogram is a simple mix of G-code instructions.
The main program O4000 calls subprogram O4001 to repeat 10 times
M98 P104001
Subprogram cuts contour by making 2mm depth of cut every time (in G91 Incremental Programming)
G1 G91 Z-2 (Incremental peck depth)
Then subprogram switches back to G90 Absolute Programming this makes contour programming easy.
So this program cuts a specific contour 20mm deep by taking 10 pecks of 2mm each.

Fanuc Subprogram Repeat Example

Contour Pecking – Fanuc Mill Subprogram Repeat Example
                    T1 M6
                    G0 G90 G40 G21 G17 G94 G80
                    G54 X-75 Y-75 S? M3 (Start Point)
                    G43 Z100 H1
                    G1 Z0 F?
                    M98 P104001 (Call sub-program & repeat 10 times)
                    G0 G90 Z100
The sub program below takes cut in G91 Incremental Programming Mode
Then switches back to G90 Absolute Programming Mode for the contour machining.
                    G1 G91 Z-2 (Incremental peck depth)
                    G90 G41 X-40 D? M8 (Absolute Move to position 1 with comp. - Switch on coolant)
                    Y40 (Move to position 2.)
                    X40 (Move to position 3.)
                    Y-40 (Move to position 4.)
                    X-75 (Move to position 5 - Clear of material - cutter diameter)
                    G40 Y-75 (Cancel compensation)