If you just want the answer then here it is
The code is broken for 8 bit controllers trying to use RPM mode. PWM255 and PERCENT work.
In the code in the src file there is a line in class SpindleLaser that reads
return unitPower ? round(100 * (cpwr - SPEED_POWER_FLOOR) / (SPEED_POWER_MAX - SPEED_POWER_FLOOR)) : 0;
I tracked down a Github Marlin fix… one word added… float…
return unitPower ? round(100 * float(cpwr - SPEED_POWER_FLOOR) / (SPEED_POWER_MAX - SPEED_POWER_FLOOR)) : 0;
Make that change and you can set spindle speed from 0 to 50000 and get proper PWM output on Pin 4 (on RAMPS) which is the SECOND set of servo pins on the board.
How I got there…
Total newbie here, just finished my MPCNC, RAMPS controller, dual endstops. Got it built, working, cutting, but was MANUALLY controlling the spindle…
Spindle speed control was my biggest hurdle of this project I think…First trying to figure out what pin was the PWM pin took me forever… Eventually figured out that the second servo set of pins does this on the RAMPS board.
Still didn’t work… was missing something…
Once I found that I learned you have to modify the Marlin firmware to turn on the spindle control
#define SPINDLE_FEATURE
Had to uncomment this in Configuration_adv.h to ENABLE spindle control
And unfortunately while I was there I saw the options for spindle control… PWM255 (0-255 values for PWM); PERCENT (0-100 percent for PWM); RPM (0-50000RPM) and PWM255 is the default
I thought “hey, I want RPM not PWM255” which was another define right there in the code.
THATS WHERE I SHOT THE HOLE IN MY FOOT!!!
The code is broken…
PWM255 mode works
PERCENT mode works
RPM mode is broken (if you are using an 8 bit controller like a mega2560 used on the RAMPS configuration like I was…)
I beat myself up for a long time on this before I even realized that PWM255 and PERCENT worked…
So I went with PWM255 and edited my ESTLCAM tools to set RPM to 255… (or whatever was approrpiate between 0 and 255)
But it bugged me so I went after it again today…
Thats when I found some github commits on the Marlin site… I figured the issue I was having was that I grabbed the code from V1Engineering that was customized for dual endstops etc… that fix wasn’t in there…
So I downloaded Marlin direct from github… same RPM issue… Huh?
Well in addition to being a newbie to MPCNC I am also pretty newbie to github so I didn’t know where to go from there other than back to the Marlin I downloaded from V1Engineering and just add the fix directly into my copy of the source…
Then I stumbled onto the V1Engineering forum and this topic… so I figured maybe this post will help someone else get back many hours of their life that I never will.