M-Code Commands: Meanings, Commands and Simulators

what is M-code Commands?

Computer Numerical Control (CNC) is an indispensable part of contemporary manufacturing. Many machines usually run under instructions and guidelines that can be downloaded via a CNC program controller.

For a machine to interpret the commands from CNC, the commands need to be input using G and M codes. CNC operators must also be aware of the appropriate codes, instructions and how to use them. Both coding operations are necessary for the CNC device system to operate correctly.

M-code is the machinery used by AutoCAD and CAM, computer aided manufacturing, to input commands to C-N-C machines. G-codes and M-codes work together for locating a work-piece and telling the machine to operate.

M-codes, miscellaneous or machine codes, control the actions of the machine, allowing it to run or stop.

G-codes can tell the machine to move in a straight line or an arc, once the tool is at the correct position the machine won’t know to stop, change tools, add coolant, or anything else that is provided by M-code. Instructions for a tool to be on, or off, is part of the M-code language.

Typically the practical use of M-codes is machine specific. Programming typically uses M-code which is one code per block of code, providing commands for the tool to be on or off, and to turn other operations on and off. and if there is more than one, it will not work properly. The manufacturer of the machine defines the M-code functions and operation.

Operators use M-codes to tell a machine to change a tool, run a spindle, provide coolant and open and close a door. There are a number of M-codes that an operator will need to successfully program their machine correctly.

Lastly, each machine has a different method to download the M-codes. One controller requires a zero, “M03” but the next machine doesn’t need a zero, or not. The specific method needed for a machine is clearly defined by its manufacturer’s instructions.

What is M-Code Commands

The types of commands programmed into a CNC machine

M-codes are a fundamental part of a CNC machine able to perform work.  G-codes tell you where to position for a specific operation, whereas M-codes are the general codes of the machine’s actions.  The use of G codes and M codes work together for a CNC machine to operate properly. 

Together the G and M codes give the commands, directions, and the programming needed for a CNC to respond to a document.  Similarly, when working with a computer there is a host computer engaged with data input. 

Although most computer languages are based on C or C++ there are differences for each type of controllers.

Fanuc builds robotic controllers that utilize M-codes for commands for CNC machines.  Fanuc machines utilize the M zero number format of M-codes. Below are some of the M-codes for a Fanuc controller.

  • M00 Program stop.
  • M01 Optional program stop.
  • M02 End of program.
  • M03 Spindle start forward CW.
  • M04 Spindle start backward CCW.
  • M05 Spindle stop.
  • M08 Coolant on.
  • M09 Coolant off.
  • M29 Rigid tap mode.
  • M99 End of program.

The M commands are in an information group that indicates when and how a machine should start or stop performing an action. Starting with M00 they continue in an arithmetic progression to M99 which terminates the program.

The way an M-code is used differs among vendors and producers. In many instances, the M-code may not even be programmed into the machine.

It is important to know what the codes are and how they control the machine. In some instances where a code is not used or programmed, the definition of the code other than it is an M-code is at the user’s discretion.

In the tables below are examples of the programmable codes for a lathe and milling operation. Table 1 has codes for a lathe where table 2 has the M-codes for an operation using a milling machine. Both provide example M-codes for Fanuc controllers.

Fanuc M-Code List (Lathe)

M codeDescription
M00Program stop
M01Optional program stop
M02End of program
M03Spindle start forward CW
M04Spindle start reverse CCW
M05Spindle stop
M08Coolant on
M09Coolant off
M29Rigid tap mode
M30End of program reset
M40Spindle gear at middle
M41Low Gear Select
M42High Gear Select
M68Hydraulic chuck close
M69Hydraulic chuck open
M78Tailstock advancing
M79Tailstock reversing
M94Mirrorimage cancel
M95Mirrorimage of X axis
M98Subprogram call
M99End of subprogram

Fanuc M-Code List (Mill)

M codeDescription
M00Program stop
M01Optional program stop
M02End of program
M03Spindle start forward CW
M04Spindle start reverse CCW
M05Spindle stop
M06Tool change
M07Coolant ON – Mist coolant/Coolant thru spindle
M08Coolant ON – Flood coolant
M09Coolant OFF
M19Spindle orientation
M28Return to origin
M29Rigid tap
M30End of program (Reset)
M41Low gear select
M42High gear select
M94Cancel mirrorimage
M95Mirrorimage of X axis
M96Mirrorimage of Y axis
M98Subprogram call
M99End of subprogram

