Horn USA
Published

Craftsman Cribsheet No.131: FANUC Macro Programming Basics

Macros are essential to high-production CNC programming because they simplify blocks of code.

Share

Macros are an essential part of high-production CNC programming because they allow for blocks of code to be simplified. They also allow programs to easily be used on families of parts. Macros can even make code more accurate and precise.

Like writing a function in traditional programming, using macro variables in G code can allow a programmer to create repeatable blocks of code that are proven. A macro is a container that holds a value. Using macros changes what the code does but not the underlying process. A programmer must only figure out the details once then let the controller process the math involved in producing the tool path. Let’s look at the basic structure of FANUC macros.

Source: PMPA

Null means no value.  It does not mean zero. Think of a variable as a container.  When it is null, that means the container is empty.

Some of these ranges vary by controller. Some manufacturers change the address system to match how they utilize the control. This may limit the range of addresses available or change their behavior.  

For example: Some controllers change the value of #1-33 values to null after the program has executed. The values for #100-199 are local to the program or channel in use but are persistent until power off. In practice #100 in Channel 1 and #100 in Channel 2 can have different values. In practice, #100 in Channel 1 and #100 in Channel 2 can have different values. (Check your controller’s manual to see exactly how your machine works.) I call this “executional persistency.” They persist in memory through multiple loops of a program but are volatile because they are reset to null at power off. The values of #500-999 are the same value across the control. Putting a #500=1 allows that value to be called by multiple channels and subprograms and receive the value of “1”. This is powerful because values can be shared between subprograms and changed, then pass the new value back to the original program.  

An example code of macros in use
Source: PMPA

The WHILE loop in the example acts as a subprogram and runs through this code until the condition is met, simplifying the code process. Since the code for each flat is combined in this block, a change affects all flats equally. A programmer does not have to go through the code and find all six places and change it manually. This program is utilizing a #100 variable local to this channel and program.

Macros are a powerful way to level up a CNC program. Using advanced programming techniques allows programmers to simplify complex tasks. Once a block of code is designed, it can be utilized on multiple programs. Code reusability is key to accurate and precise programming. Humans make mistakes but when we use proven systems (reusable code for example), we increase our ability to perform.

About the Author

David Wynn

David Wynn, MBA, is the PMPA director of technical services. He has over 20 years of experience in the areas of manufacturing, quality, ownership, IT and economics.

Email: dwynn@pmpa.org — Website: pmpa.org.

World Machine Tool Survey
Techspex
Horn USA
Kyocera EZ Bar Series
Sharp, Durable, Innovative Diamond Powder
Star swiss-type automatic lathes
manufacturer of machine tools
SolidCAM
Marubeni Citizen CNC
Come See Tsugami America at IMTS | Booth 339410

Related Content

PMPA

Craftsman Cribsheet No. 128: Why Do Machinists Say Tenths Instead of Ten Thousandths?

In machinist parlance, a tenth is a tenth of a thousandth, not a tenth of an inch.

Read More

Manufacturing Skills Training: Virginia Martinez and Laiken Carrillo

Roles of Women in Manufacturing Series: A precision machining career starts with skills. Virginia and Laiken share their journey and how they help prepare the next generation.

Read More
PMPA

Turned and Polished Steel Barstock: How It Is Manufactured, How It Impacts Your Shop

Understanding the benefits provided by turned and polished steel barstock and its differences from cold-drawn steel barstock can help you and your team avoid unexpected performance issues. 

Read More
PMPA

Craftsman Cribsheet No. 129: How to Beat the Heat

Shops tend to heat up in the summer. Here are some tips for staying cool in the warmer months.

Read More

Read Next

Cutting Tools

Replaceable-Insert Spade Drill Basics, Advantages

Although solid carbide and indexable-insert drills have their place in a machine shop, replaceable-insert spade drills offer specific advantages for various holemaking operations on machining centers and lathes.

Read More
Cutting Tools

Broaching Tool Technology For Lathes Used to Slot Inconel Parts

This shop finds value in using an indexable-insert-style broaching tool to create blind-hole slots in heat-treated Inconel aerospace parts on a CNC lathe.

Read More
PMPA

Why (and How) You Should Reboot Your Shop’s Safety Program Today

Now may be the perfect time for a safety reboot before complacency sets in.

Read More
World Machine Tool Survey
;