Exploring the Benefits of M-Code

Exploring the Benefits of M-Code

Welcome to another MachMotion minute! In this article we will be talking about macros and how you can make your day more automated!

Overview

We will be talking about what M-Code is and how it works, when to use a M-Code over G-Code, step by step using a M-Code for a dust cover and finally diving into more advanced features such as subprogram calls. We have a lot to talk about so let's get started!

About MachMotion

MachMotion provides industrial retrofits and controls, as well as specialty solutions for application/processes that require unique control solutions.

Additionally, MachMotion provides top of the line consultation and support. We are dedicated to our customers and deliver high-end products and services.

 For more information or to speak to a specialist, please visit MachMotion: https://machmotion.com

M in M-Code isn't what you think it is?

"M" in "M-Code" is short for "Miscellaneous function" but some refer to it as "Machine Code" because it calls for a machine function, which is why people think the "M" stands for "Machine". The G and M-Codes were originally designations for General and Miscellaneous functions. Simply put M-Codes are scripted routines for your control to run. They are pre built functions that are ready for use when you first power your machine up, and there also custom user macros that you can build for anything you may need to add. The proper way to reference a M-Code in the CNC industry is either "M code" or "M-Code", but if you put Mcode people will know what you're talking about.

*Bonus did you know: G-Code is the common name for RS-274 and first appeared in 1950.

Introducing the M-Code

M-Codes allow the user to create programming calls for complex processes, activating or deactivating outputs, reading inputs, performing math, etc. These M-Codes are programmed in Lua and placed in the macros folder under each profile. The file name must be the macro to be called, with a .mcs file type extension (For Example: M700.mcs).

*Bonus did you know: G-Code is sometimes called "G Programming Language."

Let's Use Our Own M-Code

Dust Cover

Every machine has some extra feature that it would be nice to automate. With simple macros you can add this automation to your G-Code files. Let's look at a dust cover for a router table. You can put macros in your G-Code file to raise and lower the dust hood. We're going to use a macro to control the output in the G-Code.

#1 Setup Output

For example, M200 turns Output 0 on and M201 turns Output 0 off.

  1. First let's make sure we are in a "Disabled state, to do this click the bottom "Enable" in the bottom left corner. If it is flashing red we are in "Disable" mode.

  1. Now go to the top menu and select "Configure" and in the drop down select "Mach…", you should now see a window with our Mach Configuration settings.

  1. In the "Mach Configuration" window select the "Output Signals" tab.

  1. Then we should set up the output. This is on Y0 of the Apollo board.

#2 Setup Screen

  1. Back in you MachMotion control software, select "Settings" in the right side tab panel.
  2. Under "Settings" select "Screen Configuration" button.
     3. Set the Output that you are using from the drop down for Button #1, and type in the text you want displayed when de/activated.
     4. Make sure to click "Re-Compile Scripts" for the changes to take effect.

     5. Make sure to "Enable" the system by click the flashing red "Enable" button in the bottom left corner.
     6. Select "Vac Hood" from the Machine tab or whatever you named the button, to raise and lower the hood.

#3 G-Code

Since we're using output #0, M200 will turn it on and M201 will turn it off. We can place these codes anywhere in our file to automate the hood. If you are using another Output number below is how they line up to the M-Codes.

Advance M-Code M98 Subprogram Calls

Subprograms are external programs referenced by the current running program. When called, program execution will continue in the subprogram. This allows the user to reduce program length and complexity by providing the ability to easily repeat sections of code, run G & M-Code the same section of code in multiple locations or in multiple fixture offsets, the possibilities are limited only by the programmer.

 To call a subprogram command M98 with the program number as shown.

Format: M98 P____ Q__ L__

P specifies the number of the program to be called. This is traditionally a four digit integer number. When the M98 is read Mach scans the current file for a block containing the program number in the following form: Format: O1234

Note that the letter “O” is used to specify the program number 1234, NOT the number “0”.

Program execution will continue with the block following the O number. For this method the subprogram should be below the end of the current program:

Full List and Description of G&M Codes

Please visit our G-Code and M Code reference manual for a complete list of available G&M code along with descriptions and examples: https://machmotion.com/blog/knowledge-support

What Next?

We hope this brings a better understanding of how M-Codes can be useful and applied to your everyday use. As always we appreciate a thumbs up and if you’re not already doing so, please subscribe to receive notifications for new videos and articles.

Please visit our website for more information: https://machmotion.com
Subscribe For More Articles: https://machmotion.com/newsletter-subscription
Subscribe For More Videos: https://www.youtube.com/user/MachMotionVideo
Follow Us On Twitter: https://twitter.com/machmotion?lang=en
Join Us On Facebook: https://www.facebook.com/MachMotion/
Share With Us On Instagram: https://www.instagram.com/explore/tags/machmotion/

References:

Authors: Jason Blake & Josiah Nisbett
Contact Sales: [email protected] or call 573-368-7399
MachMotion CNC Mill Control Kit:
https://machmotion.com/retrofits-main-mill
G-Code List: https://machmotion.com/blog/knowledge-support-gcode
M-Code List: https://machmotion.com/blog/knowledge-support-mcode
Wikipedia definition of a M Code: https://en.wikipedia.org/wiki/G-code#List_of_M-codes_commonly_found_on_Fanuc_and_similarly_designed_controls
MachMotion M-Code Summary: https://machmotion.com/documentation/gcode/Mach4-G-and-M-Code-Reference-Manual.pdf