0% found this document useful (0 votes)
129 views

CNC Programming Concepts and Commonly Used G-Codes in

The document discusses CNC lathe machine programming concepts and commonly used G-codes. It provides an overview of the CNC processing workflow including developing drawings, choosing tools, sequencing machining operations, and writing the NC program. It explains that a CNC program is a sequential list of machining instructions written using G-codes for movements and M-codes for auxiliary functions. Commonly used G-codes for lathe operations like linear, circular and rapid moves are described along with modal G-codes that remain active until cancelled.

Uploaded by

Mel Paras
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views

CNC Programming Concepts and Commonly Used G-Codes in

The document discusses CNC lathe machine programming concepts and commonly used G-codes. It provides an overview of the CNC processing workflow including developing drawings, choosing tools, sequencing machining operations, and writing the NC program. It explains that a CNC program is a sequential list of machining instructions written using G-codes for movements and M-codes for auxiliary functions. Commonly used G-codes for lathe operations like linear, circular and rapid moves are described along with modal G-codes that remain active until cancelled.

Uploaded by

Mel Paras
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 54

CNC programming concepts and

commonly used G-codes in CNC


lathe machine programming
Writing basic CNC Lathe Machine Program lesson 2
Introduction
Before you can fully understand CNC, you must first understand how a manufacturing company processes a job that will
be produced on a CNC machine. The following is an example of how a company may break down the process of CNC.

Flow of CNC processing • Write the NC program.


• Develop the part drawing • Prepare set up sheets and tool lists.
• Decide which machine will produce the part. • Send program to machine.
• Choose the tooling required. • Verify the program.
• Decide on the machining sequence. • Run the program if no changes are required
• Do math calculations for the program
coordinates.
• Calculate the speeds and feeds required for
the tooling and part material.
Preparing a program

• A program is a sequential list of machining instructions for the CNC


machine to execute. These instructions are CNC code that contains all the
information required to machine a part, as specified by the programmer.
• CNC code consists of blocks (also called lines), each of which contains an
individual command for a movement or specific action. Just as with
conventional machines, one movement is made before the next one. This
is why CNC codes are listed sequentially in numbered blocks.
CNC codes

There are two major types of CNC codes, or letter address, in any program. The
major CNC codes are called G-codes and M-codes.
• G-codes are preparatory functions, which involve actual tool moves (for example,
control of the machine). These includes rapid moves, feed moves, radial feed
moves, dwells, and roughing and profiling cycles.
• M-codes are miscellaneous functions, which includes actions necessary for
machining, but not those that are an actual tool movement (for example, auxiliary
functions). These include spindle on and off, tool change, coolant on and off,
program stops, and other similar related functions.
Letter Function
Other letter addresses or variables address
N Block number
are used in the G- and M- codes to G Preparatory function
make words. Most G-codes contain a X X axis coordinate
Y Y axis coordinate
variable, defined by the programmer, Z Z axis coordinate
for each specific function. Each I X axis location of arc center
J Y axis location of arc center
designation used in CNC K Z axis location of arc center
programming is called a letter S Sets the spindle speed
F Assigns a feed rate
address. The letters used for T Specifies tool to be used
programming are as follows: M Miscellaneous function
A-Address
Components of a CNC block/line commandscode

B-Data
C-Word
N001 G00 G28 U0. W0. ; D-Block
C, F C C C C E-End of block
E F-block number
A B A B A B A B A B
Block format
Block format is often more important than
D program format. It is vital that each block of CNC
code be entered into the CPU correctly. Each
block comprises different components, which can
produce tool moves on the machine.
Programming terminologies
 
Address
An address is a part of a program word that is expressed using letters of the alphabet.
 
Data
Data are all numbers after an address including the sign and decimal point.
 
Word
A word is consisted by an address and a data put together to specify a machine code function/s.
 
Programming terminologies
 
Block
A block is consisting of 1 or more words to specify a cycle that can be done together at the same time
or within a series of machine movements.
 
Program number
CNC machine programs are arranged in numerical order by the presence of a program number, it is set
with an alphabet “O” followed by four or less digit numbers.
 
Sequence number
An alphabet “N” followed by five or less digit numbers is used to express a sequence number. It is
used as position identification of each program line/ block that is being executed in the program.
 
Three major parts of a CNC Program

• Header / program set up


• Body / material removal
• End part / system shut down
Part Sample CNC lathe machine program interpretation
% Program start flag

