Spindle speed and M3

Has anyone tackled spindle speeds?

The post process, I see “M84 S12000”. But my spindle is controlled with PWM, 0-255, where 255 is around 12000 RPM. I could put the spindle speed in Fusion to 255, but that would mess up the feed calculations.

Is this something tackled in the Marlin firmware perhaps where I say 12,000 RPM translates to a value of 255 PWM? I have not seen anything in guffy’s post processor.

I don’t personally have a spindle, but I have a guess on how this works based on the comments in the configuration_Adv.h file. First there is this section:

   * Speed / Power can be set ('M3 S') and displayed in terms of:
   *  - PWM255  (S0 - S255)
   *  - PERCENT (S0 - S100)
   *  - RPM     (S0 - S50000)  Best for use with a spindle

This implies to me that you select one of three ways that the S parameter can be interpreted at the time you compile Marlin. The above code is pulled from the V1 maintained Rambo firmware, so in that particular version, the S parameter is expected in the range of 0 to 255. If all you have is a spindle, my guess is that you would want to change the line to:


A bit below this define, there are two other defines that may play a role in how the RPM parameter is intrepreted:

#define SPEED_POWER_MIN            5000    // (RPM)
#define SPEED_POWER_MAX           30000    // (RPM) SuperPID router controller 0 - 30,000 RPM

My guess is that Marlin uses these to map the spindle speed into the PWM value output on the pin. Any ‘S’ value below 5000 in the g-code gets mapped to 0, and any ‘S’ value a above 30000 gets mapped to 255.

That’s awesome, thanks! I got it fixed up. Not sure on the lower end speed of the 500w spindle or how it maps but I think this will do nicely :slight_smile:

There have been recent posts in the forums that @tjones99 found a bug in the RPM method. Check the Control Spindle RPM through RAMPS topic for the gory details. I don’t know whether the fix he describes has been incorporated into the Marlin codebase yet.

(edit to give credit where credit is due)

1 Like

Thanks for the plug, but can’t take credit for that, @tjones99 found and fixed it. My thread is more about the hardware of connecting the RAMPS to the spindle’s PSU.