Inch threads in LinuxCNC: G20, TPI to pitch and G33/G76 examples
· ~7 min read
LinuxCNC threads by pitch - inches or millimeters per revolution - while inch threads are specified in threads per inch (TPI). The conversion is simple, but there are a few places where it goes wrong: a missing G20, a rounded pitch, feeds and surface speed in the wrong units. Here is how to do it properly.
Contents
- Two ways: G20 or G21
- TPI to pitch
- How many decimals the pitch needs
- What else changes in G20
- Example: 3/8-16 UNC with G33
- Example: the same thread with G76
- Common mistakes
- Inch mode in Turn G-code
Two ways: G20 or G21
- The whole program in inches (G20). Diameters, lengths, depths and the pitch are in inches: for 16 TPI the pitch is K0.0625. This is the natural choice when the drawing is in inches.
- A metric program (G21) with the pitch in mm. Everything stays in millimeters, only the pitch is converted: K = 25.4 / TPI, for 16 TPI K1.5875. Handy when the part is metric but needs one inch thread (a 1/4-20 hole in a metric bracket, a UNF fitting).
LinuxCNC switches between G20 and G21 at any point in the program, whatever units the machine is configured in (LINEAR_UNITS in the INI file). The result is the same thread either way.
TPI to pitch
Pitch in inches = 1 / TPI, pitch in mm = 25.4 / TPI.
| TPI | Pitch, in | Pitch, mm | Where you meet it |
|---|---|---|---|
| 8 | 0.125 | 3.175 | 1-8 UNC |
| 9 | 0.111111 | 2.822222 | 7/8-9 UNC |
| 10 | 0.1 | 2.54 | 3/4-10 UNC |
| 11 | 0.090909 | 2.309091 | 5/8-11 UNC, BSP 1” and up |
| 12 | 0.083333 | 2.116667 | 9/16-12 UNC, 1-12 UNF |
| 13 | 0.076923 | 1.953846 | 1/2-13 UNC |
| 14 | 0.071429 | 1.814286 | 7/16-14 UNC, 7/8-14 UNF, NPT/BSP 1/2”, 3/4” |
| 16 | 0.0625 | 1.5875 | 3/8-16 UNC, 3/4-16 UNF |
| 18 | 0.055556 | 1.411111 | 5/16-18 UNC, 9/16-18 and 5/8-18 UNF |
| 20 | 0.05 | 1.27 | 1/4-20 UNC, 7/16-20 and 1/2-20 UNF |
| 24 | 0.041667 | 1.058333 | #10-24 UNC, 5/16-24 and 3/8-24 UNF |
| 28 | 0.035714 | 0.907143 | 1/4-28 UNF |
| 32 | 0.03125 | 0.79375 | #6-32, #8-32 UNC, #10-32 UNF |
| 40 | 0.025 | 0.635 | #4-40 UNC, #6-40 UNF |
Thread depths and minor diameters for each size are in the UNC/UNF thread chart for CNC lathes. To convert any TPI to pitch and back, with the nearest metric pitch, use the TPI to pitch converter.
How many decimals the pitch needs
Many TPI values give an endless decimal: 1/13 = 0.076923…, 25.4/13 = 1.953846… The pitch error adds up on every turn, so on a long thread a rounded K becomes visible:
| K for 13 TPI | Error over 1 in (13 turns) | Over 3 in |
|---|---|---|
| K0.0769 | 0.0003 in | 0.0009 in |
| K0.07692 | 0.00004 in | 0.0001 in |
| K0.076923 | 0.000001 in | 0.000004 in |
0.0009 in over three inches is enough to make a long nut bind. LinuxCNC accepts many decimals, so write at least six for an inch pitch (and at least four or five for the mm equivalent). Pitches like 16, 20, 32, 40 TPI are exact and need no rounding.
What else changes in G20
G20 changes the units of everything in the program, not only the pitch:
- X, Z and the G76 words (P, I, J, K, E) - inches;
- feed F - inches per minute with G94, inches per revolution with G95;
- G96 surface speed S - feet per minute instead of meters per minute (more in G96 and G97);
- the G7/G8 mode still applies: in G7 X is a diameter, in G8 a radius.
Threads are always cut at constant RPM (G97), so G96 should be off before the thread anyway. Also check the units of your tool table and the G7/G8 default in your machine config - an inch program on a metric-configured machine works, but the operator has to know which numbers mean what.
Example: 3/8-16 UNC with G33
External 3/8-16 thread, 0.6 in long, G20, diameter mode G7. Depth from the chart: 0.0383 in, minor diameter 0.2983 in. Six passes with decreasing depth plus a spring pass:
G7 G18 G20 G90 G40 (diameter, XZ plane, inch, absolute)
G97 S400 M3
G0 X0.45 Z0.15 (start: D0.45, 0.15 in = 2.4 pitches off the face)
G0 X0.3437
G33 Z-0.6 K0.0625 (pass 1)
G0 X0.45
G0 Z0.15
G0 X0.3307
G33 Z-0.6 K0.0625 (pass 2)
G0 X0.45
G0 Z0.15
(... passes 3-6 at X0.3208, X0.3124, X0.3050, X0.2983)
G0 X0.2983
G33 Z-0.6 K0.0625 (spring pass)
G0 X0.45
G0 Z1
M5
M30
16 TPI is an exact pitch, so K0.0625 needs no more decimals. Z speed at S400 is 400 / 16 = 25 in/min.
Example: the same thread with G76
G8 G18 G20 G90 G40 (radius, XZ plane, inch, absolute)
G97 S400 M3
G0 X0.225 Z0.15 (drive line: radius 0.225 = D0.45)
G76 P0.0625 Z-0.6 I-0.0375 J0.006 K0.0383 R2 Q29.5 H1 E0.06 L2
G0 X0.5 Z1
M5
M30
The thread peak is at radius 0.1875 (Ø0.375): I-0.0375 below the drive line, negative for an external thread. All G76 words are explained in CNC lathe threading in LinuxCNC: G33 and G76.
Both examples are for learning: check the G7/G8 mode, zero and tool offset on your machine, and run a new thread program “cutting air” first.
Common mistakes
- No G20. K0.0625 read as millimeters is a 0.06 mm pitch - the tool scratches a fine spiral instead of a thread.
- A rounded pitch. K0.0769 instead of 0.076923 - the error grows with the length of the thread.
- TPI typed as the pitch. K16 means 16 inches per revolution: the Z axis tries to move 16 inches every turn.
- Feeds left in mm/min. F100 in G20 is 100 in/min - 2.5 m/min.
- G96 values from a metric program. S150 in G20 is 150 ft/min, about 46 m/min - a completely different spindle speed.
- G7/G8 mix-up. The depth comes out half or twice what it should be.
Inch mode in Turn G-code
Turn G-code has one mm / inch switch for all 12 cycles. In inch mode the form works in inches, and the program starts with G20 and outputs every value in inches - no hand conversion. The Threading cycle splits the depth across the roughing and finishing passes you set, adds run-in and run-out, and shows every pass in the 2D simulator; the code uses G33 or G32 with the pitch letter K, I or F, to match your control.
Try the inch mode in the free online G-code generator (OD turning, no sign-up), or download Turn G-code - 15 days free, no key needed.
