top of page
Writer's pictureMike Lynch

A Custom Macro For Thread Milling

Updated: May 9

As you know, custom macro is a very powerful programming feature that allows you to include computer programming-like commands in a G-code level program. Here's a great user created canned cycle application to help you command thread milling operations.


This custom macro assumes your machining center is equipped with helical interpolation. It also assumes, of course, that your machine is equipped with custom macro B. It machines straight threads (not tapered threads) inside a hole. It will not machine external threads. It can machine in a climb milling manner (G03, coming out of the hole) or a conventional milling manner (G02, moving into the hole).


We're assuming you're using a thread milling cutter that can machine the entire thread in one pass around the hole (see drawing). That is, the thread milling cutter cannot be the "single tooth" type cutter.


While we've included some error trapping within this custom macro, you'll want to be careful with its use - as you would with any new program. Be sure to dry run it (and use your machine's graphics capabilities if available) several times to ensure that you understand the meaning of the related input values (arguments).


Here is a drawing that shows the arguments to be included in the call statement:


And here is an example calling program:

  • O0001 (Main program)

  • .

  • .

  • .

  • (Machine hole)

  • .

  • .

  • .

  • N075 T04 M06 (Thread mill)

  • N080 G54 G90 S1200 M03 T05 (Start spindle)

  • N085 G00 X2.5 Y2.0 (Rapid to hole center)

  • N090 G43 H04 Z0.1 (Rapid approach in Z)

  • N095 M08 (Turn on coolant)

  • N100 G65 P1000 X2.5 Y2.0 D3.0 R0.1 Z-1.0 Q0.0625 A1.25 T1.0 F5.0 M1.0 (Mill thread)

  • N105 G91 G28 Z0 M19 (Return to tool change position)

  • N110 M01 (Optional stop)

  • .

  • .

  • .

  • (Program continues)

  • .

  • .

  • .

  • N200 M30 (End of main program)

Again, this is a user created canned cycle application, so you treat it much like any canned cycle. Notice how, in lines N075 through N095, we're calling up the tool, getting the spindle started, and moving into an approach position (instating tool length compensation along the way) - just like you'd do before you command any canned cycle.


Line N100 is the command that calls the custom macro. Notice all the input variables (arguments). Be sure to include a decimal point for each one.


While the drawing and example program may be self-explanatory, let me make a few points.

1. X, Y, R, and Z are absolute positions - they must be specified from the program zero point of your program. If program zero in Z is the top surface of the workpiece, the Z word will be negative.


2. This custom macro does not use cutter radius compensation. Instead, you specify the diameter of the milling cutter right in the call statement (with the T word). If you need to make sizing adjustments, the T word in the program must be changed.


3. The tool first moves to the center of the approach radius in XY and to the rapid plane (R word) in Z. We're making a test in the custom macro to confirm that the approach radius is large enough. From this position, the tool will fast feed at five times the cutting feedrate (F word in the call statement) to the Z position at the bottom of the hole (Z word).


4. When it comes to milling style, we set the default to climb milling (if you leave the M word out of the call statement, the custom macro will climb mill). Climb milling usually leaves the best finish, and will cause the custom macro to use G03 (counter clockwise) motion. The Z motion will be coming out of the hole as the thread is milled. This also provides a little better chip handling. But if you prefer to conventional mill (G02 with tool moving deeper into the hole during machining), set M to 1.0 (M1.0).


5. The Z word must reflect milling style. If climb milling, the cutter will be coming out of the hole during machining. The total motion outward will be 1.5 times the pitch of the thread. If you will be machining a thread with a 0.0625 pitch, Z must be specified at least 0.0937 (plus a little clearance) past the bottom of the thread. If conventional milling, Z can be just slightly below the thread bottom.


6. Note that all arguments (except M) must be included in the call statement. If you leave one out, an alarm will be sounded (MC100 INPUT VALUE MISSING).


7. We've heavily documented the custom macro to help you understand what's going on. To conserve memory space in the control, these messages can be deleted (except those in the #3000 commands).


8. We're using some tricks to keep from having to write two sets of motions (based upon the setting of M). See if you can figure out what's going on!


Now, here's the custom macro:

  • O1000 (Thread milling custom macro)

  • (SET DEFAULT MILLING STYLE TO CLIMB MILLING)

  • IF [#13 NE #0] GOTO 1

  • #13=0


  • (TEST FOR MISSING ARGUMENTS)

  • N1 IF [#24 EQ #0] GOTO 95 (X)

  • IF [#25 EQ #0] GOTO 95 (Y)

  • IF [#26 EQ #0] GOTO 95 (Z)

  • IF [#18 EQ #0] GOTO 95 (R)

  • IF [#7 EQ #0] GOTO 95 (D)

  • IF [#20 EQ #0] GOTO 95 (T)

  • IF [#9 EQ #0] GOTO 95 (F)

  • IF [#1 EQ #0] GOTO 95 (A)

  • IF [#17 EQ #0] GOTO 95 (Q)


  • (A MUST BE BIGGER THAN HALF OF T)

  • IF [#1 GT [#20/2 +0.1]] GOTO 2

  • #3000=101(APPROACH RADIUS TOO SMALL)


  • (RAPID TO APPROACH POSITION)

  • N2 G00 X#24 Y[#25 + #7/2 - #1]

  • Z#18


  • (FAST FEED TO STARTING Z POSITION)

  • G01 Z#26 F[#9 * 5]


  • (TEST FOR CLIMB VS CONVENTIONAL)

  • IF [#13 EQ 0] GOTO 10

  • (CONVENTIONAL MILL SETTINGS)

  • #100=[0-1] * [#1 - #20/2]

  • #101=#1 - #20/2

  • #102=2 (Motion type G02)

  • #103=0-1 (Polarity for stepping Z is minus)

  • GOTO 11

  • (CLIMB MILL SETTINGS)

  • N10 #100=#1 - #20/2

  • #101=[0-1] * [#1 - #20/2]

  • #102=3 (Motion type G03)

  • #103=1 (Polarity for stepping Z is plus)


  • (MOTIONS TO MILL THREAD)

  • N11 G01 X[#24 + #100] F#9

  • #26=#26 + [#103 * #17/4] (Step Z by 1/4 pitch)

  • G#102 X#24 Y[#25 + #7/2 -#20/2] Z#26 R[#1 - #20/2]

  • #26=#26 + [#103 * #17/2] (Step Z by 1/2 pitch)

  • Y[#25 - #7/2 + #20/2] Z#26 R[#7/2 - #20/2]

  • #26=#26 + [#103 * #17/2] (Step Z by 1/2 pitch)

  • Y[#25 + #7/2 -#20/2] Z#26 R[#7/2 - #20/2]

  • #26=#26 + [#103 * #17/4] (Step Z by 1/4 pitch)

  • X[#24 + #101] Y[#25 + #7/2 - #1] Z#26 R[#1 - #20/2]

  • G00 X#24

  • Z#18

  • GOTO 99

  • N95 #3000=100 (INPUT VALUE MISSING)

  • N99 M99 (End of custom macro)

6,668 views0 comments

Recent Posts

See All

Comments


bottom of page