3 CNC Programming
3 CNC Programming
Preparatory codes
G codes
M codes
Miscellaneous codes
CODES
G codes
M codes
Control the machine
functions other than
tool movements
CODES
G codes
G Codes - Axial Movements
+X
+Z
-Z
-X
Coordinate positioning : Diametral
We will use Diametral
system for this course
+X
+Z
-Z
-X
G Codes - Axial Movements
G00 X30 Z5
Tool
Home Position
+X X30 Z5
40 -Z
+Z
-X
G Codes - Axial Movements
G00 X30 Z5
G01 X30 Z-20 F40 Feed rate
Tool
X30 Z-20
+X X30 Z5
40 -Z
+Z
-X
G Codes - Axial Movements
G00 X30 Z5 (Home 1)
G01 X30 Z00 F40(1 2)
X40 Z-35 (2 3)
3 Home
Position
2 1
+X
Ø40 Ø30 -Z
+Z
-X
35
G Codes - Axial Movements
Clockwise Circular
G02 Machining in a clockwise circular arc
interpolation
G00 X20 Z5
-X
15
25
G Codes - Axial Movements
Counter-clockwise
Machining in a counter-clockwise
G03 Circular
circular arc
interpolation
G00 X20 Z5
Ø40
Ø40 Ø20
Ø20 -Z +Z Counter-
clockwise
-X
15
25
G Codes – Machine Setup
For Milling ONLY
All coordinates are relative to the
G90 Absolute positioning reference position
(i.e. Workpiece Origin)
All coordinates are relative to the
G91 Incremental positioning current position
Incremental Incremental
mode in mode in
X axis Z axis
Home Position Important point
+Z
Tool will
-X +X • move 00 in the X direction
and 00 in the Z direction
-Z (incremental mode)
40
• and then will return to the
Home position
60
G Codes - Axial Movements
Return to machine (Rapid traverse) Moves the tool at a
G28
home position very fast rate to the home position
Tool will
• move to the workpiece
origin : X00 Y00
(absolute mode)
Home Position
+Z
• and then will return to the
-X +X Home position
-Z
40
60
G Codes - Axial Movements
Return to machine (Rapid traverse) Moves the tool at a
G28
home position very fast rate to the home position
Tool will
• move to the workpiece
origin : X00 Y00
(absolute mode)
Home Position
+Z
• and then will return to the
-X +X Home position
-Z
40
60
G Codes - Axial Movements
Return to machine (Rapid traverse) Moves the tool at a
G28
home position very fast rate to the home position
-Z
40
60
G Codes - Axial Movements
Return to machine (Rapid traverse) Moves the tool at a
G28
home position very fast rate to the home position
60
G Codes - Axial Movements
Return to machine (Rapid traverse) Moves the tool at a
G28
home position very fast rate to the home position
Tool will
• move 00 in the X direction
and 30 in the Z direction
(incremental mode)
Home Position
+Z
• and then will return to the
-X +X Home position in a rapid
traverse mode
-Z
40
60
G Codes - Axial Movements
Return to machine (Rapid traverse) Moves the tool at a
G28
home position very fast rate to the home position
Tool will
• move 00 in the X direction
and 30 in the Z direction
(incremental mode)
Home Position
+Z
• and then will return to the
-X +X Home position in a rapid
traverse mode
-Z
40
60
G Codes - Axial Movements
Return to machine (Rapid traverse) Moves the tool at a
G28
home position very fast rate to the home position
Tool will
• move to the intermediate
point : X60 Z35
X60 Z35 (absolute mode)
Home Position
+Z
• and then will return to the
-X +X Home position in a rapid
traverse mode
-Z
40
60
G Codes - Axial Movements
Return to machine (Rapid traverse) Moves the tool at a
G28
home position very fast rate to the home position
Tool will
• move to the intermediate
point : X60 Z35
X60 Z35 (absolute mode)
Home Position
+Z
• and then will return to the
-X +X Home position in a rapid
traverse mode
-Z
40
60
G Codes – Machine Setup
C
A
B
A B
C
0
+Y
D
0
-X +X
-Y
CODES
M codes
Control the machine
functions other than
tool movements
M codes : Group 1
OFF OFF
M01 M01
ON ON
M02 : Program End
Program 1 Program 2
• The M02 code is
used to end a
program.
• But the Program
won’t reset to the
beginning of the
program for the
next cycle.
M02 M02
• The Operator
must manually
press the Reset
button to start the
program again.
M30 : Program End and Rewind
Program 1 Program 2
• M30 can be used
anywhere in the
program.
• For example, we may
have a need to run the
first half of an existing
program.
• Rather than deleting
part of the program, we M30 M30
M08 Coolant ON
10
30
45
50
-X
+X
-Z
+Z
-X
+X
Roughing depth of
Cut
-Z
+Z
-X
+X
-Z
+Z
-X
+X
-Z
+Z
-X
+X
-Z
+Z
-X
+X
-Z
+Z
-X
+X
-Z
+Z
-X
+X
-Z
+Z
Material to be left
for finish pass
-X
+X
Material being
removed by
finishing pass
-Z
+Z
-X
+X
Roughing depth of
Cut
-Z
+Z
Material to be left
for finish pass
-X
Canned Cycles
• Many turning operations require tedious and
redundant motions, such as the multiple passes
performed during a rough turning operation or
multiple pecks required for deep hole-drilling
operations.
• Machine control manufacturers have equipped the
controls with features that make these tedious
operations easier and faster to program.
• These machining routines can be packaged or
“canned” into one or two blocks of code and are
called canned cycles.
Stock Removal Turning Cycle : G71
• Function G71 is the stock removal cycle for turning
that removes metal along the direction of the Z axis.
In a case where there is a lot of material to be
removed, this cycle provides an easy method for
programming.
Block 1 G71 U R
Block 2 G71 P Q U W F
Stock Removal Turning Cycle : G71
depth of
roughing cut amount of retract, along
(no sign) the X axis, for each cut
Block 1 G71 U R
Block 2 G71 P Q U W F
block number where the amount of material for roughing feed rate
code for the contour finishing to be left on
begins all diameters
(X axis)
Depth of Cut U
R12.5
Retract amount R
-Z +Z
10
25
62.5
75
-X
Stock Removal Turning Cycle : G71
G70 P Q F S
G74 R
G74 X Z Q F
G74 R
Z
G74 X Z Q F
Micrometre (µm)
R
Q Micrometre (µm)
Clearance
Clearance
G74 R1
20
G74 X0 Z-20 Q5000 F50
Micrometre (µm)
1
Clearance
Threading Cycle : G76 angle of Micrometre (µm) in
software
Relief angle (to the thread mm in machine
number of
retract it may be minimum cut
finishing cuts
require some depth for rough
angle) cut
Block 2 G76 X Z P Q F