It appears that there is some misunderstanding regarding the codes for CNC machines. A number of operators refer to every code as a G-code even in situations where both G and M codes are programmed to manipulate the machine.

See also  Thermoplastic Vs Thermosetting Plastic: What's the Difference?

In order to avoid any misinformation and misconception regarding methodology, it is important to understand that every code block has to have one M-code for the beginning or ending of functionality.

The G-code explains how, where and when to do a job (or task), and M-codes stop an operation, end a programmed task or begin a movement once the tool is already positioned.

Most parts and products produced by CNC machines are programmed using CAM or CAD software that communicate directions to CNC machines using alphanumeric programming.

Even though engineers know how to use two forms of software, it is still important that they understand that G and M codes communicate with a CNC machine.

What is CNC Machining?

CNC machining, or computerized numerical control machining, is an advanced electromechanical system, capable of coordination along three to five axes to machine parts and components by removing excess material.

The first step in the CNC machining process is to develop a design in CAD software, which is then converted into CNC codes to control the movement of tooling in the CNC system.

This technology can produce high-quality finishes on turned pieces using a wide variety of applications, covering both vertical and horizontal machining.

CNC machines now have the capacity to produce many parts desired, all in one operation. The CNC machines can be used for a number of applications, including bushings, collars, fasteners, fittings, inserts, machined components, washers, pins, nuts, spacers, spindles, standoffs, drive shafts and splined shafts, to name a few.

What are the Top M-Code Simulators?

M-code simulators are software applications that simulate or analyze the behavior of M-codes (machine code) used in CNC (Computer Numerical Control) systems.

CNC simulation software provides versatile and thorough CNC programs for verifying, optimizing, and troubleshooting CNC machine tool programs before they are run on physical equipment.

M-code simulators are equally important for the fabrication of M-codes that prevent machining mistakes that can be excessively expensive to remedy, timeline for broken down machines, and optimize the CNC programming process.

Professional M-code simulators have been developed by some of the leading software providers customized for millions of specific industries including aerospace, automotive, and precision manufacturing.

Below, you will find an astute review of the better M-code simulation software features on the market and the dedicated company you will be working with.

Predator Virtual CNC by Predator Software

Predator Virtual CNC is a large CNC machine simulator that offers solid M-code simulation and G-code simulation capabilities. It provides a very realistic 3D simulation environment.

This allows users to preview, verify and optimize CNC programs, including complex toolpaths and subprograms, prior to executing them on an actual CNC machine.

The simulation allows users to discover programming mistakes, tool collisions and any manufacturing inefficiencies which is priceless for CNC programmers, manufacturing engineers and machinists looking for precision and dependable processes.

Predator Software, founded in 1994, is an established leader in manufacturing software solutions for CNC programming, shop floor automation, digital twins technology, machine monitoring and integrations for Industry 4.0.

Its extensive support of a wide variety of CNC machine models and controllers provides manufacturing facilities with the ability to achieve their digital transformation initiatives.

Vericut by CGTech

Vericut by CGTech is one of the most recognized M-code simulators featuring high-tech CNC program verification, optimization and virtual machining features.

It’s capable of complete simulation of the entire machining operation, with simulation of the tool movement, representation of the material removal, and also errors in programming, side interference, over-travel, and inefficiencies in the CNC program.

The software is capable of simulating both G-code and M-code on all types of multi-axis and multi-channel CNC machines. It has been a go-to package for many manufacturers of complicated parts parts in high-accuracy industries.

CGTech is an international company originally founded in 1988 and has led the way in CNCtechnology & innovation. CGTech has extensive experience executing CNC simulation, NC program verification, and numerical control (NC) optimization processes for many sophisticated machine manufacturers.

CGTech services customers in the aerospace, automotive, medical device manufacturing, energy and other industries.

Their software, Vericut, enhances the safety, productivity, and efficiency of CNC machines globally and provides users with CNC programs that are highly accurate, and legitimate and also capable of verification/validation dated across the several industries in which we serve.

Cimco DNC-Max by CIMCO A/S

