Shop Doc – Custom Macro programming

Today’s Machining World Archives August 2010 Volume 06 Issue 06

Dear Shop Doc,

One of our operators came from another shop and told us that we can use Custom Macro for tool life management, but he doesn’t know how. I checked the manuals but don’t see anything obvious. Can you help?

Through the Grapevine

Dear Grapevine,
Custom Macro programming, also known as parametric programming, is capable of performing many different tasks, even ones not specifically outlined in the programming manual.

Macro programming allows the use of variables, logic, arithmetic, conditional branches, and custom alarms. For tool life management, we’ll need to use most of those functions. Ideally you should make a flow chart to outline the sequence of events that need to take place. In this case, you want to check the life remaining on all tools and either run a part or have the machine generate an alarm to notify the operator that a tool needs to be changed. Since all this needs to take place before machining, you can put that part of the Macro at the beginning of the program.

You should use variables to hold the life count and the life number for each tool. I like to relate the variable register number to the tool number. Let’s assume there are four tools and they are T0100, T0300, T1100 and T1400. We will use variable numbers 501, 503, 511 and 514 to hold the life count and variables 101, 103, 111 and 114 to hold the tool life value. Values stored in variables 100-149 are lost when the power is switched off. Variables 500-531 retain the value at power down.

O1234; (Machining program number)
#101=1000; (Tool life value for T0100)
#103=500; (Tool life value for T0300)
#111=775; (Tool life for T1100)
#114=2300; (Tool life value for T1400)

Setting the tool life from the program ensures that the proper values are used and saved. Next, you need to check the life of each tool. For this you can use a conditional BRANCH statement.

IF[#501 GT #101] GOTO 1000; (If the count in #501 is greater than the life set in #101 skip to line N1000)
IF[#503 GT #103] GOTO 3000;
IF[#511 GT #111] GOTO 11000;
IF[#514 GT #114] GOTO 14000;
(Normal machining program goes here)

At the end of the program you need to add to the tool life count and list the alarms. With the alarms you will also reset the tool life count so that you don’t have to rely on the operator to remember.

(End of normal machining program is here)
#501=#501+1; (Add one to the tool life count of tool T0100)
GOTO 9999; (Skips over alarms and goes to M30 code)

N1000 #501=0; (Reset life count for T0100)
#3000=1 (TOOL LIFE OVER CHANGE TOOL T0100) (Alarm to stop machine with message)
N3000 #503=0;
(Repeat for #511 and #514);
N9999 M30; (End of program)

The GOTO statement will cause the program to skip over the alarms while the previous IF GOTO statements will cause them to be read. There are lots of different ways to program this. Submit your program in the comments on the Shop Doc Blog at

Dan Murphy

About Dan Murphy

Dan Murphy is a regional sales manager for Rem Sales LLC., a U.S. Tsugami distributor. He can be reached at

Share this post

One thought on “Shop Doc – Custom Macro programming

  1. S. K. Sinha

    It will be easier to understand these things if one knows macro programming.
    If one does not have any background in macro programming (Custom Macro B), and wants to learn it in depth on one’s own, I would suggest the following book (look into website) CNC Programming using Fanuc Custom Macro B (9780071713320): S.K Sinha: Books

    A review of this book can be seen at
    CNC Machine Tool Book reviews and cnc software reviews by


Comments are closed.