2023.11.23
CNC systems are widely used in manufacturing processes to automate machinery and tools. A crucial component of CNC programming lies in the use of G-codes and M-codes, two distinct languages that instruct CNC machines regarding various operations. In this guide, we talk about the difference between G-code and M-code in the CNC machining process.
G Code: What are G Codes Used for in CNC
G-code is the most common CNC programming language used to control motion and position of machine tools like milling machines, lathes, routers, welding machines, 3D printers etc.
– G-code commands start with the letter G followed by a numeric code. For example, G01, G02, G03 and so on.
– G-codes are used mainly to specify the type of motion, feed rates, coordinate offsets and canned cycles needed to machine the part.
G-code programs describe the tool path and motion geometry needed to machine the part. CAD/CAM software automatically generates optimized G-code programs required by the CNC machine.
What is M-Code: What are M Codes Used for in CNC
M-codes are miscellaneous commands used in CNC programming to control machine functions like coolant, spindle speed, tool change etc.
– M-codes start with the letter M followed by numeric codes. For example, M03, M05, M30 etc.
– M-codes control auxiliary functions and machine modes like turning on/off coolant, spindle speed override, pallet change, program end etc.
– G-codes mainly control motion and location. M-codes control machine functions.
– G-codes move the tool while M-codes activate the machine capabilities needed for cutting.
– G-codes depend on the machine type while M-codes are more generic across machine tools.
– A complete CNC program requires both G and M-codes for machining a part. G-codes define the toolpath geometry while M-codes manage the machine actions.
G Code List – G Codes for CNC Lathe
G00: Rapid Position Motion
G01: Linear Interpolation Motion or Linear Motion, Chamfer and Corner Rounding – Modal
G02: CW Circulation Interpolation Motion – Modal
G03: CCW Circular Interpolation Motion – Modal
G04: Dwell (P) P=Seconds. Milliseconds
G05: Fine Spindle Control Motion (Live Tooling) – Optional
G09: Exact Stop
G10: Programmable Offset Setting
M Codes for CNC Lathes
M00: Program Stop – Modal
M01: Optional Program Stop – Modal
M02: Program End – Modal
M03: Spindle on Forward (S) – Modal
M04: Spindle on Reverse (S) – Modal
M05: Spindle Stop – Modal
M08: Coolant On – Modal
M09: Coolant Off – Modal
M10: Chuck Clamp – Modal
G Code List for CNC Milling
G00: Rapid Motion
G01: Linear Interpolation Motion
G02: CW Interpolation Motion
G03: CCW Interpolation Motion
G04: Dwell
G09: Exact Stop
G10: Programmable Offset Setting
G12: CW Circular Pock Milling (Yasnac)
G13: CCW Circular Pock Milling (Yasnac)
G17: XY Plane Selection
M Codes for CNC Milling
M00: Program Stop
M01: Optional Program Stop
M02: Program End (Setting 39)
M03: Spindle On, Clockwise (S) (Setting 144)
M04: Spindle On, Counterclockwise (S) (Setting 144)
M05: Spindle Stop
M06: Tool Change (T) (Setting 42, 87, 155)
M08: Coolant On (Setting 32)
M09: Coolant Off
M10: 4th Axis Brake On
Bonus Tips
– The first step towards making a CNC program is understanding the G codes and M codes. Which are referred to as preparatory codes and miscellaneous codes.
By knowing what individual g codes and m codes are and how the machine functions , you can start combining individual g and m codes to form “ program blocks”.
– The next step would be to have knowledge about things like work offsets, tool offsets, what they are and how they are incorporated in programming.
– Another critical ability would be the ability to understand the engineering drawing and using that to machine in practical sense.
With these three main ideas one can make a CNC program with ease .
A good programmer can use various methods to reduce the cycle time of machining and hence save a lot of time and improve the productivity on the whole.