Cimco DNC-Max is a software package with world-class software functionality for DNC (Direct Numerical Control) and M-code simulation capabilities. In addition to providing robust and reliable transfer of CNC programs, it also provides development capabilities for G-code as well as M-code.

See also  Sheet Metal Fabrication: Process, Techniques, Types And Benefits

M-code simulation makes it easy to evaluate whether there are program logic errors, G-code execution errors, syntax errors, or questions about machining the M-code program on a specific machine tool.

By using Cimco DNC-Max, you can save setup time through automation, taking advantage of the momentum of the data from CNC programs, and connecting the manufacturers of all capacities on the shop floor.

Founded in 1991, CIMCO A/S is a reputable developer of DNC software, CNC communication hardware, machine data collection, and production analytics solutions.

Its solutions are trusted for seamless and reliable integration with CNC machines, making them popular for the development of smart manufacturing applications and applicable for Industry 4.0.

Mastercam Simulator by CNC Software, Inc.

Mastercam is arguably one of the most popular computer aided design / computer aided manufacturing (CAD/CAM) software for advanced computer numerical control (CNC) programming, as it has a full-featured, integrated M-code and toolpath simulation environment.

It allows the user to visualize, back-plot, and verify CNC programs. It even has the capability of simulating complex multi-axis toolpaths and validating the machining process, including end-to-end post-processor simulation.

Mastercam is a dynamic tool that allows users to simulate and manipulate their CNC program for optimization prior to running the actual programs on the machine. It helps improve machining accuracy, increase tool life, and streamline production workflow.

CNC Software, Inc (founded in 1983) developed Mastercam, which is one of the most highly utilized CAM software in the world.

By incorporating a simulator into the main software, the user has some comfort knowing they have reduced their margin for error and are minimizing the amount of troubleshooting, time, energy and money spent on programming, machine setup, and other manual processes.

Mastercam’s user community helps build confidence in the software and the extensive library of post-processors reflects its position as the default software for complex CNC programming and M-code simulation.

Fusion 360 by Autodesk

Autodesk Fusion 360 is a comprehensive product development environment that combines advanced 3D CAD, CAM, and CAE into a single cloud environment.

Fusion 360 has a powerful set of CNC simulation capabilities including M-code and G-code interactive verification with post processor workflow, toolpath optimization, machine tool collision detection and, as a CNC programmer or Manufacturer, you see what the machining operations will actually look like in real-time, which helps you to see possible errors as well as the code that will make the actual machining operation compliant and provide the best process for any machine type and controller.

Autodesk, founded in 1982, is known for its development of professional software solutions for many design and engineering markets and, regardless of market segment, Autodesk Fusion 360 has developed a strong reputation for ease-of-use, cloud collaboration features, integrated simulation workflows that make the software easy to use for prototyping, small-batch manufacturing, and educational purposes.

Selecting an M-code simulator depends on several factors including; your manufacturing needs, type of CNC machine, industry requirements, and budget.

Modern M-code simulators not only help to drive; improved productivity, improved machining accuracy, but to also help defend against the evolving challenges of digital twin development, NC code optimization, and working toward compliance with digital manufacturing standards.

Many of the highly-rated simulation solutions, Predator Virtual CNC, Vericut, Cimco DNC-Max, Mastercam Simulator, and Fusion 360 give users low-risk, reliable, and cost-efficient CNC program verification and seamless shop floor transition.

Manufacturers who are focused on improving their CNC programming process to reduce scrap rates and improve time-to-market are not only investing in their programming methods but also by obtaining advanced M-code simulation technology.

When exploring and obtaining a M-code simulator, there are key functionalities to consider: what is the CNC controller compatibility, is the user interface intuitive, does the software support your array of complex machinings, will the simulation provide realistic scenarios with high accuracy before machining, or will you be doing this on the shop floor?

Requesting a software demo, reading external customer reviews, and consulting with technical experts will assist you and your team in exploring the best M-code simulator for your production requirements.

What is the CNC machining process?

CNC, or Computer Numerical Control, machining is a detailed approach to creating parts in an efficient manner. CNC describes computer controlled machines that, carry out the tasks as described by pre-programmed instructions, taking the 2D or 3D design from a computer.

Once the design file is entered and coded, the CNC machine undertakes the various operations as specified by the coded design.

The CNC Machining Process

While there are many types of manufacturing processes, the major difference between CNC machining and those other processes is that CNC machining is a subtractive process.

