CNC Programming

When producing a CNC program, a clear program structure is required. Whatever system used to create a CNC program one should consider that there is a possibility of errors (bugs) It is easier to debug a program that is written in a structured manor. The program structure is especially important in the case of very large programs that have been created by others so that they can be understood by the operator who might be testing the program on a machine and need to edit t5o make adjustments.

The contruction of a CNC block

Unlike conventional lathes, modern CNC machines have a numerical control system. The control translates a CNC program, by reading the individual work steps (Blocks), which are set out in an understandable language (codes), so that the workpiece machining is performed automatically.

Block

A CNC program consists of several blocks (lines) where the executing codes are located. The blocks are consecutively numbered, and the block number is indicated by the letter "N" with subsequent digits for the block number and then Word, Address, Value.

A CNC block usually contains several words. A word consists of an address (letter) and a value, or code (number).

Example:

N110G01X+60M03
Block No.WordWordWord

Note the meaning, G01 Linear Interpolation (movement in a straight horizontal or vertical line or at an angle if the block contains an X, and a Z, word). The value X+60 (X60gg) is the length of the move in X. The word M03 will start the spindle forward.

Modal Codes and Block Dependamt Codes

Modal codes are self-maintaining, meaning that the code is active over several blocks until it is revoked or overwritten by another code in its group. Block dependent codes only work in the block in which they are written. e.g., N120 G04 F1.5 (Dwell for 1.5 seconds)

Modal codes are e.g., codes such as speed / cutting speed, feed rate, direction of rotation and tool data. Since these codes are active over several blocks, you only need to enter them once.

G codes are preparatory codes and M codes are auxiliary functions.

Example:

N115F0.07S1800M03Here the feedrate is programmed to 0.07mm / rev The speed to 1800 rpm and the direction of rotation is forward.
N120G01Z-60F0.04The tool moves from its position in a linear motion (G01) to the position Z = -60.
N125X+70Since the code G01 is modal, the tool moves further perpendicular to the position X = 70.
N130Z-85The tool moves horizontally to Z = -85

Format of Addresses

Most CNC codes have multiple addresses. The addresses have different behavior depending on their composition, the difference is that some must be written together Others must always be written together and, in some cases, only one code must be written and the other omitted. We name the different options in the following way:

Mandatory possible alternatives

The difference between mandatory, possible, alternative, and related codes is here, determined and described as follows:

Obligatrory

There are some CNC codes that must be written together and should be on a line alone with no other words. Example: G96 S ... Together with the code G96 (constant cutting speed), the address S must be programmed with the desired value.

Possible Adressess

Are the addresses that can be programmed with the code but can be omitted as needed. The description of these addresses is given in square brackets.
Example: G85 N… D… [U] [W]
In the NC block example, the addresses N and D must be programmed. If U and W are omitted, they are considered 0.

Alternative

Are addresses where one address or the other must be omitted.

Example Auto Chamfering:
G75 X L or
G75 Z L..

i.e. that either the address X or Z must be programmed