Variables in Custom Macro

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


Facebook Share Icon LinkedIn Share Icon Twitter Share Icon Share by EMail icon Print Icon

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.