Header/ program set


O0001 Program number
N5 G28 U0. W0. Return to home position
N10 T0101 M6 Tool #1 call with offset no.1
N20 G97 S1500 M3 Constant spindle rotation on
up

N25 G0 X35. Z0. Rapid positioning to (x35, z0.)


G1 X-1. F.2 Linear interpolation to X-1.
G0 X35. Z1. Rapid positioning to (Z1.)
N30 G73 U1. R1. Stock removal in turning
N35 G73 P40 Q80 U.1 W.1 F.2 command for N40 to N80
N40 G1 X0. Z0. Feed down to X0. Z0.
N45 X10. Feed down to X10. Z0.
Body/ material removal

N50 Z-10. Feed down to X10. Z-10.


N55 X15. Feed down to X15. Z-10.
N60 Z-15. Feed down to X15. Z-15.
N65 X18. Feed down to X18. Z-15.
N70 Z-20. Feed down to X18. Z-20.
N80 X20. Feed down to X20. Z-20.
N85 G70 P40 Q80 F.1 S2000 Finishing cycle for N40 to N80
N90 G0 X62. Z1. Rapid positioning to (X62.,Z1.)
N95 M5 Turn off spindle
N100 G28 U0. W0. Return to home position
rt

N140 M30
d
G- Codes

• G-codes are preparatory functions, which involve actual tool moves. These include rapid
moves, feed moves, radial moves, dwells, and roughing and profiling cycles. Most G-codes
described here are Modal, meaning that they remain active until cancelled by another G-code.
G-codes, also called preparatory codes, are any word in a CNC program that begins with the
letter “G”. Generally, it is a code telling the machine tool what type of action to perform.
Modal G-Codes
• codes that remains active until cancelled by another G-code.
• Is a G-code that remains effective in CNC program until another G-code in the same group is
encountered (programmed). Every G-code has a group associated with it, only one G-code of
associated group can be active at a time in CNC program
Commonly used CNC Lathe G-codes
G- codes Functions
G00 Rapid positioning
G01 Linear interpolation
G02 Circular interpolation CW
G03 Circular interpolation CCW
G04 Dwell
G20 Set units in inch
G21 Set units in metric
G28 Automatic zero return
G29 Return from zero reference position
G40 Tool nose radius compensation cancel
G41 Tool nose radius compensation left
G42 Tool nose radius compensation right
G70 Finishing cycle
G71 Turning cycle
G72 Facing cycle
G74 Peck drilling cycle
G75 Grooving cycle
G76 Threading cycle
G90 Absolute programming
G91 Incremental programming
G98 Linear feed rate per time
G99 Feed rate per revolution
M-code Function M-code Function

M00 Programs Stop M06 Tool Change


M01 Optional program Stop M08 Coolant On

M02 Program End M09 Coolant Off


M03 Spindle on Clockwise M10 Clamps On

M04 Spindle on Counterclockwise M11 Clamps Off

M05 Spindle Stop M30 Program End, reset to start


Types of programming
Types of programming

Absolute programming (G90)


• In absolute programming, all measurements are made from the part origin
established by the programmer and set up by the operator. Any
programmed coordinate has the absolute value in respect to the absolute
coordinate system zero point. The machine control uses the part origin as
the reference point in order to position the tool during program execution
Types of programming

Relative programming (G91)


• In incremental programming, the tool movement is measured from the last
tool position. The programmed movement is based on the change in
position between two successive points. The coordinate value is always
incremented according to the preceding tool location. The programmer
enters the relative distance between current location and the next point
Rapid positioning program
Command (G-00) and
linear interpolation
G 00 Rapid positioning

Format: N G00 X Z ;
N- Block number
X- final tool destination in X-axis
Z- final tool destination in Z-axis
 
• The G00 command is used primarily to move the tool to and from a cutting position. It is used most often
before and after G01, G02, and G03 command. It can also be used to position the tool for a tool change.
• G00 or also known as rapid or traverse move. G00 command is usually used for moves when machine
travels from position to position above the material and when NO CUTTING is applied. When G00
command is stated we also need to specify in which direction move will occur.
Start position of the tool upon execution of G00

End position of the tool upon execution of G00


G 01 Linear Interpolation

Format: N G01 X Z F ;
N- Block number
X- final tool destination in X-axis
Z- final tool destination in Z-axis
F- feed rate

