Macro Threading Calculator, Simulator and NC Code Generator
Pass planning, FANUC macro program and tool path simulation that stop chatter and insert breakage on coarse-pitch, trapezoidal, tapered and multi-start threads.
Read this first — the problem this page solves
You know how to cut a thread. You can do an M20×2.5 with your eyes closed. Then a Tr40×8 trapezoidal thread lands on the machine and everything changes: the tool chatters, the surface comes out rough, the insert breaks after a couple of parts. You reduce the depth of cut and it still does not help.
The cause is not the depth of cut. As the pitch grows the thread groove gets wider. At a 2 mm pitch the groove opening is 1.75 mm; on an 8 mm pitch trapezoidal thread it is 5.07 mm. When the tool tries to cut that whole groove at once, the thing that sets the cutting force is how wide the tool is engaged at that instant. Halving the depth does not help enough, because the width has not changed — the tool vibrates and the insert cannot take the load.
The fix is to split the groove. This tool divides the thread groove along two axes: first into depth layers, then across the width of the groove within each layer. The tool cuts one part of the groove, then the next. Same thread, same helix — only the area engaged at any instant gets smaller. Since the groove is wide at the top and narrow at the root, there are more lateral passes in the upper layers and fewer deeper down.
Why can we not just do this by hand — why is a macro needed?
You can do it by hand — but a Tr40×8 means 9 depth layers × 2–3 lateral passes = 24 separate threading passes. You would have to work out the X value, the Z shift and, on a taper, the slope for every one of them. One wrong digit and you either scrap the thread or lose the tool.
The macro makes the control do that arithmetic. You give only the major diameter, the pitch and the depth; the macro generates the layers, the lateral passes and the start angles itself. Load it onto the machine once and every thread after that is a single G65 call.
Why is the built-in G76 cycle not enough?
G76 is a good cycle and the first choice on standard 60° threads. It runs into three walls:
- The tool nose angle in the standard format can only be 80°, 60°, 55°, 30°, 29° or 0°. Asymmetric profiles such as buttress (3°/30°) cannot be entered.
- Multi-start threads are impossible. The start shift is given with address
Q, but in G76Qis already used for the depth of cut. - It cannot split the groove into lateral passes. It divides the depth, not the width — so it does not solve the actual problem.
That is why the macro uses G32. G32 is a single synchronised interpolation: you give X and Z however you like and the helix stays locked to the spindle. That is where the flexibility comes from.
Will this program run on my machine?
The macro is called with G65 — that call form requires no CNC parameter change whatsoever. If your control has Custom Macro B, it runs. Conditional branches are written as IF[…]GOTOn; older controls that do not support IF…THEN will not trip over it.
The NC program tab contains no macro at all — every pass is written out one by one, so it also runs on controls without macro support. Use that one if you want to be certain.
Do not change CNC parameters yourself. The numbers differ from model to model; the same function is No.7051 on FS10/11 and No.6051 on the 0i / 16i / 30i family.
What you read off the drawing
Simulation — the tool moves as the code runs —
Thread profiles and depth: what the tool calculates and how
If you leave the minor diameter blank, the tool works out the depth from the selected profile. Knowing the figures behind that calculation lets you compare the tool's value with the minor diameter on the drawing; if they differ by more than 0.1 mm, enter the drawing value, because the drawing always takes priority. In the table h3 is the external-thread depth on the radius and P is the pitch.
| Profile | Thread angle | External depth (radius) | Typical use |
|---|---|---|---|
| Metric ISO (M) | 60° | h3 = 0.6134 · P | General fasteners |
| Unified UN/UNC/UNF | 60° | h3 = 0.6134 · P (P = 25.4 / TPI) | Inch fasteners |
| Whitworth (BSW/BSP) | 55° | h3 = 0.6403 · P | Pipe threads, older British standards |
| Trapezoidal ISO/DIN 103 (Tr) | 30° | h3 = 0.5 · P + ac (ac = 0.25 mm for P 2–5; 0.5 mm for P 6–12; 1 mm for P 14–44) | Lead screws, vice and press spindles |
| ACME | 29° | h = 0.5 · P + clearance | Lead screws of US origin |
| Buttress DIN 513 | 3° / 30° | h3 ≈ 0.868 · P | Heavy axial load in one direction (presses, jacks) |
Example: for Tr40×8, h3 = 0.5 · 8 + 0.5 = 4.5 mm and the minor diameter is 40 − 2 · 4.5 = Ø31. An M40×1.5 on the same diameter is only 0.92 mm deep. With five times the depth and three times the groove width, the volume of material removed grows by a factor close to fifteen; those numbers are the reason for the macro approach. For standard 60° threads the G76 threading cycle simulator and, for the single-block approach, the G92 threading cycle simulator are the shorter route.
Four infeed strategies and the load-split logic
| Strategy | How the tool feeds in | Advantage | Drawback |
|---|---|---|---|
| Radial (straight) | Each pass only goes deeper in X | Simple, symmetrical profile, fine for small pitches | Both flanks cut at once, V-shaped chip jams, chatter |
| Flank | Feeds in at half the thread angle (30°/29°) | One flank cuts, chip flows freely | The idle flank rubs, surface finish suffers |
| Modified flank | Feeds in 3–5° less than half the thread angle | Good chip control, second flank takes a light clean-up cut; the general recommendation | Unnecessary on fine pitches |
| Alternating flank / lateral split | Cuts the left and right side of the groove in separate passes at the same depth | Both edges of the insert wear evenly, lowest force in a wide groove | Many passes; hard to program by hand, a macro is needed |
This tool automates the last row. The depth layers follow #7 · √n: you give the first pass depth and the n-th pass stops at √n times that value. The difference between consecutive passes therefore shrinks and the chip cross-section removed per pass stays roughly constant, so the cutting force does not climb as the thread gets deeper. At each layer, if the groove is wider than the insert tip, the difference is split into lateral passes with FUP[#117/#2]+1; argument B (lateral step) sets how fine that split is. Choosing B between 60 and 80 percent of the insert tip width usually works well: a smaller value inflates the number of passes, a value equal to the tip width leaves a thin fin between two passes.
Custom Macro B: G65 arguments and variables
The macro is called with a single block: G65 P9500 X40. Z-60. F8. K4.5 B1.2 W1.6 …. Every letter on the G65 block becomes a numbered local variable inside the subprogram. FANUC's standard letter-to-variable mapping is below; G, L, N, O and P cannot be used as arguments (P is the program number, L the repeat count).
| Letter | Variable | Letter | Variable | Letter | Variable |
|---|---|---|---|---|---|
| A | #1 | I | #4 | T | #20 |
| B | #2 | J | #5 | U | #21 |
| C | #3 | K | #6 | V | #22 |
| D | #7 | M | #13 | W | #23 |
| E | #8 | Q | #17 | X | #24 |
| F | #9 | R | #18 | Y | #25 |
| H | #11 | S | #19 | Z | #26 |
The O9500 macro in this tool uses exactly that mapping: X (#24) major diameter, Z (#26) thread end point, F (#9) lead, K (#6) thread depth on the radius, B (#2) lateral step, W (#23) insert tip width. Three families of variables live inside a macro. Local variables #1–#33 exist only for that G65 call and are cleared when it ends. Common variables #100–#149 are shared between programs but reset at power-off; the tool keeps its intermediate results in #110–#124. Permanent common variables #500–#999 survive power-off and are reserved for things like offsets and counters; this macro does not touch them. System variables read the machine state: #5041/#5042 are the current X/Z position in the workpiece coordinate system, #4001 is the modal G code of group 01, #3000 raises a user alarm. Because the macro saves the start position in #102/#103 and returns there at the end, the flow of your main program is not disturbed.
Conditional flow is written as IF[#115 LT #112] GOTO 100; the comparison operators are EQ, NE, GT, GE, LT and LE, and the square brackets are mandatory. The GOTO target is an N number; if that N block does not exist you get alarm PS0128. The WHILE…DO…END structure is more readable but is not available on every control, which is why the tool uses only IF/GOTO. Of the FANUC macro functions the tool uses SQRT, FUP (round up), ROUND and ABS; all four belong to the basic Custom Macro B set.
The physics of G32 threading: synchronisation, lead and run-in
On a G32 block the F address is not a feed rate but the lead: the distance the tool travels in Z per spindle revolution. For a single-start thread the lead equals the pitch; for a three-start Tr40×8 the lead is 24 mm and F24. is written. The control waits for the one-revolution signal from the spindle encoder and starts every pass at the same angular position, so every pass must start from the same Z point at the same RPM. The tool therefore starts all passes from one Z start point and sets it to max(3 mm, 1.4 × lead); for a 24 mm lead that is a 33.6 mm run-in. The distance is needed for the axis to reach its programmed speed: the portion cut while Z is still accelerating has a wrong pitch, and the run-in keeps that portion outside the part. For the same reason the exit needs a thread relief groove or enough clearance; under G32 the tool stops as soon as it reaches the end Z, there is no automatic chamfer as in G76.
The RPM is held constant with G97. Under G96 constant surface speed the RPM changes as the diameter changes and the pitch is ruined; that is why the tool writes G97 S____ at the start of the program and leaves the value to you. During threading the feed override is locked to 100 percent and the feed hold key is held off until the pass is complete; this is the control's own behaviour and cannot be switched off. On a multi-start thread the offset between starts is given as a spindle start angle with the Q address, in units of 0.001° and without a decimal point: on a three-start thread the second start is Q120000 and the third Q240000. The tool computes this inside the macro with ROUND[360000·[#121−1]/#3]. If an older FANUC model does not support Q, the starts are offset by shifting the Z start point by one pitch; the run-in must then remain sufficient for every start.
Insert selection: which insert for a coarse pitch?
- Full-profile threading insert: profile and pitch are ground into the insert; it also cuts the crest and gives the best finish. Each pitch needs its own insert, though, and for Tr/ACME above 6 mm pitch the choice becomes thin. In this tool enter the flat of the insert tip as "cutting edge width".
- Partial-profile (V) insert: only the thread angle is fixed, so one insert covers a wide pitch range. It does not cut the crest, so the major diameter must be turned beforehand. Its small nose radius does not form the full root radius; the tool corrects the depth for the nose radius for that reason.
- Grooving insert: the most common economical solution for trapezoidal and ACME threads; flat-tipped and narrower than the root. Lateral sweeps are compulsory to cut the flanks, and the tool's lateral-pass logic was designed for exactly this insert. Choose a width between 70 and 90 percent of the root width.
- Round-nose tool: used for large-pitch round threads and for roughing; because it has no flank angle, a separate finishing tool completes the final profile.
A coarse pitch also means a larger helix angle: about 4° for single-start Tr40×8 and close to 12° for three starts. A standard insert shim is inclined 1–1.5°; once the helix angle exceeds that, the trailing flank of the tool rubs on the thread and the idle flank shows burnished marks. The fix is a shim (anvil) inclined to match the helix angle; a rubbing noise and heat are the signs that this adjustment is missing.
Alarms and problems seen on the shop floor
| Symptom / alarm | Cause | Fix |
|---|---|---|
| PS0114 ILLEGAL EXPRESSION FORMAT | Missing square bracket, IF[…] or an arithmetic expression mistyped | Check that no line was corrupted while transferring the macro; load from file instead of copy-pasting |
| PS0115 VARIABLE NO. OUT OF RANGE | The control has no common variables beyond #100–#149 (#100–#199 is an option on some models) | Check the variable range; the tool uses #110–#124, available on most models |
| PS0128 SEQUENCE NUMBER NOT FOUND | The N block targeted by a GOTO was deleted or renumbered | Do not remove blocks such as N100, N21, N22 from the macro |
| PS0129 ILLEGAL ARGUMENT / user alarm 1 or 2 | F (lead) or K (depth) missing on the G65 block | The macro stops with #3000; add the missing argument to the call block |
| Thread drifts every pass, flanks torn | RPM changed between passes (G96) or a different Z start | G97 constant RPM, all passes from the same Z start; the tool already does this, do not break it when editing by hand |
| Wrong pitch at the start of the thread | Run-in too short, cutting begins before the axis is up to speed | Leave the Z start at least 1.4 × lead ahead; longer at high RPM |
| Chatter persists | Lateral step B too large, first pass too deep, tool overhang too long | Reduce B, bring the first pass down to 0.3–0.4 mm, mount the tool short |
| Idle flank burnished, surface shows rubbing marks | Helix angle exceeds the shim angle | Fit a shim inclined to the helix angle |
| Starts not evenly spaced (multi-start) | Q start angle written with a decimal point or not supported | Integer form such as Q120000; if unsupported, use the Z-shift method |
| Gauge does not go, thread too tight | Minor diameter calculated differently from the drawing, or the insert tip width entered wrongly | Enter the drawing's minor diameter by hand, measure the insert and correct the width; repeat the last pass as a spring pass |
Points to check when loading the macro on the machine
- O9500 lies in the 9000–9999 range, which some machines lock against editing through parameter 3202 (the NE9 bit). If the program cannot be transferred, rename it to a free number such as O8500 and change the P on the G65 block to match.
- Macro comments are in parentheses and use upper-case ASCII; comments with accented or non-Latin characters cause read errors on some controls, which is why the tool deliberately writes them in simplified form.
- Make the first run in single-block mode and away from the part, in fresh air; compare the sequence of G00 and G32 moves with the simulation on the canvas.
- In the main program bring the tool to the safe position (the X and Z start the tool suggests) before the macro call; the macro reads the start position from #5041/#5042 and returns there, so a wrong start point is also wrong on the return.
- On machines without macro support, or with uncertain parameters, use the explicit code on the "NC program" tab; the same passes are written out one by one and contain no variables at all.
Frequently asked questions
Can lateral passes be done with G92 or G76 instead of G32?
Partly with G92: flank passes can be written by shifting the Z start and X by hand on every block, but as the count grows so does the risk of error, and there is no Q support for multi-start threads. G76 applies its own pass plan and does not accept an external lateral shift. That is why a load-split program is only written cleanly with G32 or a macro.
Does the same macro work for internal threads?
Yes. When "Internal thread" is selected in the tool the X direction is reversed; inside the macro this is done with the sign variable #113 (external −1, internal +1), while #110, which holds the sum of the flank slopes, stays the same in both cases. For an internal thread the bore diameter becomes the minor diameter, the run-in must lie outside the mouth of the bore, and because the tool overhang is long the first pass should be shallower than for an external thread.
Where does the X value come from on a tapered thread?
When taper is selected, X is written on the G32 block together with Z; the control drives both axes synchronously and the helix follows the cone surface. The tool calculates the slope from the taper start and end diameters and shifts both the entry and exit X of every pass. For standard tapers such as pipe threads (1:16) entering the two diameters from the drawing is enough.
How many passes are ideal?
There is no fixed number; the aim is to keep the cross-section removed on each pass below what the insert can carry. For Tr40×8 with a grooving insert, 9 layers and 20–25 passes in total is a typical figure; in hard material reduce the first pass and increase the number of layers, in aluminium and brass you can reduce them. If the insert catalogue gives a recommended pass table, take the first-pass value from there.