FIFTY LINETurn G-code

Threading in LinuxCNC: G33 and G76 with examples

· ~11 min read

Threading is the most nerve-racking lathe operation. The Z axis has to move in exact sync with the spindle, the profile is built up over many passes, and a mistake in a sign or a unit breaks the insert or ruins an almost finished part. LinuxCNC has two tools for threads: G33 (a single threading pass) and G76 (a multi-pass cycle). Here is how both work, with calculations and examples.

Contents

  1. What the machine needs for threading
  2. G33 - a single threading pass
  3. Thread depth and diameters
  4. How many passes, and how deep
  5. Infeed method: radial and flank
  6. The G76 cycle: parameters
  7. G76 example: M12×1.5
  8. Run-in and run-out
  9. Internal, left-hand, multi-start, inch, tapered
  10. G32 and G76 on Fanuc - the differences
  11. Common mistakes
  12. Threading in Turn G-code

What the machine needs for threading

  • A spindle position sensor (encoder) with an index pulse - one pulse per revolution. In HAL it is connected to spindle.0.revs and spindle.0.index-enable. G33 and G76 do not work without it: LinuxCNC waits for the index pulse so that every pass starts at the same angle and follows the groove already cut.
  • Constant RPM - G97. With G96 the RPM changes with the diameter, while the thread pitch is in mm per revolution.
  • Enough Z axis speed. Z speed = RPM × pitch. At S300 with a 1.5 mm pitch that is 450 mm/min; at S1000 with a 3 mm pitch it is already 3000 mm/min. If the axis cannot keep up, the pitch drifts.
  • Hands off the overrides. Changing the spindle override in the middle of a thread ruins the profile: the passes stop lining up.

G33 - a single threading pass

G33 Z-25 K1.5
  • Z (and X if needed) - the end point of the pass.
  • K - thread pitch (lead) in mm per revolution with G21, or inches per revolution with G20.

A full pass looks like this: move to depth, synchronized move, retract, return.

G0 X11.8 Z3         (move to pass depth, 3 mm run-in)
G33 Z-20 K1.5       (threading pass)
G0 X14              (retract from the part)
G0 Z3               (return to the start)

A thread needs many of these blocks, with a gradually smaller diameter (for an external thread) and the same Z start point. Writing them by hand is slow and risky, which is why G76 and program generators exist.

Thread depth and diameters

For metric threads (ISO, 60° profile) with pitch P:

Value Formula M12×1.5
Fundamental triangle height H 0.866·P 1.299 mm
External thread depth (bolt) h₃ 0.6134·P 0.92 mm
Bolt minor diameter d₃ d − 1.2269·P 10.16 mm
Internal thread depth (nut) H₁ 0.5413·P 0.812 mm
Nut minor diameter D₁ d − 1.0825·P 10.376 mm

In practice the bolt major diameter is turned 0.1-0.2 mm under nominal, and the hole for an internal thread is bored close to D₁. The final check is a thread gauge (ring or plug) or the mating part.

For inch threads (UNC, UNF) the pitch comes from threads per inch (TPI): P = 25.4 / TPI mm. For example, 1/2”-13 UNC has a 1.954 mm pitch. Pipe threads BSP (G) and NPT have their own profile angles (55° and 60°) and tables.

How many passes, and how deep

If every pass has the same depth, each one removes more metal than the last: the chip gets wider as the profile gets deeper. So pass depth is reduced as you go: the first pass is the deepest, the last ones are light.

  • Constant chip area: depth after pass n = first pass depth × √n. The load on the insert is the same on every pass.
  • A final spring pass at the same diameter with no extra infeed takes out the springback.
  • A rough guide to the number of passes: 1 mm pitch - 4-6, 1.5 mm - 6-10, 2 mm - 8-12. More for gummy stainless, a light machine or long tool overhang; fewer for brass and a rigid machine. For exact values, see your insert maker’s catalog.

Infeed method: radial and flank

  • Radial infeed - the tool moves straight in X. Both cutting edges work, chips evacuate poorly, chatter is possible. Fine for small pitches and ductile materials.
  • Flank infeed (compound infeed) - each pass is also shifted in Z, so the tool travels along one flank of the profile. For a 60° thread the usual angle is 29.5°: one edge does the main work, and the other lightly cleans its flank.
  • Modified (alternating) flank infeed - the flanks alternate, so the insert wears evenly. Used for large pitches.

The G76 cycle: parameters

G76 calculates and runs all the passes itself. Before it, the tool is placed at the start point: its X defines the drive line - the tool returns along it between passes - and its Z is the start of the thread.

G76 P- Z- I- J- K- R- Q- H- E- L-
Parameter Meaning
P Thread pitch (lead per revolution)
Z End of the thread in Z
I Offset of the thread peak from the drive line. Negative - external thread, positive - internal
J First pass depth (positive), measured from the thread peak
K Full thread depth (positive)
R Depth degression: 1.0 - constant depth, 2.0 - constant chip area. Values in between work too
Q Compound (flank) infeed angle, for example 29.5. Default 0 - radial infeed
H Number of spring passes at full depth
E Length of the taper (run-out) at the thread ends, in Z
L Where to taper: 0 - none, 1 - entry, 2 - exit, 3 - both ends

Important: in diameter mode G7 and radius mode G8 the values of X, I, J, K are interpreted differently. Check the G76 documentation for your LinuxCNC version, and run the cycle “cutting air” with extra X clearance the first time.

G76 example: M12×1.5

