Gravotech
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. 

Gravotech
Precision grinding & hard turning custom solutions
IMTS 2024
To any Measurement Question there is an Answer
Paperless Parts
MMS Top Shops
Gravotech
Kennametal
Hurco
IMTS 2024
MMS Made in the USA
The view from my shop.

Related Content

Measurement

How To Calibrate Your Calipers

If you’re interested in calibrating your own digital, dial or Vernier calipers, here are some steps to take to make sure it goes off without a hitch.

Read More

Understanding G27, G28, G29 and G30

Take a closer look at these reference position commands.

Read More

7 CNC Parameters You Should Know

Parameters tell the CNC every little detail about the specific machine tool being used, and how all CNC features and functions are to be utilized.

Read More
Basics

Threading On A Lathe

The right choices in tooling and technique can optimize the thread turning process.

Read More

Read Next

Large Part Machining

The Cut Scene: The Finer Details of Large-Format Machining

Small details and features can have an outsized impact on large parts, such as Barbco’s collapsible utility drill head.

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
Gravotech