Lathe G-codes

The FluidBoard brings your lathe up to the level of industrial controllers. Threading, constant surface speed, feed per revolution, and diameter programming — all built in. These are the features that separate a real CNC lathe from a stepper-driven spindle with some G-code support.

All threading and synchronization features require a spindle encoder.

Threading

Single-pass threading (G33)

Cuts one synchronized threading pass. The axis moves in rigid lockstep with the spindle — if the spindle speeds up, the axis speeds up with it.

G33 Z-30 K1.5     ; Cut to Z-30 with 1.5mm pitch
  • K = thread pitch in mm per revolution
  • Motion is rigidly synchronized to the spindle encoder
  • Feed override is disabled during the cut
  • The controller waits until the spindle reaches the start of the next revolution before it starts the pass, so every pass begins at the same angle. It works this out from the encoder count; an index pulse is not required

Multi-pass threading cycle (G76)

An automated cycle that handles depth progression, compound infeed, and spring passes — the same workflow used on industrial lathes.

G76 P1.5 Z-30 J0.3 K0.92 Q29.5 H2 R1
Parameter Meaning
P Thread pitch (mm/rev)
Z Thread end position
J First cut depth
K Full thread depth
I Taper amount (0 for straight threads)
Q Compound infeed angle (29.5° for metric)
H Number of spring passes at final depth
R Degression: 1 = constant chip area, 2+ = constant depth

Each pass automatically: rapids to the next depth, cuts synchronized to Z end, retracts, and returns. The cycle repeats until full depth, then runs spring passes for a clean finish.

The K value in the example is not arbitrary: 0.92 mm is the full depth of an M-thread with 1.5 mm pitch (see below).

Thread depth and infeed

For ISO metric 60° threads, these approximations are what most machinists work from:

Thread Depth (per side) Example: 1.5 mm pitch
External 0.6134 × pitch 0.92 mm, so 1.84 mm on diameter
Internal 0.5413 × pitch 0.81 mm; bore to nominal − 1.0825 × pitch first

Turn the blank for an external thread a little under nominal (typically 0.1–0.2 mm on diameter) so the crests don't end up sharp. Always check the result with a ring gauge or the mating nut; the formulas give you the depth to aim for, not a guarantee.

There are two ways to feed in between passes:

  • Radial infeed — the tool goes straight in along X. Both cutting edges cut at the same time. Simple, and fine for fine pitches, but on coarser pitches the chip from both flanks collides and you get chatter and torn flanks.
  • Flank (compound) infeed — the tool also moves sideways by the flank angle on every pass, so mainly the leading edge cuts and the chip leaves cleanly. This is what Q29.5 in G76 does: slightly less than the 30° half-angle, so the trailing edge takes a light shave and leaves a clean flank.

Whichever you use, the depth per pass should get smaller as you go deeper, because the tool engages more of its edge on every pass. That is what the R (degression) parameter of G76 is for. Finish with one or two spring passes at full depth: the tool and work spring back under load, and a pass without extra infeed removes what is left.

Before you cut your first thread

  • Check the axis speed. During threading, Z moves at pitch × RPM. A 1.5 mm pitch at 1,000 RPM means 1,500 mm/min, and the axis has to get up to that speed in step with the spindle. Keep this well below your Z axis maximum rate, and start slow (a few hundred RPM).
  • Start before the part. Begin the pass a few pitches clear of the stock in Z, so the axis is up to speed before the tool enters the material.
  • Give the thread somewhere to end. At the end of the pass the tool is still at depth. Cut a relief groove where the thread ends, or end the thread in air.
  • Keep the start position identical. Every pass must start from the same Z, unless you deliberately shift it for flank infeed. A different start Z means a groove in a different place.
  • Set the tool on centre height and square to the work with a thread gauge (fishtail). A tilted tool cuts an asymmetric thread.

Example: M20×1.5 with G33

This is an example to adapt, not a ready-to-run program. It cuts an external M20×1.5 thread, 30 mm long, ending in a relief groove at Z-30, using radial infeed in diameter mode. Depth per pass goes from 0.25 mm down to 0.04 mm, with one spring pass at the end.

; EXAMPLE - M20x1.5 external thread, adapt before use
G21 G18 G7 G90       ; metric, ZX plane, diameter mode, absolute
T3 M6                ; threading tool and its offsets (radius 0 in the tool table)
S400 M3              ; 400 RPM x 1.5 mm = 600 mm/min in Z
G4 P2                ; give the spindle time to reach speed
G0 X22 Z4.5          ; clear of the part, 3 pitches before the start

G0 X19.50            ; pass 1  (0.25 mm deep)
G33 Z-30 K1.5
G0 X22
G0 Z4.5

