Programming Structure
Programs are a group of commands executed to control the machine by the CNC control unit. These commands are written in sequence, line by line, to be executed in order. Each line contains commands for axis movement, operation of peripheral units, tool changes, etc. These lines are also referred to as G-code blocks. Each G-code line (block) must be terminated with a line end character.
CNC codes are created by a command indicated by a letter, followed by a numerical value. Each letter (code) has a specific meaning.
The functions of the codes are as follows:
|
Code |
Function |
Alternative Function |
Type |
|
A |
A-axis movement |
|
Decimal |
|
B |
B-axis movement |
|
Decimal |
|
C |
C-axis movement |
|
Decimal |
|
D |
Tool radius compensation number |
|
Integer |
|
E |
Extruder axis movement |
|
Decimal |
|
F |
Cutting feedrate |
|
Decimal |
|
G |
Preparation codes |
|
Decimal |
|
H |
Tool length compensation number |
|
Integer |
|
I |
Distance to the center of the arc on the X axis |
|
Decimal |
|
J |
Distance to the center of the arc on the Y axis |
|
Decimal |
|
K |
Distance to the center of the arc on the Z axis |
|
Decimal |
|
L |
Subprogram repetition count |
|
Integer |
|
M |
General purpose use codes |
|
Integer |
|
N |
Line number |
|
Integer |
|
O |
Program number |
|
Integer |
|
P |
Subprogram number / Waiting time |
Auxiliary integer |
Integer |
|
Q |
Auxiliary decimal number |
|
Decimal |
|
R |
Radius value |
Auxiliary decimal number |
Decimal |
|
S |
Spindle rotation RPM |
|
Integer |
|
T |
Tool number |
|
Integer |
|
U |
U-axis movement |
X axis incremental target (Lathe) |
Decimal |
|
V |
V-axis movement |
Y axis incremental target (Lathe) |
Decimal |
|
W |
W-axis movement |
Z axis incremental target (Lathe) |
Decimal |
|
X |
X-axis movement |
Wait value |
Decimal |
|
Y |
Y-axis movement |
|
Decimal |
|
Z |
Z-axis movement |
|
Decimal |
The codes must be written adjacent to their corresponding values. Two codes do not have to be adjacent; a space can be left between them. A dot (.) cannot be added to the value next to integer codes. Characters like "+", "-", or "." cannot be added before the codes.
Incorrect Writing Examples:
X 100 (There is a space between X and the value 100)
G04 P20. (A . (dot) has been added next to a code of integer type)
-X100 (A – (minus sign) has been added before the X code)
Correct Writing Examples:
X100
G04 P20
X-100
If a code of decimal number type does not have a "." (dot) at the end, the decimal part of the number is processed as .0000. Similarly, if only the dot is added without any value following it, this value will also be processed as .0000. Similarly, any digit not added after the dot will be processed as 0.
X100 => X100.0000 will be processed
X100. => X100.0000 will be processed
X100.2 => X100.2000 will be processed
A code can be followed by either a fixed number or a variable. Variables are indicated with the "#" prefix.
#0 = 2000000
X#0 => X200.0000 will be processed
X-#0 => X-200.0000 will be processed
A value or variable number must always be specified next to a code. Each line must end with a line-ending character. A ";" (semicolon) can be added at the end of the line, but it is not mandatory. It is recommended to add the "%" character at the end of the program.
In the program, comments can be written between the characters "(" and ")". The content within these characters will be ignored and not processed.
(COMMENT)
X100. (COMMENT NEXT TO THE CODE)
The codes can be specified in either uppercase or lowercase. A code block cannot exceed 63 characters in length.
A program template can be created as follows:
