What's new
What's new

How to create a user defined M code?

g-coder05

Titanium
Joined
Mar 5, 2006
Location
Subic Bay
I was at a shop the other day and saw an operator keying in a M900 on a turning center that made the machine run a sub.

G28 U0.
W-20. (Center of travel)
G28 Y0.
M8
T0000
/M1

Just curious on how to assign a M code to the sub. It seemed to be a handy command while he was touching off tools. Im sure I could find alot more uses for this also.
 
M code designation can be set for a Fanuc control equipped with the User Macro Option by setting Parameters 7071 through to 7079 inclusive, to call Program Nos. 9001 through to 9009 inclusive. The setting range is between 0 to 9999. These Parameter Nos. vary with the model, with the above Parameters being for Fanuc Controls of around the 11 series vintage.

The designated M codes can be used to call Subprograms (macro program) in the same way M98 is used to call a Subprogram, or used to call a Macro Program and pass parameters in the same way as G65 is used. A different range of Parameters are set for the different usage of the M codes.

Regards,

Bill
 
I know how to do it (and custom G codes) but only on Fanuc 16, 18, 21 and their variants.

With the parameter write enabled, you have to first decide which you want, M code or G code. Then you go into a small group of parameters and enter the 2, 3, or 4-digit code you want associated with a particular O9000-series program.

I raise a BIG CAUTION: if there is ANY value in any of those parameters, LEAVE IT!

If there's already a value from the machine tool builder and you go and change it, you'll screw up something and it could be very dangerous. If you accidentally delete a value, some function of the machine will longer longer work. The same is true of the "9000 series" macro programs executed by the G and M codes you wish to create. If you've disabled the "write protect" of 3202.4, you could easily wreak havoc on your machine tool builder's programs! Back up EVERYTHING before editing ANYTHING.

6050 = G code that calls the custom macro of program number 9010
6051 = G code that calls the custom macro of program number 9011
6052 = G code that calls the custom macro of program number 9012
6053 = G code that calls the custom macro of program number 9013
6054 = G code that calls the custom macro of program number 9014
6055 = G code that calls the custom macro of program number 9015
6056 = G code that calls the custom macro of program number 9016
6057 = G code that calls the custom macro of program number 9017
6058 = G code that calls the custom macro of program number 9018
6059 = G code that calls the custom macro of program number 9019

6071 = M code that calls the custom macro of program number 9001
6072 = M code that calls the custom macro of program number 9002
6073 = M code that calls the custom macro of program number 9003
6074 = M code that calls the custom macro of program number 9004
6075 = M code that calls the custom macro of program number 9005
6076 = M code that calls the custom macro of program number 9006
6077 = M code that calls the custom macro of program number 9007
6078 = M code that calls the custom macro of program number 9008
6079 = M code that calls the custom macro of program number 9009
6080 = M code that calls the custom macro of program number 9020
6081 = M code that calls the custom macro of program number 9021
6082 = M code that calls the custom macro of program number 9022
6083 = M code that calls the custom macro of program number 9023
6084 = M code that calls the custom macro of program number 9024
6085 = M code that calls the custom macro of program number 9025
6086 = M code that calls the custom macro of program number 9026
6087 = M code that calls the custom macro of program number 9027
6088 = M code that calls the custom macro of program number 9028
6089 = M code that calls the custom macro of program number 9029

Use these very carefully, and DO NOT blame me if you screw up your machine. ;)
 
I'm no help on a Fanuc but on a Haas there is a nice way outlined in the manual to Alias a G code to a program. This is about the same thing and handy as hell. For me to turn my spindle on in high gear at 1000 RPM for edge finding I type G154 in MDI and hit cycle start and it does the magic.
I have G153 to park the table front and center.

On my Fanuc I just have programs set up as subs and do a M98 call.
Like to warm up my spindle. Program 1 is the warm up program. MDI M98P1 cycle start.

This is handy when your running an ongoing production job. No need to switch your main program to warm up then switch back to run. Cuts down on mistakes.

You right this kind of thing can be handy and save writing code.
 
Thanks for all the help here. Fanuc,Haas, Now if I just had the proceedure for the A-2100 I would have my cake and be able to eat it too.:drool5:
 
A small correction (in red):

6050 = G code that calls the custom macro of program number 9010
6051 = G code that calls the custom macro of program number 9011
6052 = G code that calls the custom macro of program number 9012
6053 = G code that calls the custom macro of program number 9013
6054 = G code that calls the custom macro of program number 9014
6055 = G code that calls the custom macro of program number 9015
6056 = G code that calls the custom macro of program number 9016
6057 = G code that calls the custom macro of program number 9017
6058 = G code that calls the custom macro of program number 9018
6059 = G code that calls the custom macro of program number 9019

6071 = M code that calls the subprogram of program number 9001
6072 = M code that calls the subprogram of program number 9002
6073 = M code that calls the subprogram of program number 9003
6074 = M code that calls the subprogram of program number 9004
6075 = M code that calls the subprogram of program number 9005
6076 = M code that calls the subprogram of program number 9006
6077 = M code that calls the subprogram of program number 9007
6078 = M code that calls the subprogram of program number 9008
6079 = M code that calls the subprogram of program number 9009
6080 = M code that calls the custom macro of program number 9020
6081 = M code that calls the custom macro of program number 9021
6082 = M code that calls the custom macro of program number 9022
6083 = M code that calls the custom macro of program number 9023
6084 = M code that calls the custom macro of program number 9024
6085 = M code that calls the custom macro of program number 9025
6086 = M code that calls the custom macro of program number 9026
6087 = M code that calls the custom macro of program number 9027
6088 = M code that calls the custom macro of program number 9028
6089 = M code that calls the custom macro of program number 9029