G0 X19.10            ; pass 2  (0.45)
G33 Z-30 K1.5
G0 X22
G0 Z4.5

G0 X18.80            ; pass 3  (0.60)
G33 Z-30 K1.5
G0 X22
G0 Z4.5

G0 X18.56            ; pass 4  (0.72)
G33 Z-30 K1.5
G0 X22
G0 Z4.5

G0 X18.36            ; pass 5  (0.82)
G33 Z-30 K1.5
G0 X22
G0 Z4.5

G0 X18.24            ; pass 6  (0.88)
G33 Z-30 K1.5
G0 X22
G0 Z4.5

G0 X18.16            ; pass 7  (0.92, full depth)
G33 Z-30 K1.5
G0 X22
G0 Z4.5

G0 X18.16            ; spring pass, same depth
G33 Z-30 K1.5
G0 X22
G0 Z4.5

M5

Try the nut after pass 6. If it doesn't fit after the spring pass, add another pass of 0.02–0.04 mm on diameter and try again.

To turn this into flank infeed, move the start Z of each pass toward the chuck by 0.57 × the depth reached so far (tan 29.5° ≈ 0.57). For pass 1 that means starting at Z4.36 instead of Z4.5. Because every pass waits for the same spindle angle, that shift puts the tool against one flank of the existing groove. For anything beyond a handful of passes, G76 does this bookkeeping for you.

Constant surface speed (G96 / G97)

When turning a face or taper, the cutting diameter changes — and with it the surface speed at the tool tip. G96 keeps the surface speed constant by automatically adjusting RPM as you cut toward or away from center.

G96 S150           ; 150 m/min surface speed
G50 S3000          ; Cap RPM at 3000 (safety limit near center)
G95                ; F below is mm/rev
G1 X0 F0.1         ; Face cut — RPM increases as X approaches center
G97                 ; Back to constant RPM mode

Consistent surface speed means consistent chip load, better surface finish, and longer tool life. Every real lathe controller has this.

CSS calculates RPM from the X position, so X0 has to be the spindle centreline. If your X zero is somewhere else, the controller computes the wrong diameter and the wrong speed. Touch off your tools on a measured diameter (see tool table) so X0 really is the centre.

Always set G50 before G96. Near the centre the calculated speed goes up very quickly, and G50 is the only thing between the formula and your chuck's maximum RPM. Set it no higher than the chuck's rating, and lower for large or unbalanced work.

Configuration

Add this to your machine YAML:

css_axis: X         # Which axis is the cutting radius (X for lathes)

Feed per revolution (G95)

In standard mode (G94), feed rate is in mm/min. In G95 mode, feed rate is in mm per spindle revolution. The chip load stays constant regardless of RPM — which is how machinists actually think about lathe cutting.

G95                 ; Feed per revolution mode
G1 Z-50 F0.15      ; 0.15 mm per revolution
G94                 ; Back to feed per minute

Feed override is still available in G95 mode.

Diameter mode (G7 / G8)

On most lathe controllers, X values represent diameter, not radius. G7 enables this convention:

G7                  ; Diameter mode — X20 means 20mm diameter (10mm radius)
G8                  ; Radius mode — X20 means 20mm radius (default)

This means standard lathe G-code and post-processors work without modification.

Quick reference

G-code What it does
G33 Single-pass synchronized threading
G76 Multi-pass threading canned cycle
G96 Constant surface speed (S in m/min)
G97 Constant RPM mode (default)
G50 S# Max RPM limit for CSS
G95 Feed per revolution
G94 Feed per minute (default)
G7 Diameter programming mode
G8 Radius programming mode (default)

Troubleshooting threads

Symptom Likely cause Fix
Every pass cuts a new groove Encoder slipping on its coupling or belt, or start Z changed between passes Fix the encoder mounting; keep start Z identical
Pitch is consistently wrong cpr or gear_ratio wrong in the encoder config Check PPR × 4 and the ratio between spindle and encoder
Z axis stalls or loses steps during the pass Pitch × RPM too fast, or too little run-up before the part Lower RPM, start further away in Z
Spindle speed alarm while threading Passes too heavy, spindle slows under load Lighter passes; see tolerance and allowed_errors on the encoder page
Chatter, torn flanks Radial infeed on a coarse pitch, or passes too deep Use flank infeed (G76 with Q), more passes
Nut doesn't fit after full depth Blank oversize, tool worn or not at centre height Check blank diameter and tool height; add a light pass

Next steps

Set up your tool table to manage multiple tools, or learn about cutter radius compensation to program part geometry directly.

Related: spindle encoder, converting a manual lathe, external stepper drivers for axes that can keep up.

Copyright (c) 2024 by NubiloSoft, all rights reserved.
Accepted payment methods