• We use G01 with moves when machine is moving tool through material and therefore
applying various types of cutting. Normally speed of G01 move is set with F-word
(distance/ time).
Excess materials

 
Start position of the tool upon execution of G01

End position of the tool upon execution of G01


Clockwise (G02) and
Counterclockwise
(G03) Circular
Interpolation program
Command
G 02 Clockwise Circular Interpolation
G 03 counter clockwise circular interpolation

Format: N G02 X Z R ;
N G03 X Z R ;
X- End position of arc on x-axis
Z- End position of arc on z-axis
R- Radius of Arc

• Once either the G02 or G03 mode is established, arcs are defined in G-code by identifying
their 2 endpoints and the center which must be equidistant from each endpoint or an alarm
will occur.
 

P4 G02
G01

G03

P3 P2

P1
Pause/ dwell for precise
CNC timing (G04)
G 04 Pause/ dwell for precise CNC Timing

Format: G04 P ;

P- Dwell time (millisecond)


 
• G04 is called the dwell command because it makes the machine stop what it’s doing or dwell for a
specified length of time. It’s helpful to be able to dwell during a cutting operation, and also to
facilitate various non-cutting operations of the machine.
• G04 G-code is a dwell command which may also called as pause in the program, the time period
specified in the program any axis can be stopped without affecting the other commands and
functions. https://www.cnccookbook.com>g04-gcode-pause-dwell/
Calculating dwell time :

• Minimum dwell is the time required to complete one revolution of the spindle.

Minimum Dwell (sec.) = 60 / r/min.

For example, calculating dwell for 600 spindle revolution, divide 60 by r/min. ,
60/600 = 0.1 secs
Cnc-programming-tips.blogspot.com/2014/11/g04-dwell-command.html?m=1
Calculating Dwell Sec.:

• Dwell Sec. = 60 x N/ RPM

Where: 60 - number of minutes


N - number of spindle rotations
RPM – current spindle speed
Example: Dwell sec= 60 x 3/600 = 0.3
Calculating dwell rev.:

Dwell rev. = RPM x Dwell sec./60


 
Example: Dwell rev. = 600 x 0.3 x/ 60 = 3
revolution
 
Note:
• The G04 code is not a modal code.
• Dwell command is always completed before the next operation
begins.
• The actual time specified in dwell is either seconds or milliseconds.
• Dwell can also be used in the fixed cycles together with cycle data,
not in a separate block.
• When using dwell no axis motion will takes place.
• Fixed cycles like G76, G82, G88, and G89 in which dwell can be
used.
• Cycles like G84 and G74 dwell can be used only by parameter
setting.
Calculating dwell rev.:

Example:
 
N170 G90 G0 Z5.
N171 G82 X12. Y6. R2 Z-4. P300 F100 (dwell command 0.3
seconds)
Unit setting and
reference positioning
commands
G 20 Units set in English
G21 units set in metric

Format: (Inserted/ typed in header part of the program)

• The role of G20 and G21 G-codes is to tell your controller what
units the numbers in the program are in. if the program starts
with a G20, it will assume the program uses inches for
coordinates. If it starts with a G21 G-code, it will assume
millimeters.
G 28 Return to reference

Format/s: N G28 U0. W0. (tool movement going to machine zero point)
N G28 X0. Z0. (tool movement approaching to work zero point)

U- machine zero point/ incremental command or movement on X-axis


W- machine zero point/ incremental command or movement on Z-axis
 
• G28, its function is to return to the machine’s reference position, sometimes called the zero position.
That zero return position is where most programs begin, most machine will go to this position when
you manually home or reference or zero position for calculating fixture offsets for mills and geometry
offsets for lathes.
• Once the controller knows what units you’re
giving it, it uses that knowledge to convert the
coordinates to the unit system it uses internally.
Most controllers can be set up to use either metric
or imperial internally, and they will also have a
default for what units they’re expecting if the part
program has no G20 or G20
https://www.cnccookbook.com/g21-gcode-g20-cnc-metric-imperial/
Tool Nose radius
compensation
commands (G40, G41,
G42)
G 40 Cancel tool nose radius compensation
G 41 Tool nose radius compensation to left
G 42 Tool nose radius compensation to right

• When you use tool nose radius compensation on


