91ÊÓƵÍøÕ¾ÎÛ

Published

Variables in Custom Macro

Choosing the appropriate type of parametric programming variable is especially important in complex applications.

Share

Leaders-In background

As with all computer programming languages, variables in FANUC’s custom macro—or any version of parametric programming—are storage registers for values. You can use them to represent just about anything.

Also as with most computer programming languages, there are different kinds of variables in custom macro. But unlike variables in most computer programming languages, you can often choose among two or more custom macro variable types for a given application. This is the source of some confusion and can lead to misusing variables.

There are five variable types in custom macro:
• Letter address arguments are used in custom macro to call G65 or G66 commands.
• Local variables range from #1 through #33 and are reset to vacant at M99 or M30.
• Common variables range from #100 through at least #149 and are reset to vacant when the machine is powered off (or M30 depending on the parameter setting).
• Permanent common variables range from #500 through at least #509 and are retained even after the machine’s power is turned off.
• System variables range from #1000 through #10000 or more, and are used to access CNC-related functions.

With the exception of letter address arguments, custom macro variables are specified with a hashtag symbol (#) and a number. So in a CNC program, #132, for example, specifies common variable number 132.

Here, we will concentrate on the appropriate use of local, common and permanent common variables. For simple custom macro applications, it may not matter which of these variable types you choose. However, there is a finite number of available variables. As application complexity or the number of related programs increases, appropriate variable-type selection becomes much more important. 

Volatility Issues
Local variables are the most volatile. They are only kept active during the execution of the program in which they are used. Common variables are less volatile, usually remaining active until the machine’s power is turned off. Permanent common variables are not volatile at all, since they are retained even after the power is turned off. Our general suggestion is to always choose the most volatile variable type that will adequately handle your application. Reserve the use of less volatile variables for times when variable volatility will cause some kind of problem.

In user-created canned-cycle applications, for example, everything happens right in the custom macro program. Consider a thread milling program. Once the program has been executed and a thread has been milled, there will no longer be a need for any of the variables used in the program. For this reason, you can/should exclusively use local variables (as long as they are not being used to represent arguments) for all of your user-created canned-cycle variable needs. While using common, or even permanent common variables, in a user-created canned-cycle custom macro program will work, doing so will reduce the number of available, less volatile variables for applications when they are needed.

With part-family applications, on the other hand, it is often necessary to share variables among programs. One program may, for instance, set a speed or feed-rate variable that will be used in another program. Since common variables are retained until the power is turned off, we recommend using them for this kind of application. And again, permanent common variables could be used, but using them in this manner would reduce the number of them available for times when they are truly needed.

By the way, if you expect to use previously developed user-created canned-cycle custom macro programs within part-family applications, you must be especially careful with common variables. If you use them within your user-created canned-cycle programs, you must take care not to overwrite any of the common variables being used for the part-family application.

Reserve the use of permanent common variables for applications that require variable values to be retained from day to day. Consider a part-counting custom macro program. The current part count must be retained even if the machine’s power is turned off. Also, some permanent common variables may already be in use, meaning you must confirm that they are available for your applications. This is especially true if your machine has certain accessories, like a spindle touch probe. 

Related Content

Basics

6 Variations That Kill Productivity

The act of qualifying CNC programs is largely related to eliminating variations, which can be a daunting task when you consider how many things can change from one time a job is run to the next.

Read More
Basics

Obscure CNC Features That Can Help (or Hurt) You

You cannot begin to take advantage of an available feature if you do not know it exists. Conversely, you will not know how to avoid CNC features that may be detrimental to your process.

Read More
CNC Tech Talks

2 Secondary Coordinate Systems You Should Know

Coordinate systems tell a CNC machine where to position the cutting tool during the program’s execution for any purpose that requires the cutting tool to move.

Read More
CNC Tech Talks

The Best Point of Reference for Program Zero Assignment Entries

Correctly specified program zero assignment and coordinate position values enable the CNC to determine how far to move the cutting tool during each positioning motion.

Read More

Read Next

Automation

Why We Ask Machine Shop Leaders to Speak at TASC – The Automated Shop Conference

TASC is our industry’s premier peer-to-peer automation stage where America’s shop leaders refine the art of metalworking and CNC machining. For conference speakers, it's also an opportunity to showcase your skills and gain exposure for your business. Here are five why stepping into the spotlight at TASC could be your smartest move toward elevating your shop.

Read More
View From My Shop

Shop Tour Video: You've Never Seen a Manufacturing Facility Like This

In the latest installment of our “View From My Shop” series, explore Marathon Precision’s multi-process approach to manufacturing, where blacksmiths and hand-forged dies meet state-of-the-art CNC machining. Discover how restoring classic muscle cars and building custom art projects creates a dynamic shop culture — and draws top talent to this unique and innovative metalworking facility. 

Read More

Registration Now Open for the Precision Machining Technology Show (PMTS) 2025

The precision machining industry’s premier event returns to Cleveland, OH, April 1-3.   

Read More