CNC Programming Language - G Code and M Code
In the world of CNC machine tools, G code and M code are like a pair of tacit partners. They control every movement and operation of the machine tool together and are also the core parts of the machine tool. This article will explain what G code is and what M code is. Why they are called the key to CNC machine.
G code: The full name is "preparation function code". The main function is to specify the movement trajectory and processing method of the machine tool. For example, the G00 code is for rapid positioning. The machine tool will move to the specified coordinate position at the fastest speed. It is often used to quickly approach the workpiece or quickly adjust the tool position; the G01 code represents linear interpolation. The machine tool will move in a straight line at a given speed and path to cut a straight line contour; G02 represents clockwise circular interpolation, and G03 is counterclockwise circular interpolation. These two codes allow the machine tool to accurately process various arc shapes. There are also G28 for returning to the reference point, G30 for returning to the second reference point, etc. These G codes are like instruction sets for machine tool movement, providing a basis for various complex processing techniques.
M code is a kind of auxiliary function code, which controls some auxiliary actions and status of the machine. For example, M03 indicates the forward rotation of the spindle, which makes the spindle of the machine tool rotate at the speed set by the worker. M04 is used for the reverse rotation of the spindle. there are many auxiliary codes.
There are many lists of G codes and M codes, each with parameters and functions. The code consists of numbers and letters, which are input into the machine tool through programming software, and then the machine tool performs corresponding actions according to the received code instructions. Of course, if it is a machine model of different brands, there may be a little difference, but the overall situation remains unchanged. Some functions are mentioned in the introduction above. Next is the full function of G code and M code, which can be checked.

G code full list and function
G00: Rapid positioning, rapid movement to the specified position.
G01: Linear interpolation, linear cutting.
G02: Clockwise circular interpolation.
G03: Counterclockwise circular interpolation.
G04: Pause.
G17: Select XY plane.
G18: Select XZ plane.
G19: Select YZ plane.
G20: Select English units.
G21: Select metric units.
G28: Return to reference point.
G30: Return from reference point.
G33: Thread cutting.
G40: Cancel tool radius compensation.
G41: Tool radius left compensation.
G42: Tool radius right compensation.
G43: Tool length positive compensation.
G50: Set workpiece coordinate system.
G90: Absolute programming.
G91: Incremental programming
M code list and functions
M03: Spindle forward rotation.
M04: Spindle reverse rotation.
M05: Spindle stop.
M06: Tool change.
M08: Coolant on.
M09: Coolant off.
M30: Program end and rework.
M98: Subroutine call.
How to read and write G & M code programs
G & M code programs usually consist of a series of instructions, each on a line. Instructions start with a letter, followed by one or more parameters. For example, G01 means linear interpolation, and X100.0 Y200.0 means move to coordinates (100.0, 200.0) on the X and Y axes. Being familiar with the code format is the basis for reading and writing programs. This part is to understand.
Then learn the commonly used codes and their functions. Commonly used code functions can help you quickly understand and write programs.
Generally speaking, G & M code programs usually consist of multiple program segments, each of which performs a specific operation. Understand the function and role of each program segment. Comments can be used to help understand the structure and function of the program. Comments start with a semicolon (;) and are followed by the comment content.
Write the G & M code program according to the processing requirements and machine tool specifications. Finally, debug it, which can be debugged by simulating the processing. If errors are found, they should be corrected in time.
Finally, add a few points to note
Coordinate system: When using the G90 command, since G90 is absolute programming, all coordinates are relative to the program origin, commonly known as (absolute position). G91 is incremental programming, and its coordinates are calculated relative to the offset of the current position.
Tool: If the tool is in radius compensation, G41 and G42 can be used for compensation. G41 is (left tool) and G42 is (right tool).
Unit setting: The unit setting cannot be wrong. G20 and G21 are set correctly to avoid errors.
Coolant: M8 and M9 are used to control the coolant switch.
With the continuous development of CNC technology, G code and M code are also constantly updated and improved. New G code and M code functions continue to emerge, providing more possibilities for machine tool processing. For example, some advanced G code functions can realize the processing of complex surfaces and improve processing efficiency and precision; M code can also be used to control more auxiliary equipment, such as automatic tool change system, online measurement system, etc. The above is a basic explanation of G code and M code.
This article describes the application of G code and M code in CNC programming. G code and M code play a vital role in CNC machine tools. Jeek is a leading manufacturing company in China. The company has three-axis, four-axis and five-axis. If you have products that need to be processed, you can provide drawings or contact us, and we will reply to you in time.
