G-Code and M-Code: What Does It Mean in CNC Machining?
CNC machines have become an integral part of the manufacturing process. Modern-day CNC machines come with advanced features and functionality to support automation, integration, programmability, etc. However, to tap into this potential, CNC machining personnel must be well-versed with the technology to facilitate such functioning.
In short, apart from manual operation, operators and programmers need to have an understanding of machine programming to run high-end multitask, multiaxis CNC machines. This post gives an overview of the G-Code and M-Code and what they mean in CNC machining. So let’s dive right in.
Pic. source: https://www.secotools.com
What Are G-Code and M-Code in CNC Machining?
G-Codes and M-Codes are dedicated programming languages that control lathes, milling machines, 3D printers, and other CNC machines. They form the basic foundation of computer-aided manufacturing software. And while they may function together, they have specific roles cut out for them, which are as follows:
G-Code controls the machine movement and regulates how or where the parts, such as the spindle, should move to aid fabrication.
M-Code controls the miscellaneous functions of the machine, such as defining when to start or stop a particular action or program.
As one can see from above, the G-Code and M-Code play very complementary roles for machining the part.
G-Code is the original programming that was used by NC machines.
Even though it lacks the standardized technical nomenclature, G-Code stands for “Geometric” codes. It plays a preparatory role and controls the machine part’s position, movement, and shape.
G-Codes are essentially a variation of three main tool motions:
– Straight line motion, as fast as possible
– Straight line motion at a defined speed
– Move along a circle at a specific speed
To indicate these functions, G-Code contains an alphanumeric sequence that primarily dictates what to move, how to move, and where to go. However, the main issue with G-Code lies in the non-standardization of these sequences. Hence the same code could bear different meanings in different machines.
For instance, one may respond to G1, while the other requires the input as G01.
Functions of G-Code Machining
Naturally, the letter G indicates geometry against which the tool should move or stop in the G-Code. However, the G-Code also involves other functions like:
– N for the line number.
– X, Y, Z for the positioning of the tool in the X, Y, and Z axes.
– F for the feed rate of the workpiece.
– S indicates the spindle or cutting speed.
– T stands for the tool that the machine should use.
– I and J indicate the incremental center of arcs that the machine makes.
– R is the radius of the arc.
– A is the position of the auxiliary axis rotating around the X-axis.
– B is the position of the auxiliary axis rotating around the Y-axis.
– C is the position of the auxiliary axis rotating around the Z-axis.
– D is the tool diameter offset.
– L stands for loop, which indicates the number of iterations for any operation.
– P helps with delayed functions or jump in time.
Hence, the operator must have an in-depth understanding of the language of the machine that they are operating.
Examples of G-Code Machining
Some common G-codes used in machining include:
G00 – rapid positioning to a specified coordinate.
G01 – linear feed movement.
G02 – circular or helical feed movement (clockwise).
G03 – circular or helical feed movement (anti-clockwise).
G17 – X-Y plane selection.
G18 – X-Z plane selection.
G19 – Y-Z plan selection.
G20 – programming in inches.
G21 – programming in millimeters.
G90 – absolute moves.
G91 – incremental moves.
Pic. source: https://www.sandvik.coromant.com
Technically, M-Code is a sub-section of the G-Code. M-Code expands on the G-Code and goes beyond geometry.
As stated previously, the M in M-Code stands for “Miscellaneous” functions. However, it could also indicate “Machining” functions as it controls machine variables such as tool speed, tool change, coolant ejection, pallet change, etc.
M-Code also experiences a change in program dialect with a change in environment. As such, the operator must know where to use M0 and where to input M00.
Functions of M-Code Machining
Like G-Code, M-Code requires one block of information per line. All codes are generally associated with the letter M followed by the numeric string. Some CNC machines allow M-code customization where the operator can define the function against a code.
Some examples of M-Code are as below:
M00 – stop function.
M01 – stop program.
M02 – end of program.
M03 – move spindle linearly or clockwise.
M04 – move spindle in reverse or anti-clockwise.
M05 – stop spindle movement.
M06 – load tools (This usually includes the T command since it indicates which tool to load).
M08 – release coolant.
M09 – stop coolant flow.
The primary difference between G-Code and M-Code is clear: they control different movements of the equipment. G-codes control the geometry and cutting, while M-codes control the other functions.
Chances are you may have used G-codes and M-codes at some point while programming a CNC machine. However, user-friendly tools, such as CAM software applications, must have masked this usage through a simplified interface.
Regardless, now you know!
Want to reduce waste of machine capacity in your shop floor, improve profits via Industry 4.0 ?
Check out our LEANworx CNC machine monitoring system.
You start seeing big results in just a couple of weeks.
Want to just learn what Industry 4.0 is ?
We have a great blog on what is Industry 4.0.
About the Author
Peter Jacobs is the Senior Director of Marketing at CNC Masters. He is actively involved in manufacturing processes and regularly contributes his insights for various blogs in CNC machining, 3D printing, rapid tooling, injection molding, metal casting, and manufacturing in general.