GRBL’s PWM functionality – How to control a laser or variable speed spindle.

As of Version 0.9, GRBL supports PWM for controlling variable spindles and lasers. (Both our Arduino CNC shield(V3.10+) and Raspberry Pi CNC Boards support the PWM functionality. )

To use the functionality there are two parts to look at. The first part is the way GRBL firmware is set up when compiled. Luckily most of it will work out of the box.

For advanced users the following might be helpful:

  • #define VARIABLE_SPINDLE // This enables PWM spindle Control. Remove to disable PWM.
  • #define SPINDLE_MAX_RPM 1000.0 // Max spindle RPM. This value is equal to 100% duty cycle on the PWM.
  • #define SPINDLE_MIN_RPM 0.0    // Min spindle RPM. This value is equal to (1/256) duty cycle on the PWM.
  • // #define MINIMUM_SPINDLE_PWM 5 // Default disabled. Uncomment to enable. Integer (0-255)

The second part is where the real G-Code commands are used. Below is a list of G-Code commands and what they do:

  • S command
    • Sets the Spindle speed.(0-1000 with default build)
  • M3 Command
    • Sets Spindle Pin to the PWM rate as specified by the S command. (Clockwise)
    • Sets Spindle Direction pin High
  • M4 Command
    • Sets Spindle Pin to the PWM rate as specified by the S command.(Counter Clockwise)
    • Sets Spindle Direction pin Low
  • M5 Command
    • Sets Spindle pin Low. (PWM 0)
    • Keeps the Direction Pin as is.
  • M7 / M8 Command
    • Sets the Coolant pin High.
  • M9 Command
    • Sets the Coolant pin Low.

G-Code Examples

The following examples are from the standard GRBL V0.9i build.

Set the spindle to full speed and switch it off after 5 seconds.

Set the spindle to 50% speed and switch it off after 5 seconds.

This example will do the following:

  • Move the machine to X0 and Z0.
  • Switch on the spindle.
  • Move Z down into the material.(Milling bit)
  • Move side ways on the axis.
  • Move Z out of the material.
  • Switch off the spindle.

That should do it for now. Please add comments below if you have questions or suggestions.

Probe can be tested with the following commands:

 

 

  1. And how to control laser ? Use m7/m8 and m9 commands? I.e. Turn laser instead of cooler, or together with it?

  2. hi, How to add a cooling cycle for a long project like work for 30 rest for 20mn and continue until end of project?

  3. Pingback: K40 eBay Chinese CO2 Laser Cutter – Flashing the Arduino UNO with GRBL Part 2! – DIY 3D Tech