The Lathe module enables spindle-synchronized turning operations on CNC lathes. It allows the carriage (typically Z-axis) to move in precise synchronization with the spindle rotation, enabling threading and other turning operations.
The Lathe module uses a quadrature encoder attached to the spindle to track its rotation. The carriage movement is then synchronized to the spindle position, allowing for:
The Lathe module implements the G33 command for spindle-synchronized motion:
G33 K<pitch> [Z<distance>]
| Parameter | Description |
|---|---|
K |
Distance per revolution in mm (required). Negative values reverse direction. |
Z |
Distance to travel in mm. If omitted, enters manual mode. |
G33 K1.5 Z-20 ; Thread 20mm at 1.5mm pitch
G33 K-2.0 Z15 ; Thread in reverse direction
In threading mode:
G33 K1.0 ; Start manual half-nut engagement at 1.0mm/rev
In manual mode:
A quadrature encoder must be attached to the spindle to track rotation. The encoder connects to the hardware quadrature encoder interface on the STM32H7.
| Specification | Recommended Value |
|---|---|
| Type | Incremental quadrature encoder |
| Resolution | 100-2000 PPR (pulses per revolution) |
| Output | A, B channels (and optionally Index/Z) |
| Voltage | 3.3V or 5V with level shifting |
An index pin provides a once-per-revolution reference pulse. When configured:
[lathe]
enable = true # Enable the lathe module
encoder_ppr = 1000 # Encoder pulses per revolution (after any gearing)
index_pin = PF10^ # Optional index pulse pin (use ^ for pull-up)
| Option | Description | Default |
|---|---|---|
enable |
Enable the lathe module | false |
encoder_ppr |
Encoder pulses per revolution (including any gearing ratio) | 1000 |
index_pin |
Pin for index/Z channel pulse | nc |
If your spindle has a gear ratio between the motor/encoder and the chuck:
encoder_ppr = encoder_resolution × gear_ratio
For example, with a 500 PPR encoder and 2:1 gearing (encoder turns twice per spindle revolution):
encoder_ppr = 500 × 2 = 1000
Display the current spindle RPM:
> rpm
1250.5
The RPM is calculated from the encoder pulses. If an index pin is configured and available, it provides more accurate RPM readings.
G28 Z0 ; Home Z axis
G0 X10 ; Position tool
M3 S1000 ; Start spindle at 1000 RPM
G33 K1.5 Z-25 ; Cut thread at 1.5mm pitch, 25mm length
M5 ; Stop spindle
G0 X15 Z5 ; Retract
G28 Z0
G0 X10.2 ; First pass depth
M3 S800
G33 K2.0 Z-30 ; First pass
G0 X15 Z5 ; Retract
G0 X10.0 ; Second pass depth
G33 K2.0 Z-30 ; Second pass (starts at same angular position)
G0 X15 Z5
M5
M3 S600 ; Start spindle
G33 K1.0 ; Engage electronic leadscrew
; Press Ctrl+Y to disengage
M5
The G33 command requires the spindle to be running (RPM > 0) before execution. Ensure:
If threads don’t align on multi-pass operations: