CNC PROGRAM

cnc program

Structure and contents of an CNC program

An NC (Numerical Control) program is a set of instructions used to control the movements of a machine tool or a machining process. These programs are typically written in a language understood by the specific CNC (Computer Numerical Control) machine being used.

Blocks and block components

Blocks

An NC program consists of a sequence of NC blocks. Each block contains the data for the execution of a step in the workpiece machining.

Block components

NC blocks consist of the following components:

  • Commands (statements) according to DIN 66025
  • Elements of the NC high-level language

Commands according to DIN 66025

The commands according to DIN 66025 consist of an address character and a digit or sequence of digits representing an arithmetic value.

Address character:

The address character (generally a letter) defines the meaning of the command.
Examples: Address character Meaning: G function (preparatory function), X Position data for the X axis, S Spindle speed … etc

the meaning of addresses commonly used in CNC programming for machine tools:

AddressMeaning
ARotational movement around X-axis
BRotational movement around Y-axis
CRotational movement around Z-axis
DTool radius offset
EMachine-specific use
FFeed rate (tool movement speed)
GGeneral function (e.g., movement)
HTool length offset
IIncremental position along X-axis
JIncremental position along Y-axis
KIncremental position along Z-axis
LNumber of repeats in a subroutine
MMiscellaneous function (e.g., spindle control, coolant)
NLine number (optional)
OProgram number (optional)
PDwell time (pause)
QFeed per revolution (threading)
RArc radius
SSpindle speed
TTool selection
UIncremental position along U-axis
VIncremental position along V-axis
WIncremental position along W-axis
XAbsolute position along X-axis
YAbsolute position along Y-axis
ZAbsolute position along Z-axis

These addresses represent various parameters and commands used to control the movements, tool selection, spindle speed, and other functions of a CNC machine tool. The meanings may vary slightly depending on the specific machine, control system, and programming language being used.

Digit sequence

The digit sequence is the value assigned to the address character. The sequence of digits
can contain a sign and decimal point. The sign always appears between the address letter and the sequence of digits. Positive signs (+) and leading zeroes (0) do not have to be specified.

Elements of the NC high-level language

As the command set according to DIN 66025 is no longer adequate for the programming of complex machining sequences in modern machine tools, it has been extended by the
elements of the NC high-level language.
These include, for example:

  1. Commands of the NC high-level language

In contrast to the commands according to DIN 66025, the commands of the NC high-evel
language consist of several address letters, e.g.

  • OVR for speed override
  • SPOS for spindle positioning
  1. Identifiers (defined names) for:
    • System variables
    • User-defined variables
    • Subprograms
    • Keywords
    • Jump markers
    • Macros
  2. Comparison operators
  3. Logic operators
  4. Arithmetic functions
  5. Check structures

Effectiveness of commands

Commands are either modal or non-modal:

  1. Modal : Modal commands retain their validity with the programmed value (in all following blocks) until:
    • A new value is programmed under the same command
    • A command is programmed that revokes the effect of the previously valid command
  2. Non-modal : Non-modal commands only apply for the block in which they were programmed.

CNC PROGRAM : G-CODE EXAMPLE

