Digital Readout Kit for Mills, Lathes, & Grinding
Published

Custom Macros Can Skip Holes After Replacing Broken Tools

Using “vacant” local variables enables CNC machinists to create custom macros that can target multiple types of machining work.

Share

Leaders-In background
A stock photo of a woman operating a CNC machine

Some programmers shy away from using custom macros because they feel these macros make it more difficult to restart a program from the middle of a complex machining operation. This concern can often be overcome with a little planning. Indeed, custom macros sometimes make it easier to restart the program and run from the middle of a cutting tool’s machining operation.

The technique in this article was inspired by Chad Kluth of Mid Valley Industries in Kaukuana, Wisconsin. I was helping him resolve a different issue in a bolt-circle hole-machining custom macro. I include it here since it is relevant to our discussion.

Kluth’s application involved machining very large and tough 4140 steel components used in the mining industry. He needed to drill as many as 100 holes, each 2 inches in diameter, around a bolt-circle pattern into a round face/flange to a 6-inch depth. As you can imagine, tool wear and tool breakage are big issues. Even a drill with new inserts may not make it all the way through the cycle without wearing out — and the drill could be 90 holes into the cycle when it does wear out. To make matters worse, a hard inclusion in the raw material could cause the drill to break at any time.

Kluth uses a universal bolt-circle custom macro capable of performing several kinds of hole-machining operations, including drilling, standard tapping, rigid tapping, reaming and counterboring. The original issue had to do with rigid tapping. Being a “universal” custom macro, the M29 command needed to ignore rigid tapping if the machine was performing any other operation. To solve this issue, we used “vacant” local variables.

As for skipping holes, an argument in the calling command specifies the number of holes to skip. For example, if the drill wears out during the 90th hole, the user needs to set this argument to 89. We used the K-word (L-word with older FANUC CNCs) in the canned cycle command to specify whether the machine should skip a hole. If K is set to zero (K0), the hole is skipped. If K is set to one (K1), the hole is machined.

Here is a sample program containing an example calling command:

  • O0001
  • N005 G90 S500 M03
  • N010 G00 X0 Y0
  • N015 G43 H01 Z0.1
  • N020 G65 P9010 X0 Y0 Z0 C81.0 D6.0 R0.1 B12.0 A90.0 I100.0 F12.0 H89.0
  • N025 G91 G28 Z0
  • N030 M30

These are the mandatory arguments that must be in the calling command:

  • (X = X center)
  • (Y = Y center)
  • (Z = Z surface)
  • (D = Hole depth)
  • (C = Cycle to use — G81, G82, G83, G73 or G84)
  • (R = Z rapid position)
  • (B = Radius of bolt circle)
  • (A = Start angle)
  • (I = Number of holes)
  • (F = Feed rate)

These are the arguments that are only required in special cases:

  • (T = Needed with G82 to specify dwell time)
  • (Q = Needed with G73 or G83 to specify peck depth)
  • (M29.0 = Needed if rigid tapping)
  • (Sxxxx.x = Needed if rigid tapping to specify spindle RPM)
  • (H = Needed if skipping holes to specify the number of holes to skip)

Here is the custom macro:

  • O9010 (Universal bolt-circle custom macro)
  • #101=1 (Initialize counter)
  • #102=#1 (Initialize current angle to A)
  • #103=360 / #4 (Incremental angular distance between holes)
  • #104=#26 + 0.1 (Rapid approach plane)
  • #105=#26 - #7 (Z bottom position of hole)
  • #32=1 (Skip-hole counter — used if H is included in calling command)
  • N1 IF[#101 GT #4] GOTO 99 (Test if finished machining holes)
  • #110=#24 + COS[#102] * #2 (X position for current hole)
  • #111=#25 + SIN[#102] * #2 (Y position for current hole)
  • #33=1 (K word value, set to 1 in case next hole will be machined)
  • IF[#11EQ#0] GOTO5 (Test if H is included in the calling command)
  • IF[#32GT#11] GOTO5 (Test if finished skipping holes)
  • #33=0 (Next hole will be skipped)
  • N5 M#13 S#19 (Not executed if #13 and #19 are vacant)
  • G#3 X#110 Y#111 R#104 Z#105 P#20 Q#17 F#9 K#33 (Machine current hole)
  • G80 (Cancel cycle)
  • #101=#101 + 1 (Step counter)
  • #102=#102 + #103 (Step current angle)
  • #32=#32+1 (Step skip-hole counter)
  • GOTO 1 (Go back to test)
  • N99 M99 (End)

Here is a guide to the bolded items in the custom macro:

  • M#13 S#19 – If a CNC word contains a vacant local variable, the CNC will ignore the word. When performing rigid tapping, the calling command must include the words M29.0 and Sxxxx.0 (S specifies the RPM for rigid tapping). If doing some other operation, users must leave M and S out of the calling command.
  • P#20 and Q#17 – If the user is using counterboring (G82), they must include T in the calling command to specify dwell time. When peck drilling (G73 or G83), users must include Q to specify peck depth.
  • K#33 – FANUC has two programming formats for canned cycles. With newer FANUC CNCs, K specifies the number of holes being machined. Older FANUC CNCs use L for the same purpose. If this custom macro does not work (the machine is not skipping holes even if H is included in the calling command), change the K#33 in this command to L#33.
PMTS 2025 Register Now!
DANOBAT
JTEKT
DN Solutions
Starrett W9400 Touch Screen Indicator
Hurco
MWI
SolidCAM
MMS Made in the USA
Techspex
Pat Mooney Saws
Innovative Manufacturing for the Medical Industry

Related Content

CNC Tech Talks

5 Reasons Why You Should Know How to Write Custom Macros

Custom macros enhance what can be done in G-code programs, giving users the ability to code operations that were previously not possible.

Read More
Sponsored

How this Job Shop Grew Capacity Without Expanding Footprint

This shop relies on digital solutions to grow their manufacturing business. With this approach, W.A. Pfeiffer has achieved seamless end-to-end connectivity, shorter lead times and increased throughput.

Read More

Generating a Digital Twin in the CNC

New control technology captures critical data about a machining process and uses it to create a 3D graphical representation of the finished workpiece. This new type of digital twin helps relate machining results to machine performance, leading to better decisions on the shop floor.

Read More

Five-Axis Machines Speed NASCAR Engine Production

Moving from an aging set of five-axis mills to more advanced machines enabled Hendrick Motorsports to dramatically improve its engine production.

Read More

Read Next

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

5 Rules of Thumb for Buying CNC Machine Tools

Use these tips to carefully plan your machine tool purchases and to avoid regretting your decision later.

Read More
Workforce Development

Building Out a Foundation for Student Machinists

Autodesk and Haas have teamed up to produce an introductory course for students that covers the basics of CAD, CAM and CNC while providing them with a portfolio part.

Read More
CNC Turnkey Package for Knee Mills and Lathes