The precision you find with CNC machining is largely due to the exact instruction machines receive from the computer processor. Standard codes are used to dictate the location, operation, and speed of precision manufacturing. There are two different CNC machine codes to deal with. The term G-Codes is used as an overall capture, but M-Codes are quite different in that they are specific to CNC machine operations and machine manufacturers. It’s important to know the difference between the two.
G-Codes
The original geometric codes standardized for CNC machining worked on small processors. This meant commands needed to be simple and exact. The official code is RS-274D, but since many codes start with the letter G, the default name was adopted. Simple alpha-numeric codes translate to every possible function in the machining process.
Each machining process needs to begin with basic functions provided through G-Codes, such as, load the required tool, turn on the spindle at a specified speed, activate the coolant, and place the tool at exact coordinates to align properly before cutting proceeds.
Most G-Codes will be directional, or geometric, in nature. They include a digit (sometimes two) after the letter to designate a function. Common G-Codes include G0 – move to a certain point (go), followed by an alphanumeric location, and G1 – move in a straight line from point to point, also defined by alphanumeric codes that define the axis and distance. G-Codes also include arcs and dictate the plane the tool is cutting on.
Other important G-Codes include tool length or diameter to provide compensation for the cutting tool on the workpiece. These codes utilize D and H prefixes followed by the numeric measurement of the offset.
Canned Cycles
Many G-Code sequences are repetitive and common to many operations. Abbreviated codes, such as a simple drilling cycle, utilize the G81 code followed by only coordinates, speed, plane, and depth of drill. The motion of drilling and retracting is built into the G81 code, as opposed to the many lines of code that would be needed to activate the same process.
M-Codes
Not all CNC machines can perform the same functions. Or they may perform them in a slightly different manner. This is where specific codes created by machine manufacturers, or M-Codes, have been introduced. Each machine will come with a set of M-Code specifications. This is an important piece of data for machinists and programmers to understand if they are working with different machines in their shop. Even the addition of a “0” in the coding, and no operational differences in the machine, will affect the success of a program.
M-Codes are generally the large machine commands, such as spindle speed, coolant commands, and on and off control because these relate directly to the machine’s specific engineering. Multiple M-codes are not often used in the same code block because that will cause operating problems.
Code Blocks
A Code Block is a series of codes programmed together to complete an action. For example, in a multi-stage machining process, the spindle will start to rotate and a series of actions will be performed. The tool and spindle will return to the home position before the second cutting operation is performed. An example would be when the overall shape of a part is cut before a drilling operation is put into action. Each operation is treated separately from start to finish. Tools are replaced and the workpiece is cleaned. Newer technology prompted by robotics and smart computers in Industry 4.0 sees machines housing multiple tools and spindles that can approach a workpiece from different angles. These operations, though more complicated to program, can machine a complete workpiece in one code block.
A Bit of History
The first step to automation from manual machining used a card-punching system to program commands. Cards often became damaged or lost on the shop floor. The next step was for machinists to manually enter the G-codes and M-codes into the CNC machine. Smarter and faster computer processors now determine and program the code for machining operations directly from CAD designs. It is still critical for operators, programmers, and machinists to know CNC machine codes to troubleshoot and have an understanding of design and manufacturing principles. These codes are the very basics of CNC machine operations.