External M12×1.5 thread, 20 mm long, written in radius mode G8 (X is the radius). Part zero is on the face and the centerline; the major diameter is already turned.

G8 G18 G21 G90 G40      (radius, XZ plane, mm, absolute)
G97 S300 M3             (constant RPM - 300)
G0 X7 Z3                (drive line: radius 7 = D14, 3 mm off the face)
G76 P1.5 Z-20 I-1 J0.1 K0.92 R1.5 Q29.5 H1 E1.5 L2
G0 X20 Z20              (retract)
M5
M30

How to read the G76 line:

  • the tool starts at radius 7, the thread peak is at radius 6 (I-1), i.e. Ø12;
  • the first pass is 0.1 mm below the peak (J0.1), full depth is 0.92 mm (K0.92, which is h₃ for a 1.5 pitch);
  • pass depth decreases (R1.5), with 29.5° flank infeed (Q29.5);
  • one spring pass at the end (H1);
  • a 1.5 mm run-out at the exit (E1.5 L2) - the tool leaves the metal smoothly, without a step.

This is a teaching example: before cutting on your machine, check the G7/G8 mode, the zero, the tool offset, and that the X retract does not run into the chuck or tailstock.

Run-in and run-out

Run-in is the distance before the thread starts. At the start of a synchronized move the Z axis accelerates and lags behind the spindle for a moment, so the pitch is off for the first millimeters. The tool has to get up to speed in the air: the start is usually 2-3 pitches or a few millimeters off the face, more at high RPM or with a slow axis.

Run-out is how the tool leaves the thread. If the thread runs up to a shoulder, you need an undercut (a relief groove for the tool) or a smooth X retract inside the synchronized move, like E/L in G76 or a G33 X… Z… K… line. Otherwise there is a step at the end of the thread, and the tool can crash into the shoulder.

Internal, left-hand, multi-start, inch, tapered

  • Internal thread. The passes go with an increasing diameter, and the retract is toward the centerline, inside the bore. In G76, I is positive. Make sure the boring bar fits in the bore including the retract.
  • Left-hand thread. Either run the spindle in reverse (M4) with the tool upside down, or cut from the chuck toward the face (Z plus). Which one depends on your machine and toolpost.
  • Multi-start thread. K (or P in G76) is the lead: pitch × number of starts. Each next start begins shifted in Z by one pitch. For example, a 2-start thread with a 1.5 pitch has lead K3, and the second start begins 1.5 mm further along Z.
  • Inch thread. With G20, K is in inches per revolution: for 13 TPI it is K0.0769. You can also stay in G21: K = 25.4 / TPI.
  • Tapered thread (NPT, BSPT, 1:16 taper). Give G33 both X and Z - the tool follows a sloped line while keeping the pitch. G76 cannot cut a thread tapered along its whole length, only tapers at the ends. A full walkthrough is on the Taper threading page.

G32 and G76 on Fanuc - the differences

  • On Fanuc and many Chinese controls (GSK, KND, Syntec) a threading pass is G32 with the pitch in F. In LinuxCNC it is G33 with K.
  • Fanuc G76 is written in two lines with different addresses (P made of three digit pairs, some values in microns without a decimal point), while LinuxCNC uses one line with its own letters. A Fanuc threading program cannot be moved to LinuxCNC as is.
  • Fanuc also has a simple threading cycle, G92; in LinuxCNC G92 is a coordinate system offset - a completely different command.

For the full list of codes, see the G-code and M-code reference for lathes.

Common mistakes

  1. G96 instead of G97. The RPM changes, so pitch and profile wander.
  2. No index pulse, or the encoder counts the wrong way. Passes miss each other’s groove and you get a “double” thread.
  3. Too little run-in. The first turns have the wrong pitch and the nut will not go on.
  4. Wrong sign of I in G76. An external thread with a positive I is cut as an internal one - the tool drives into the part.
  5. G7/G8 mix-up. The depth comes out twice or half what it should be.
  6. First passes too deep. Chipped insert, chatter, torn profile.
  7. Turning the spindle override mid-thread. The profile is ruined.
  8. Fanuc code. G32, G92 or a two-line G76 work differently in LinuxCNC, or not at all.

Threading in Turn G-code

In Turn G-code a thread is a form with fields. The Threading cycle cuts external and internal, right- and left-hand, and multi-start threads. The Taper threading cycle cuts threads along a taper. You enter:

  • diameter and pitch, number of starts, thread length;
  • number of roughing and finishing passes;
  • run-in and run-out length;
  • the threading move syntax: G33 or G32, and the pitch letter K, I or F - to match your control.

The program calculates the depth and diameter of every pass and outputs ready G-code: separate lines for the approach, run-in, thread and run-out, without G76, so every pass is visible in the code and in the 2D simulator before you run it. Here is the start of a real program for M12×1.5 (G7 mode, X is the diameter, G32 K syntax):

G21 G18 G90 G7 G40 G80
G54

G97 S50 M3
G0 Z3.0000
G0 X18.0000

G0 Z3.0000
(Pass 1 of 10, X12.0000)
G0 X12.0000
G0 Z2.0000
G32 Z0.0000 K1.5000
G32 Z-18.0000 K1.5000
G32 X14.0000 Z-20.0000 K1.5000
G0 X18.0000

The last pass lands on Ø10.16 - exactly d₃ for M12×1.5. The full program, explained line by line, is on the Threading page.

Download Turn G-code - 15 days free, no key needed.

← All articles