a CNC lathe (that means we are using G41 and
G42) you have to tell the machine where the
cutting point of the turning tool is so that the
correct tool path is produced.
• The tool nose radius is generally rounded and so a
hypothetical tool nose point is treated as the tool nose
for programming. With such a programming, an error
caused by the tool rounding arises during taper
cutting or arc interpolation between the actually
programmed shape and the cutting shape. Nose R or
tool radius compensation is a function for
automatically calculating and offset setting this error
by setting the nose radius or tool radius value.
Facing
2

3 7
Turning

Boring
6

8
1

4 5

Back facing
G 40 Cancel tool nose radius compensation
G 41 Tool nose radius compensation to left
G 42 Tool nose radius compensation to right
• The G40 command cancels any compensation that was applied to the tool during a
program and acts as a safeguard to cancel any cutter compensation applied previously.
• The G41 command applies tool nose radius compensation left to allow the programmer
with turning and boring tools using actual coordinates, not following for the radius of the
tool. The offset register value will compensate for the difference caused by the small radius
on the tool.28
• The G42 command applies tool nose radius compensation right to allow the programmer to
program with turning and boring tools using actual coordinates, not allowing for the radius
of the tool. The offset register value will compensate for the difference caused by the small
radius on the tool.
Commonly used M-
codes
M-codes

• M-codes are miscellaneous functions, which include actions necessary for


machining, but not those that are actual tool movements. That is, they are
auxiliary functions, such as spindle on and off, tool changes, coolant on
and off, program stops, and other related similar functions.
M 00 Program Stop and M 01 Optional program stop

M 00 Program Stop

Format: N M00 (inserted in the header part of the program)


 
• The M00 command is a temporary program stop function. When it is
executed, all functions are temporarily stopped, and will not restart unless
and until prompted by user input.29
M 00 Program Stop and M 01 Optional program stop

M 01 Optional program stop

Format: N M01 (inserted in the header part of the program)


 
The M01 command is an optional stop command and halts program execution only
if the M01 switch is set to ON. If the M01 switch is set to OFF, the program will
ignore any M01 commands it encounters in a program and no optional stop will be
executed
M 02 Program End
M30 program stop and rewind

Format: N M02
N M02 (inserted in the end part of the program)
 
• The M02 command indicates an end of the main program cycle operation.
Upon encountering the M02 command, the MCU switches off all machine
operations (for example, spindle, coolant, all axes, and any auxiliaries), and the
program is terminated.
• This command is found by itself on the last line of the program.
M 02 Program End
M30 program stop and rewind

Format: N M02
N M30 (inserted in the end part of the program)
 
• M02- end the program. Pressing cycle start (“R” in the axis GUI) will
restart the program at the beginning of the file.
• M30- exchange pallet shuttles and end the program. Pressing the cycle
start button will start the program at the beginning of the file.
M03 Spindle on clockwise
M04 spindle on counter clockwise
M05 spindle off

 Format: N S M03
N S M04
N M05 (inserted mostly in the end part of the program or before tool changing operation)
S- spindle speed/ RPM
 
• M03 is the M-code used in the CNC program to activate the spindle along the clockwise direction with
given spindle speed specified with the alphabet “S”.
•  
• M04 is the M-code used in the CNC program to activate the spindle along the counter clockwise direction
with given spindle speed specified with the alphabet “S”.
M06 tool change

• Format: N T M06;

T- tool magazine number

• M06 is the M-code used in the CNC program to activate the automatic tool
change along which T number called on the program. As soon as the controller
reads the T number with M06 it will search the tool magazine for the T number
specified and rotates and brings the tool into the spindle.
M07 shower coolant or flood coolant
M08 coolant on
M09 coolant off

• Format: N M08; (used only during the process of stock removal)


N M09;
 
• M08 mist coolant, in general this M code activates the mist coolant pump and the coolant is flooded into the machine
through the pipes provide near spindle and flow is directed towards the cutting of material by tool. This cools the tool
which gets heated by the material cutting forces. The basic mist uses the venturi principle for operation. When air is
introduced to a typical unit and the “air valve” is open, it passes completely through and is released at the “nozzle tip”.
The air stream forms a “venturi”, creating suction that draws coolant from a coolant reservoir to the “coolant port”
where it joins the air to form a mist spray. The force of the spray is easily regulated by adjusting the “air valve”33
• M09, this M-code turns off all the coolant commands running on the controller. Programmer has to keep in mind not to
use M09 while the material cutting is in progress. It must be switched off only when required or at the end of the tool
finishes the cutting.

You might also like