Notes CNC Program
Notes CNC Program
A broader definition of CAM can include the use of computer applications to define a
manufacturing plan for tooling design, computer-aided design (CAD) model preparation, NC
programming, coordinate measuring machine (CMM) inspection programming, machine tool
simulation, or post-processing.
• Milling Machines: Widely popular. In fact, they might even be the most popular type of CNC machine
used today. Milling machines utilize rotary cutters to shape workpieces to perfection. They can be
programmed to provide the required depth, angle and cutting direction.
• CNC Lathes: A lathe is utilized to develop highly precise conical and spherical shaped parts. This
particular machine uses turning centers wherein the cutting tool shaves off the excess material while the
material is rotating on a spindle.
• Drilling machines: CNC drills are highly advanced drilling machines where the speed of the drill and
the depth to be drilled is handled by highly sophisticated computer programs.
• Screw Machines: Screw machines are the advanced version of automated lathes. They are used to
produce smaller yet complex machined parts for automotive, aerospace, medical and electrical
hardware industries.
• CNC Grinders: This type of machine utilizes a rotary wheel that abrades the material into the desired
shape by repeatedly grinding it.
• CNC Plasma Cutters: Plasma cutters uses plasma beam to cut the materials into 2D shapes.
There are various type of CNC controllers (control systems) in the market nowadays. Some of them
are as follows:
• Siemens
• Fanuc
• Heidenhein
• Mitsubishi
The above four are generic control system that are used by most CNC machine manufacturers.
However there are some CNC machine manufacturers that have their own control systems:-
• Haas
• Mazak
• Hurco
• Cincinati
• And many more…….
Spindle
Cutter
Known as a “BLOCK”
Letter Number
EXAMPLE OF CNC PROGRAM As mentioned previously, the CNC programming comes with letter
codes.
G code:
It is known as geometry code – involve with actual tool movements
in X, Y & Z directions.
M code:
It is known as miscellaneous code – involve with necessary
actions for machining such as spindle on/off, coolant on/off, tool
change, end of program.
T code:
It is known as tool number code/tooling code – involve when it is
necessary to change the new cutting tools for certain related
machining cutting process in the same CNC program.
X, Y, and Z codes:
These codes are used to specify the coordinate axis.
Numbers that following the code, defines the coordinate at the
End of the cutting tool movement relative to an absolute or
Incremental reference point.
F code:
It is used to specify the feed rate.
S code:
It is used to specify the spindle speed.
R code:
This code is refer to retract distance between the cutting tool
And the work piece when used with codes such as G81, G82,
And G83.
P code:
It is used to specify the dwell time associated with G04.
Prepared by: Jurie@2020
G CODES IN CNC
G-code is defined using the G address letter and a two digit number in NC Programming; Example: G00
G-Code is mostly used common name in NC Programming language since they prepare the machine for a
certain type of motion. G-codes instruct the machine where to move, how fast to move and which path to move.
G-codes are called as preparatory/geometry codes which prepare machine to move.
1) Modal G-code.
2) Non-Modal G-code.
Modal G-code:
The G-codes for motions are called Modal G-code. The modal G-code once called it stays till it is cancelled with
another G-code. If G1 (Linear Move) command is called it will be executed again on the next line unless some
other command called which cancels G1.
Additionally, modal G codes are further split into groups according to their task and function. A modal G code will
remain active until another G code from the same group is programmed into a block, or it is cancelled. Example
units of programming inches (G21) and millimeters (G20) are modal. Model groups are as shown on the next
slide.
Non-Modal G-codes:
The Non-Modal G-codes effect only the lines on which they occur. Example: G04 (Dwell) is Non-Modal. The
machine suspends machine motions code, dwells for the programmed time, and then returns to normal
movements.
Prepared by: Jurie@2020
M-CODES IN CNC
M-codes are Non-Axis movement command which known as machine codes which control the miscellaneous
functions of machine excluding the axis movement of the machines.
M-Code is the Letter “M” Followed by the Numbers which control the machine functions. Example: M03 a controls the
spindle to rotate along clockwise direction.
M-code can be used to initiate a miscellaneous function not related to tool movement.
M-code Usually acts like a switches that stay ON until they are turned OFF by another M code
M-code is always allowed one per block of code.
Some M-codes are used in conjunction with other address, M06 tool change is always called with the conjunction
with a T word which is for tooling code.
The machine tool manufacturer often provides many additional M-Codes, many of these codes are non- standard,
and therefore we should consult the user manual of machine before making assumptions while using M-codes in
the CNC program.
• In the CNC program, there are two types of G-Code for coordinate system as
stated below:
- G90 (Absolute programming)
- G91 (Incremental programming)
• NOTE:
You no need to memorize all the G-codes.
You can refer to the G-code table for CNC milling as reference.
P0 0 0
P1 12 12
P2 26 16
P3 38 32
P0 0 0
P1 12 12
P2 14 4
P3 12 16
Linear interpolation
Point 5
Point 1
Point 2
Point 3
Point 4
Point 4 Point 3 Point 5
Point 1
Program stop
Point 1 Point 2
Unit: in metric
Using G41 and G42 cutter compensation, will enable the machine to
calculate this, so we can program to the dimensions of the drawing.
This explanation can be showed further as in the figure on the next
slide.
CUTTER
WORK PIECE
CUTTER
CODES EXPLANATION
G00 : Rapid transverse
G01 : Linear interpolation
G41 : Tool nose radius compensation left
G43 : Tool length compensation “+” direction
G54 : Workpiece coordinate system 1 selection
G90 : Absolute command
G91 : Incremental command
M06 : Tool change
H : Tool length offset
Use when the dimensions/measurements are involved with radius for an arc, partial arc or
complete circle. One of the example is to create fillet.
The I, J, & K representing the radius on each axis direction. The usage of I, J, & K is to avoid
from any confusion with X, Y, & Z.
All of these I, J, & K can be replaced with “R” to indicate the radius. The value of the radius
can be “-” or “+” depends on the direction.
The G-code for CW circular interpolation is G02, while for CCW circular interpolation is G03.
Point S
Point A
Point B
Point C
Point D
Point E
Point F
Point G
Point H
Point I
Point A
Point S
Unit: in inches
Point 6
Point 1 Point 2 Point 3 Point 4 Point 5
Unit: in metric
Prepared by: Jurie@2020
EXAMPLE: ABSOLUTE COMMAND, CIRCULAR INTERPOLATION,
CUTTER COMPENSATION
PART PROGRAM
SELF ASSESSMENT #1 • Write a part program based
from the given profile.
• Use absolute command
• Workpiece thickness: 20mm
• Units: Metric millimeter
• SP is a Starting Point
SP (0,0)
SP (0, 0)
MAIN PROGRAM
&
SUBPROGRAM
Prepared by: Jurie@2020
MAIN PROGRAM & SUBPROGRAM IN CNC
Main program:
It is a whole body of entire CNC program. All CNC
commands/programs in order to produce a certain
part will include under this main program.
Subprogram:
It is a normal CNC program which called from a
program (normally called Main program) to add
some kind of repeatable machining operation.
• This is used for the simple program within the program and does not require complication of creating a
subprogram.
• If there is a repetition of the loop of subprogram L count on the M97 line, the sub-program will be repeated L
number of times.
• M98 is M-code of a subprogram call. Normally, we write this M-code in the main program.
• M98 is the M-code used to call a Subprogram with the reference to the separate program
created and loaded on the controller.
• The Pxxxx code is the sub-program number being called; it must be in the same block as the
M98.
• A sub-program must end with an M99 to enter to main program after the subprogram.
• If there is a repetition of the loop of subprogram L count on the M98 line, the sub-program will be
repeated L number of times before continuing to the next block.
Example:
Main program:
O01234 (Program number and Start of main program)
N0001 T02 M06;
N0002 T03
N0003 G54 G90 G00 Z50
...
...
... (Part program)
...
...
M98 P111 (Jumps to program O00111 to execute sub-program)
... (The M99 at the end of the sub-program will jump back here)
...
... (Finish part program)
...
M30 (End of main program)
Sub-program:
O00111 (Identifies the start of a separate sub-program)
...
... (Sub-program portion of part)
...
M99 (Jumps back to the line after the sub-program call in the main program).
Prepared by: Jurie@2020
WHAT IS M97, M98 & M99 OF M-CODES? (CONT’)
• If in the main program: it will cause the program to loop back to the beginning and repeat over
and over again without stopping.
• If in the subprogram: it will end the subprogram and return to the main program (a line after the
related subprogram call).
O01234
...
... (Complete part program)
...
...
M99 (This will cause the program to jump back to the beginning and
repeat itself)
An M99 without a P code at the end of a sub-program will return to
the main Program.)
Example:
Main program: Sub-program:
SUBPROGRAM
Subprogram number
Depth 6mm
Material/Work piece
G-CODE PROGRAMMING
STARTING
POINT
WITH DEPTH 10mm
https://www.slideshare.net/MaheshNamdev1/4-basic-cnc-programming-milling
https://www.academia.edu/40488047
http://www.helmancnc.com
https://www.quora.com/How-do-I-learn-CNC-programming
https://gcodetutor.com/gcode-tutorial
https://machmotion.com/blog
https://www.mechaterrain.com
https://www.slideshare.net/manujarora98/g-and-mprogrammingformillsmanual
https://mdaltd.ca/cnc-machines-face-modern-manufacturing/
http://cnc-programming-tips.blogspot.com
Prepared by: Jurie@2020