Skip to content

Threading setup and use

Huub Buis edited this page Mar 24, 2024 · 25 revisions

Development:

I have added spindle sync threading (G33) to this GRBL-L-Mega version and the GRBL-L version:

  • using an index pulse to start the thread
  • using optionally synchronization pulses (spindle speed encoder pulses) to better compensate for spindle speed changes
  • using the current GRBL input pins (Y-Limit and Probe) so existing GRBL shields can be used.

The original GRBL version doesn't support threading. There are some GRBL GUI's that support threading by using a stepper for driving the spindle CNCL and grblgru. This works very well but it takes some effort to implement. There is a GRBL-Mega fork fschill grbl-Mega spindle sync that has implemented threading (G95) by using spindle speed encoder pulses to synchronize. Based on this version I have developed the grbl-L and grbl-L-Mega lathe G33 threading versions. G33, spindle sync threading, is supported by CNCL.

What you need:

Threading needs a spindle index pulse to start at the same spindle position every threading pass. A magnet on the spindle and a magnetic sensor is basically all you need. Make a holder for the sensor and mount the sensor on the bed by using 3 magnets and you can start threading.
Optionally, to compensate better for spindle speed changes during a threading pass, you need synchronization pulses. A second sensor and 4 magnets will do for synchronization pulses.

Magnet:

Use small 4..6 mm Neodym magnets. It is important that they are equally strong, so use magnets out of one batch. Position the magnets as accurately as possible. Place the magnet for the index pulse in such way, that the index pulse lays between two synchronization pulses. Beware, magnetic proximity switches are sensitive for the magnet orientation. If it doesn't work, flip the magnet and mark the side that needs to be on the outside.

Sensor:

An inductive sensor like the NJK-5002C (5 Volt version) will do. If you are using limit switches, use the same type (NO or NC) sensor because the limit pin invert setting is for all limit pins.

Connecting the sensors:

  • Connect the index pulse to the Y-limit pin.
  • Connect the synchronization pulse to the Probe pin. If you are using an Arduino Uno shield without Probe pin, use the SCL pin instead.
  • Here you find the layout of the Arduino Mega and Arduino Uno boards and the connections for a RAMPS shield.

If there are no synchronization pulses, the index pulse is also used as synchronization pulse. In that case, the probe pin should not be used.

Configuring GRBL-L(-Mega) for spindle synchronization

  • Set the number of synchronization pulses (set $40)
  • Enable hardware limits (set $21 to 1)
  • For normally open sensors (NO) set $5 to 0
  • For normally closed sensors (NC) set $5 to 1 and connect the X-limit and Z-limit pin to GND, if there are no limit switches connected to them.
  • The actual (measured) spindle speed can be reported in the real time status report instead of the spindle speed set by GRBL, by setting bit 1 in the report option ($10) add 2).
  • The spindle synchronization error can be reported in the real time status report (|SE x.xxx) by setting bit 2 in the report option ($10 add 4).
  • The spindle synchronization error can be reported as feedback message during threading at every index puls ([Se:x.xxx]) by setting bit 3 in the report option ($10 add 8).

Command examples:

Threading can be done by sending a G33 code to the GRBL-L controller. The target position and pitch (feed in units per revolution) have to be set. When $13 = 0, units are mm otherwise inches

  • G90 G33 Z-5 K1; Moves the Z-axis to absolute position Z-5 and a pitch of 1 unit per revolution.
  • G91 G33 Z-5 K0.5; Moves the Z-axis -5 units at a pitch of 0.5 units per revolution
  • G91 G33 Z-5 X-1 K1; Moves the Z-axis -5 units & the X-axis -1 units at a pitch of 1 unit per revolution. The pitch is based on the Z-X travel length!
    Full example
    G0 X1 Z0 ; go to start position
    G0 X-0.5 ; go to cutting depth, clear of workpiece
    G90 G33 Z-5 K1 ; Threading pass at a pitch of 1 unit per revolution
    G0 X1 ; retract at end of move
    G0 Z0 ; end of pass

Error messages:

There are 4 (3 new) error messages related to threading G33:

  • 18 No index pulse detected in the last 6 seconds.
  • 19 No synchronization pulse detected in the last 6 seconds.
  • 39 Invalid GCode when G33 is sent but the number of synchronization pulses is set to 0 ($40=0).
  • 40 Invalid GCode when G33 is sent but hardware limits are not enabled ($21=0)

Real time status:

The G33 synchronization error is added to the realtime status at every index pulse when bit 2 in GRBL setting $10 is set.
<Run|MPos:-2.380,0.000,-11.892|Bf:32,235|FS:25,30|Se:0.043>

Feedback message:

During G33 moves, the synchronization error is output as feedback message at every index pulse when bit 3 in GRBL setting $10 is set.
[Se:-0.012]

Build information:

Build option X1 is added to the build information so GUI's can check ($I) if G33 is supported.
[VER:1.1g.20190816.Mega:]
[OPT:VNM+X1HS,33,255]

Limitations:

  • You can't start threading at the tip of the workpiece. The Z-axis needs time to accelerate. Depending on your settings, it may take 2 to 8 synchronization pulses to start. Set the start position so that the Z-axis is at the requested speed when threading starts.
  • Don't change the spindle speed during a threading pass.
  • Don't stop during a threading pass. After the threading pass is done, you may stop and turn the spindle in any direction.
  • Run at least at 10 RPM.
  • Don't use high resolution encoders for synchronization because the Arduino Uno and Mega processors don't have enough processing power. The higher the encoder resolution, the slower the spindle has to run. In practice, I think the limit will be 8 pulses per revolution.
  • There is a limit on the maximum spindle speed you can run. The actual limit depends on the number of sync pulses per revolution, spindle speed drop during threading, max feed rate(s) Z (X), max acceleration(s) Z (X), Pitch size, etc.

Threading accuracy:

The threading accuracy is reported as feedback message and in the real time status report, depending on setting $10. Monitor the threading accuracy to see how your lathe threading setup is doing. Beware that , at the threading start and end, the synchronization error will be high due to the acceleration and deceleration of the carriage. To decrease the synchronization error:

  • Setup your spindle pulleys / gears for the highest torque.
  • Run the spindle at low speeds.
  • Take shallow cuts.
  • Use sharp cutting tools.

If all is working well, find the limits of your setup and make a note of the threading conditions, material and workpiece diameter for future use.