Use these very carefully, and DO NOT blame me if you screw up your machine. ;)

If you call a program as a subprogram, you cannot pass data for use inside the program.
For more information, read chapter 7 of this book:
Amazon.com: CNC Programming using Fanuc Custom Macro B (9780071713320): S.K Sinha: Books
 
One Question: What is the difference between this book and the original FANUC manual?

Way of presentation is different, even though the content is same.
For example, from Fanuc manual, it is very difficult to learn how a subprogram can be called with a T-code. (Just try it. Then read pp. 150-151 of this book.)

There is a difference between a book (textbook) and a manual (handbook). A manual contains all the information, but not is a sequence which makes learning easy. A good books is designed to be read from beginning till the end, in the same sequence. A manual only supplies information, whereas a book actually teaches you.

A review of this book is available at
CNC Machine Tool Book reviews and cnc software reviews by Machinetoolhelp.com
 
Way of presentation is different, even though the content is same.
For example, from Fanuc manual, it is very difficult to learn how a subprogram can be called with a T-code. (Just try it. Then read pp. 150-151 of this book.)

There is a difference between a book (textbook) and a manual (handbook). A manual contains all the information, but not is a sequence which makes learning easy. A good books is designed to be read from beginning till the end, in the same sequence. A manual only supplies information, whereas a book actually teaches you.

A review of this book is available at
CNC Machine Tool Book reviews and cnc software reviews by Machinetoolhelp.com


I bought the book 2 weeks ago, thought I can learn more but that
does not happen,sorry!:cheers:
 
I bought the book 2 weeks ago, thought I can learn more but that does not happen, sorry!:cheers:

If you do not learn, I have to be sorry for misleading you; you have to be angry, rather very angry!

Actually, the book has been designed for those who have no or inadequate background in macro programming. If you already know enough, you may not find new things. I have considered the plight of those whom nobody is helping. I have myself gone through this stage. Mike Lynch rightly describes macro programming as "the best kept secret of CNC." (He is another author, apart from Peter Smid.)

If you feel that the book can be improved, do let us know. Of course, if you have already thrown it in the dustbin, ....
 
If you do not learn, I have to be sorry for misleading you; you have to be angry, rather very angry!

Actually, the book has been designed for those who have no or inadequate background in macro programming. If you already know enough, you may not find new things. I have considered the plight of those whom nobody is helping. I have myself gone through this stage. Mike Lynch rightly describes macro programming as "the best kept secret of CNC." (He is another author, apart from Peter Smid.)

If you feel that the book can be improved, do let us know. Of course, if you have already thrown it in the dustbin, ....


It is ok. I just thought the book tells me some secrets about macro programming. For beginners the book is good.
Maybe you should put more example programms in there.
 
...
Maybe you should put more example programms in there.

Thanks for the suggestion. A few common examples should have been included. That can be done in the second edition. I would also like to know about any ambiguity/error/typo in the book. (For example, on page 202-203, the multiplication signs before COS and SIN are missing in the last line / first line. On page 99, DO#1 is to be read as DO 1. There are a few more.)

I did not give too many examples because a number of working macros are already available on the net. Of course, it is unlikely that the available macros would exactly suit a particular application. One would invariable need to make certain modifications in macros developed by others. Therefore, I concentrated on macro-programming techniques only, instead of giving a number of sample programs.
 
Must be a decent book considering theres a few people selling used copies for $71.00. but it's $47.00 at amozon new!
 
Must be a decent book considering theres a few people selling used copies for $71.00. but it's $47.00 at amozon new!

If a new copy is available for $47, why will anybody sell/purchase a used copy for $71? Couldn't quite understand it.
Even with postage, it won't be $71.

Or, do you mean $17 ?
 
I asked the same question from my publisher. They say that they have no control over the price-tag of resellers. Here is their reply:

"Amazon’s price is $46.80, 22% off the $60 retail. The other prices are third-party vendors/bookstores. We can’t set a price, by law. All we can do is suggest a price and sell it to a bookstore at a discount. From there, it’s up to individual stores to determine their prices. I don’t know why anyone would do it, but apparently, some stores put a huge markup on the price, apparently up to $178. That’s not within our control though".

I believe amazon supplies books in all countries. If so, their price, with international shipping charges, should not be more than, say, $60. Then why would anybody pay $178. Of course, there may be some delay in delivery because of postal delays and payment issues.

Edit: somebody just now told me that amazon supplies in UK and USA only. Obviously, some resellers are taking advantage of non-availability of books in some countries.
 
OK, Aliasing a Haas G code is kicking my a$$. I created a program named O9010 then tried to asign a parameter to make the program run with G200. It didnt work. Ive read the page in the Haas manual over and over and cant find my mistake. Can somebody walk me through the procedure step bt step? Im ready to pull my hair out.
 
I do not know about Haas, but on Fanuc we would store 200 in parameter 6050, for G200 to call O9010 as a macro.
What exactly is the problem on your machine?
Undefined G-code (O9010 not being called at all)?
Or, some problem inside O9010?
 








 
Back
Top