Machine tool builders vary dramatically when it comes to what they allow you to do with M-codes. Some are quite limited in this regard while others allow you to control almost everything by M-codes. Too many times programmers ignore all but the most basic M-codes when working with their particular CNC equipment. They don’t even consider the possibility that an M-code may be available to help with a particular application. This is especially true when a new programmer takes over the programming of an existing piece of CNC equipment.

One of the first things you should do whenever you begin working with any machine is to study the list of M-codes available. You will normally find the list of M-codes supplied in the machine tool builder’s manual (not the control manufacturer’s manual). You may be surprised at what you find. For any M-codes that do not make sense, contact your machine tool builder to learn their usage.

Neglecting your M-codes list can cause problems ranging from inconvenient to downright damaging to the machine tool. For example, on a turning center you may find you have control of your chuck’s clamping direction (internal or external) by M-code. This would make it possible to easily program first and second operations on a workpiece within the same program (turning the part around after the first end is finished) in conjunction with outside diameter and inside diameter chucking. Maybe the first operation chucks on the outside of the workpiece and the second chucks in the inside. Without knowing these M-codes exist, you wouldn’t consider this a possibility.

In more extreme cases, you could cause damage to the machine. For example, say a company has a horizontal machining center with a rotary (B) axis incorporated in the table. And say the programmer is supposed to specify an M-code to clamp the table before performing any heavy machining operations on a particular side of the table (though not all rotary axes require this). Not doing so would place undue strain on the B-axis drive motor and drive mechanism, and this system would wear out much faster than it should have.

Applications for M-codes

The primary application for M-codes is to allow programmable on/off switches for mechanical devices. This allows the programmer to activate mechanical functions like spindle, coolant, chuck jaws, hydraulic clamping, tailstock, and indexers. Again, some machine tool builders give the programmer control of almost everything (even chip conveyors, worklights, and protective doors) while others are quite limited in this regard.

A second application for M-codes is to allow programmable on/off software related switches. Usually these functions are related to some feature of programming. For example, some machine tool builders allow the programmer to control whether optional block skip (or block delete) is on or off through M-codes. M12 may be used to turn on this feature and M13 to turn it off. Other applications for M-codes in this category include enabling and disabling feed rate override, controlling thread chamfering for turning centers, controlling how cutter radius compensation is handled for rounding corners, and controlling whether mirror image is turned on or off.

Some rather obscure M-codes

As you look through your M-codes list, be prepared for some rather obscure functions. You may find, for example, you have control of whether an M-code is activated at the beginning of a motion command or at the end. So you may find you have control of whether the machine will turn itself off at the completion of the program (for unattended use). You may also have control of how many “look ahead” commands the control will use with cutter radius compensation.

These are but a few of the rather unusual uses for M-codes. It may take quite a bit of study to understand the implications of when these codes can help.

Adding M-codes

Keep in mind that most machine tool builders allow the end user to add M-codes as required. This may be necessary, for example, on a vertical machining center when adding an indexer to the machine. This kind of M-code interface usually requires the assistance of the machine tool builder. Other examples of after-market devices that can be interfaced with M-codes include hydraulic clamping systems for machining centers, programmable steadyrests for turning centers, and bar feeders for turning centers.

http://findarticles.com/p/articles/mi_m3101/is_16_56/ai_16112816

Many CNC users have two or more highly similar CNC machines made by different machine tool builders. Depending on work load, most need to run the same jobs on any one of the similar machines at any given time. Say, for example, you have two 20-horsepower, eight-inch chuck, turning centers. One is made by brand X and the other by brand Y. As each job comes up you would probably like to run it on whichever turning center frees up first.

One problem this kind of CNC user constantly faces is incompatibility with regard to programs. Even if the two (or more) similar machines have identical controls, there will probably still be some incompatibility regarding M codes. If both of the turning centers have two spindle ranges, one may use M23 for low range and M25 for high range. The other may use M41 and M42. To overcome these M code incompatibility problems, either the CNC user must maintain two (or more) complete sets of CNC programs (which can be cumbersome), or the operator of each machine will be constantly editing programs written for the other machine (which is tedious, error prone, and time consuming).

Turning center spindle ranges are but one example of when similar CNC machines built by different machine tool builders are not compatible with regard to M codes. While some M codes are somewhat standardized (M00, M01, M03, M04, M05, and so on), almost any M code the machine tool builder must name for their own miscellaneous functions introduces a potential incompatibility problem (tailstock, chuck jaws open/close, automatic toolchanger functions, pallet changer, and so on).

If your machines have custom macro B, you have the ability to change the function of your M codes (up to ten on current model controls) in such a way that the machines become compatible. In essence, you can set up the control so that when it reads one M code, it executes another. While this technique can be applied to any M code incompatibility, let’s stress its use for the turning center spindle range M codes.

The first step is to pick the M codes you want to use. In the spindle range example, maybe more of your machines use M41 and M42, so you wish to change the machines that currently use M23 and M25. Or maybe the machines that use M41 and M42 do not have custom macro B, meaning the only machines you can change are those that use M23 and M25 (though custom macro B can be added to many controls at any time).

For those machines you wish to change (we’ll say those using M23 and M25), look in the custom macro section of your programming manual. In the section related to creating your own M codes, you will find parameters that must be changed (two in our case). These parameters control what happens when a specified M code is executed. When set properly, whenever the specified M code is read, the control will automatically jump to a custom macro. In the custom macro, we will include the M code that performs the actual spindle range change. This is a bit confusing, so here is a full example.

One popular control uses parameter numbers 7071 through 7079 to control which M codes call custom macros. For this control, parameter number 7071 is related to program number 09001 and parameter number 7072 is related to program number 09002. On the machines that currently use M23 and M25, we will set parameter number 7071 to a value of 41 and 7072 to a value of 42. From this point on, whenever this control reads an M41, it will execute program number 09001. Whenever it reads an M42, it will execute program number 09002.

The last step is to enter the correct programs into the control. Most controls even allow your M code related custom macros to be protected so that they cannot be changed or deleted (another parameter is related to this function). Here are the two simple programs.

09001 (Program number) M23 (Execute low range command) M99 (End of custom macro) 09002 (Program number) M25 (Execute high range command) M99 (End of custom macro)

When these programs are in the control’s memory, and when the parameters are properly set (remember, they will probably be different parameter numbers for your particular control), whenever the control reads an M41, it will jump to program number 09001. In this program, the M23 will make the range change. From this point on, programs that have M41 and M42 will execute without modification in machines originally set up to accept M23 and M25.

You say your turning center has only one spindle range?

There may be times when you find the need to delete M codes in order to get programs to run. In the previous example, maybe one of the similar turning centers has only one spindle range. Yet whenever an M41 or an M42 is read, the control of this machine will stop executing due to an unrecognizable Mcode. For this type of machine, you can use similar techniques to make the control ignore the unused M codes. The parameters will be set the same as shown earlier. Only the custom macros will change.

09001 (Program number) M99 (End of program) 09002 (Program number) M99 (End of program)

Notice these are nothing more than empty programs. When the control reads an M41, it will jump to 09001, which immediately sends execution back to the previous program. Though nothing actually happens within the programs, the control will no longer get stuck on the unrecognizable M codes.

http://findarticles.com/p/articles/mi_m3101/is_n4_v68/ai_17570283/pg_1