SMW Autoblok Stationary and Automation Products
Published

Second-Referencing Variables in Custom Macro

This technique allows operators to query a large number of values using only a few CNC commands.

Share

Here is a little-known technique that can help you query a large number of values with just a few custom macro commands. It can be used with any series of consecutively numbered variables, such as offset-related system variables, axis-related system variables, common variables and permanent common variables. Examples of when this technique can be helpful include:

• After using a spindle probe to determine how much raw material is on a surface to be machined. Maybe the probe has touched along a series of points on a rough casting and you wish to determine the high point. With this information, you can determine how many roughing passes to take.

• When querying a group of tool offset registers to determine whether any are inappropriately set. Perhaps the operator forgot to enter a value or the value is outside an acceptable range. 

The trick lies in understanding how custom macro variables can be second-referenced. Consider these commands:

#100 = 3.25 (Set common variable #100 to a value of 3.25)
#33 = 100 (Set local variable #33 to a value of 100)
#32 = #[#33] (Set local variable #32 the value of #100, which is 3.25)

In the third command, the first hashtag character (#) of #[#33] tells the CNC that a variable will be referenced; the #33 inside the brackets tells the CNC which variable will be referenced. Variable #33 is currently set to a value of 100, so the CNC currently evaluates #[#33] as #100.

In custom macro terms, this is called second-referencing a variable, and by itself, it may not seem to have helpful implications. Consider, however, that the value of the second-referencing variable (#33 in our example) can be changed, meaning a different variable will be in play. If a loop is used that steps the second-referencing variable number, a large number of variables can be queried with but a few custom macro commands.

Consider this more realistic example: You have a large casting to machine, but you are unsure of how much raw material must be removed from a surface, and that amount of material may change with each new casting.

Say the material to be removed is on the right side (X plus) of the casting, and this side is 20 inches long. If you use a spindle probe to find the most positive position in the X axis on the right side of the casting, the high point, you will be able to calculate the worst-case condition in terms of the amount of raw material to be removed. With this information, you will be able to determine how many roughing passes to take. You then have the spindle probe perform a series of touches, say 40 of them at 0.5-inch increments. You make the probe store the results of these touches (40 X positions) in common variables #101 through #140. Now you need to determine the high point (largest value). Here is a series of commands that will do so:

(Determine largest X value of #101-#140)
#32 = #101 (Starting largest X position)
#33 = 102 (Current common variable number to test)
N10 WHILE [#33 LE 140] DO 1 (Start of loop, testing through #140)
IF [#[#33] GT #32] THEN #32 = #[#33] (Retain larger value, #[#33] or keep #32)
#33 = #33 + 1 (Step second-referencing value)
END 1 (End of loop; #32 is the largest X position in the group)

These six custom macro commands test 39 common variables. When the loop is finished, local variable #32 will contain the largest X value in the group of probed positions. This value then can be compared to the X position of the finished X surface to determine how much raw material must be removed and how many passes to take.

Second-referencing variables can also be used with tool offsets. System variables from #2001 on, for example, are commonly used with machining center CNCs to provide access to tool-length geometry offsets: #2001 for offset one, #2002 for offset two and so on.

Consider this series of commands that tests offset registers from 1 through 20. If any are set to zero, an alarm is sounded (possibly indicating that the operator forgot to set one of them).

(Test offsets 1-20)
#100 = 2001 (Current offset number to test)
N10 WHILE [#100 LE 2020] DO 1 (Start of loop, testing through offset 20)
IF [#[#100] NE 0] GOTO 11
#3000 = 100 (Offset set to zero)
N11#100 = #100 + 1 (Step second-referencing value)
END 1 (End of loop; if loop ends, all offset registers have a value)

These examples show how second-referencing variables can come in handy whenever you have a series of consecutively numbered custom macro variables to query. 

SMW Autoblok Stationary and Automation Products
VERISURF
SolidCAM
An ad for Formnext Chicago on April 8-10, 2025.
IMTS 2024
World Machine Tool Survey
MMS Made in the USA
DN Solutions
Paperless Parts
EZ Access - Have it all with Ez - Mazak
High Accuracy Linear Encoders
Techspex

Related Content

Grinding

10 Things to Know About Creep-Feed Grinding

Because of the high material removal rate creep-feed grinding can deliver in challenging materials, grinding might not be just the last step in the process—it might be the process.

Read More

8 Ways to Increase Productivity on the Manufacturing Floor

When it comes to machine shop productivity, continuous improvement depends on efficient employees, equipment and processes. 

Read More
Basics

Buying a Lathe: The Basics

Lathes represent some of the oldest machining technology, but it’s still helpful to remember the basics when considering the purchase of a new turning machine. 

Read More
Turn/Mill

A New Milling 101: Milling Forces and Formulas

The forces involved in the milling process can be quantified, thus allowing mathematical tools to predict and control these forces. Formulas for calculating these forces accurately make it possible to optimize the quality of milling operations.

Read More

Read Next

Micromachining

A History of Precision: The Invention and Evolution of Swiss-Style Machining

In the late 1800s, a new technology — Swiss-type machines — emerged to serve Switzerland’s growing watchmaking industry. Today, Swiss-machined parts are ubiquitous, and there’s a good reason for that: No other machining technology can produce tiny, complex components more efficiently or at higher quality.

Read More

3 Mistakes That Cause CNC Programs to Fail

Despite enhancements to manufacturing technology, there are still issues today that can cause programs to fail. These failures can cause lost time, scrapped parts, damaged machines and even injured operators.

Read More

Encountering Surface Finishes in the Everyday World

Surface measurement is becoming increasingly important to ensure proper performance of a manufactured product. Advanced surface measurement tools are not only beneficial in the manufacturing industry but also have unconventional applications.

Read More
SMW Autoblok Stationary and Automation Products