See also  What is Drilling?- Definition, Process, and Tips

Often times parts are made in a none additive or formative way and are made by removing layers of material until we reach the desired shape.

Computer Programming

Once again, the effectiveness of CNC manufacturing is primarily determined by the outcome of the original programmer.

Not the machines—they must still be pre-programmed; the software has to be programmed; and if there are rules, they have to be programmed; if there are design limitations in the program, the designer must code those limitations into the original program.

The efficiency of the CNC processes and how efficiently and effectively it is completed is relative and depends on the instructions presented. Thus, programming in the machine shop is given careful consideration to avoid errors and delayed production.

Computer Aided Design (CAD) and Computer Aided Manufacturing (CAM)

CAD-CAM refers to the software that is used to both design and machine parts using CNC machines. CAD (Computer-Aided Design) software is used to create, draw, and model parts using geometric shapes and constructs. CAM (Computer-Aided Manufacturing) is used to convert the CAD data to machine language which is referred to as G-Code.

Before exporting the CAD model to machine instructions, CAM software must identify the toolpaths that the cutting tool must travel to remove the excess material from the workpiece.

CAD and CAM, working together, provide the CNC machine detailed instructional information that is imperative for accurate cuts as well as efficient cutting.

CNC Machine Setup

Proper cutting tool preparation must occur before uploading the CAD-CAM program to the CNC machine. One way is to simply pull tools from a tool cart and install them into the machine.

A second, simpler method is through the use of an Automatic Tool Changer (ATC). An ATC is usually in the form of a rotating drum or chain that holds a collection of tools and automatically replaces them as the machine rotates through the tool preset positions.

The ATC increases production by decreasing set up time between parts and reduces machine down time.

Another important step in the set up portion of the CNC milling operation is to identify the gage point which identifies the distance from the tip of the tool to the reference point. Spot checking this measurement will allow the tool to cut at the expected depth.

It is also necessary to check the coolant or lubrication system. Either air, mist, flood, or high-pressure coolant can apply the coolant. The required pressure is important to prevent tool damage or damage to the machine.

One common mistake during the set up phase is to not verify the quality of the coolant. The operator would often perceive an unpleasant odor if the coolant was bad. There could also be inadequate coolant, low concentration of coolant, or insufficient filtration in the system.

Work Holding

Work holding devices are utilized to hold, support, and position the workpiece in the machining process. Work holding devices are also often referred to as CNC fixtures.

Work holding fixtures are used for the stabilization of the workpiece to ensure that precision, repetitive operations, and smooth machining occur. Whereas jigs guide and direct the tools, work holding devices focus on holding and supporting the workpiece itself.

Just as CNC tools come in many types, work holding fixtures are also of many types. Different types of work holding devices and fixtures are designed for specific operations including, turning, milling, drilling, boring, and grinding.

Loading the G-Codes

G-codes are largely accepted as the standard for CNC programming. While there are universal G-codes for all CNC machines, manufacturers make edit excursions for their own equipment. Each G-code represents a movement or function of a CNC machine’s cutting tools.

G-codes can be generated out of any CAD design by software, written by hand (writing G-code is great for developing your skills), or can be created using conversational programming (conversation programming does not use CAD designs).

G-codes can be transferred to a CNC machine through a USB drive, directly from a CAM computer, or programmed directly at the machine.

Program Proofing

Proofing programs is the final process prior to performing the actual cuts. The purpose of proofing is to authenticate the program, and confirm the CNC machine setup is accurate to eliminate possible errors with the G-code.

This is an essential step for ensuring errors do not exist in the G-code. A proofing process can be done by running the machine through the cutting process, without cutting into the workpiece. In other words, cutting air.

This is time consuming and ties up the machine for a period of time, but is effective. A G-code simulator can be used to proof a program and present all of the potential space where the CNC process is simulated, and any problems can be identified.

Machining the Part

Following completion of all preparations, the next step is to install the workpiece and start cutting. It is essential to pay attention to your first workpiece as it is machined. This first part is a template for all the subsequent parts and will provide useful information on the programming and set-up efficacy.

Execution

Once setup and testing have been completed successfully, the CNC machine is now set for production. CNC machining allows manufacturers to produce parts that are safe, fast, and efficient, with each part essentially an identical version of the original design.