CNC ProgramComments
%-The percent sign marks the beginning of a file or program. There is one at the beginning and one at the end. Not always necessary on newer machines.
O02215– O and the numbers that follow make up the label number.
(Mill Demonstration) – Anything within parenthesis is comments for the user or programmer to see. The machine does not use them.
(G54 is X Y Part Zero )– Comment. This lets the operator know offset #1 is X Y Part Zero. G is code for General.
(X Y Part Zero is the CENTER of the part)– Comment. This lets the operator know G54 is  the center of the part.
(Material is 4″ long by 2 1/2″ wide by 1/2″ thk. aluminum)– Comment. This is part material information.
(Part will be profile milled to 2.200 wide by 3.700)-Comment. Future part dimension information for after milling.
(Set Z tool offsets T1 T2 T3 on the top of the part)– Comment. This is to set the Z axis for the three tools T1, T2 and T3 to the top of part. T is code for Tool.
(D01 is Cutter Comp for T1 .250)– Comment. D is code for setting Diameters. In this case setting tool 1 for .250.
(T1 1/2″ 4 flute End Mill)– Comment. Tool 1 is a 1/2″ Flute End Mill.
(T2 1/2″ Spot Drill)– Comment. Tool 2 is a 1/2″ Spot Drill.
(T3 #3 Drill .213 Dia.)– Comment. Tool 3 is a .213 diameter Drill.
(Press Option Stop for M1)– Comment. M is code for Miscellaneous or Machine, depending on who you are asking. I have seen both referenced. M1 stops a program temporarily if the optional stop switch is on.
G17 G40 G80 G98– G17 selects the X Y plane. G40 sets the path compensations off. G80 cancels all cycles and returns Z axis back to initial Z level or R level. In this situation, it will return to R level which is meant by G98. 
G28 G91 Z0 Y0– G28 returns to home position (machine zero). G91 sets incremental programming. Z0 an Y0 set axis Z and axis Y to 0.
M01– Optional stop. Will only stop if the operator pushes the optional stop button.
(T1 1/2″ End Mill )– Comment. Tells us tool 1 is a 1/2″ End Mill, like in the beginning of the program.
N10 T1 M06– N is code for a line number. Used like a GOTO statement. T1 M06 means tool change, use tool 1. Some machines need to be told to change the tools; others have the tools indexed so when giving a tool statement, the machine will automatically change.
S2200 M03– S is code for speed, either spindle speed or surface speed, depending on the mode. 2200 is the rpm’s. M03 means spindle on in clockwise motion for the speed just set.
G00 G90 G54 X-2.35 Y1.7– G00 moves each axis at its max speed. G90 means fixed or simple cycle. G54 selects zero offset one. Moves axis X -2.35″ and axis Y 1.7″.
G43 H01 Z1. M08– G43 means tool height offset compensation, followed by the H command H01 meaning up 1. This corresponds to the command Z1, axis Z up 1. M08 means coolant on.
G01 Z-0.15 F50.– G01 means linear interpolation, a straight line between points. Z-0.15 means Z down .15″. F is code for Feedrate and that is set to 50 here. Using right hand rule for coordinates: Z axis – is down, + is up, Y axis – is left, + is right, X axis – is away, + is toward the operator.
(Begin to Mill Profile)– Comment. Begin the milling process.
(Activate Cutter Compensation)– Comment. This is stating the cutter compensation coming up in the following instructions.
G42 X-1.85 D01 F50.– G42 means tool radius compensation right for conventional or up milling. Done for -1.85″ on axis X. at a diameter of 1″ (D01) at a feedrate of 50 (F50).
G01 Y-0.6 F10– Linear interpolation (G01) on axis Y for -0.6″ at a feedrate of 10 (F10).
G03 X-1.35 Y-1.1 R0.5– G03 is a circular interpolation, instead of a line, and this is counterclockwise. This is done on axis X for -1.35″, and axis Y for -1.1″. The radius compensation is .5″(R0.5).
G01 X1.6– Linear interpolation axis X for 1.6″.
G03 X1.85 Y-0.85 R0.25– Counterclockwise circular interpolation on axis X for 1.85″, and axis Y for -0.85″ at a radius compensation of .25″
G01 Y0.43– Linear interpolation on axis Y for .43″.
G01 X1.5375 Y1.1 – Linear interpolation to a point at axis X 1.5375″ and axis Y 1.1″ from current point.
G01 X-2.35– Linear interpolation axis X -2.35″.
(Deactivate Cutter Compensation)– Comment. States the next operation.
G40 G01 X-2.55 F25– G40 shuts off radius compensation. Linear interpolation axis X -2.55 at a feedrate of 25.
G01 Z0.1 F50– Linear interpolation axis z .1″ at a feedrate of 50.
(Mill 1.000 X .750 Pocket)– Comment. States the next operation.
G00 X0.675 Y0.125– Reposition axis’ at max speed. Axis X .675″ and axis Y .125″.
G01 Z-0.075 F1.5– Linear interpolation axis Z -.075 at feedrate 1.5.
G01 X1.175 F4– Linear interpolation axis X 1.175 at feedrate 4.
G01 Y-0.125– Linear interpolation axis Y -.125″.
G01 X0.675– Linear interpolation axis X .675″.
G01 Y0.125– Linear interpolation axis Y .125″.
G01 Z0.1 F50– Linear interpolation axis Z .1″ at feedrate 50.
G00 Z1. M09– Reposition axis’ at max speed. Axis Z 1″. Coolant off (M09).
G28 G91 Z0. Y0. M05– Return to home position, machine zero. Incremental programming. Axis Z at 0, axis Y at 0. Stop spindle.
M01– Optional stop.
(T2 1/2″ Spot Drill)– Comment. Relates what tool 2 is and will be used.
(Spot Drill 4 places)– Comment. Statement of what the tool will be used for.
N20 T2 M06.– Line number 20 – Tool 2. Statement of tool change to tool 2.
S2000 M03 –Speed 2000RPM, spindle on clockwise rotation.
G90 G54 G00 X-0.5 Y0.5– G90 changes to absolute programming. This means all measurements come from one origin, instead of incremental. From zero offset 1, reposition axis’ at max speed to axis X -.5 and axis Y .5.
G43 H02 Z1. M08– Tool height offset, and the offset is a negative 2. Axis Z for 1″. Coolant turned on.
G01 Z0.1 F50– Linear interpolation axis Z .1″ at a feedrate of 50.
G83 G99 Z-0.11 Q0.02 R0.1 F6– G83 is peck hole drilling with return to R level for clearing out chips being G99. Axis Z -.11″ and Q is the peck increment which is .02″ with a radius compensation of .1″ at a feedrate of 6.
X-1.5 Y0.5– Drill place 2 at axis X -1.5″ and axis Y .5″.
X-1.5 Y-0.5– Drill place 3 at axis X -1.5″ and axis Y -.5″.
X-0.5 Y-0.5– Drill place 4 at axis X -.5″ and axis Y -.5″.
G80 G00 Z1. M09– G80 cancels canned cycle and returns to initial level. From zero offset 1, axis Z 1″, and then coolant off.
G28 G91 Z0. Y0. M05– Return to home position, machine zero. Incremental programming. Axis Z at 0, axis Y at 0. Stop spindle.
M01– Optional stop.
(T3 Drill #3 holes)– Comment. Relates what tool 3 is and will be used.
(Drill 4 places)– Comment. Statement of what the tool will be used for.
N30.T3 M06– Line 30- Tool. Statement of tool change to tool 3.
S2200 M03– Speed 2200RPM, spindle on clockwise rotation.
G90 G54 G00 X-0.5 Y0.5– G90 changes to absolute programming. This means all measurements come from one origin, instead of incremental. From zero offset 1, reposition axis’ at max speed to axis X -.5 and axis Y .5.
G43 H03 Z1. M08– Tool height offset, and the offset is a negative 3. Axis Z for 1″. Coolant turned on.
G01 Z0.1 F50– Linear interpolation axis Z .1″ at a feedrate of 50.
G83 G99 Z-0.6 Q0.075 R0.1 F6– G83 is peck hole drilling with return to R level for clearing out chips being G99. Axis Z -.11″ and Q is the peck increment which is .02″ with a radius compensation of .1″ at a feedrate of 6.
X-1.5 Y0.5– Drill place 2 at axis X -1.5″ and axis Y .5″.
X-1.5 Y-0.5– Drill place 3 at axis X -1.5″ and axis Y -.5″.
X-0.5 Y-0.5– Drill place 4 at axis X -.5″ and axis Y -.5″.
G00 G90 Z1. M09– Reposition axis’ at max speed. G90 changes to absolute programming. This means all measurements come from one origin, instead of incremental. Axis Z 1″. Coolant off (M09).
G28 G91 Z0. Y0. M05– Return to home position, machine zero. Incremental programming Axis Z at 0, axis Y at 0. Stop spindle..
M30– End of program.
%– End of program marking.

Leave a Reply