RAMPS 1.4 Spindle Speed

I pretty much have all the electronics and hardware I need to build my MPCNC, I’m just trying to find the time to actually put it together. I got the generic 52mm brushed DC spindle, and I have an old RAMPS 1.4 board I’ll be using wit marlin, and controlling from Estlcam. It seems pretty straightforward to turn it on and off using a relay from a fan output, and maybe to set the speed arbitrarily from the 0-10V header on the PSU, but I’d also like to directly read the speed from the board.

Obviously this spindle doesn’t have its own tachometer, so I was thinking of getting one of those cheap hall effect tachs, which I’ve used on some other projects (can’t post links).

Is there any way to use that tach or some other sensor with the RAMPS to have a speed readout in Estlcam? If not then I’ll settle for just having that hall effect tach standalone, but it’d be nice to be able to set it in software.

I don’t have any practical experience in this area, but here are a few points I’ve gleamed from staying active in this forum.

  • Topics dealing with spindle speed are generally tied up with the concept of maintaining a constant RPM under varying loads. That is, some sort of feedback loop. You can find these topics in the forum by searching for “PID,” and here is one very long topic on this issue.
  • In skimming these topics, RPM is generally read from the spindle using a optical sensor like this one rather than a Hall sensor.
  • There is no pathway I know of for transmitting “arbitrary” data (like RPM) back to the g-code sender. There are very few g-code query commands, and they only provide specific data, and they must be repeatedly sent. Of course you have access to the Marlin source, so you could certainly hack this in if you have have the skills.
  • Marlin has the ability to take spindle speeds authored in your CAM software and output that data by setting a PWM pin. I don’t believe this is enabled in the V1 maintained versions of the firmware, but shouldn’t be too hard to enable.
  • If you have a bit of programming and hardware experience, you could use a WIFI enabled microcontroller and a browser or separate app to provide the two-way communication necessary to read and set RPM at a distance.

If it were me, I’d start by ignoring the variations of RPM based on load and just figure out a way to set the spindle no-load speed based on the PWM pin on the Ramps board. While the RPMs will vary somewhat under load, generally your spindle would follow the spindle speeds generated by your CAM solution.

1 Like

Yeah, I wasn’t really expecting or looking for a PID loop, I’m not quite that insane, but thanks for the link lol. I think I’ll leave this one alone then, and settle for setting up marlin to convert spindle speeds into PWM. I haven’t actually made sure that works yet, but if the PSU doesn’t like the PWM, I’ll just make a little LC circuit I’ve used to smooth out PWM for DC fans before.

I think I’ll still get the hall sensor purely for my own information though, so I can see what the thing is doing along with using my ears.

1 Like

From scanning the Marlin files, I believe all you have to do to enable support is uncomment this line in configuration_Adv.h:

//#define SPINDLE_FEATURE

I’m guessing but I think these three lines in configuration_Adv.h define the range mapped to the 256 levels of the PWM pin:

    #define SPEED_POWER_MIN            5000    // (RPM)
    #define SPEED_POWER_MAX           30000    // (RPM) SuperPID router controller 0 - 30,000 RPM
    #define SPEED_POWER_STARTUP       25000    // (RPM) M3/M4 speed/power default (with no arguments)

And you will find the pin assigments in pins_RAMPS.h in this section:

//
// M3/M4/M5 - Spindle/Laser Control
//
#if HAS_CUTTER && !defined(SPINDLE_LASER_ENA_PIN)
  #if !NUM_SERVOS                                 // Use servo connector if possible
    #define SPINDLE_LASER_ENA_PIN              4  // Pullup or pulldown!
    #define SPINDLE_LASER_PWM_PIN              6  // Hardware PWM
    #define SPINDLE_DIR_PIN                    5
  #elif HAS_FREE_AUX2_PINS
    #define SPINDLE_LASER_ENA_PIN             40  // Pullup or pulldown!
    #define SPINDLE_LASER_PWM_PIN             44  // Hardware PWM
    #define SPINDLE_DIR_PIN                   65
  #else
    #error "No auto-assignable Spindle/Laser pins available."
  #endif
#endif
2 Likes

I saw that and set it to RPM control (also taking note of Terry Jones’ marlin fix to get that working here Control spindle RPM through RAMPS). I just need to figure out what the best way is to set the maximum output to 10V, as the spindle’s controller takes 0-10V.

I’m not sure if I should be setting the maximum RPM in marlin 120% (12V/10V) higher so it interprets the controller’s maximum as lower, or if I should set marlin to the actual max and offset Estlcam’s gcode output somehow. I’m not sure if that made sense, I but can reword it lol.

1 Like

Just reading your post here.

Spindle takes 0-10V to control. RAMPS board outputs a PWM (pulse width) signal. (and its a 5V signal out of the RAMPS board) is my understanding.

I built the simple schematic that you see in the ESTLCAM Spindle settings for a PWM to 0-10V converter and it has a pot so that when you set your spindle speed to max in Marlin you get a near 100% duty cycle 5V PWM signal which should give you a 10V signal out of the PWM to 0-10V converter. Thats what the pot is for. Set Marlin speed to max, adjust pot for max spindle speed.

Unless I am totally misinterpreting your post…

I should also add that after a witch hunt for what I thought was a noise issue, I was thinking it best if I used an opto isolated PWM to 0-10V converter and I started to design one and then looked on eBay and they are $5 so I ordered one… I just wanted to keep the RAMPS power isolated from the spindle power.

2 Likes

Huh, I had no idea you could get PWM to 0-10V converters off the shelf either. I’ll add that to my options.

I was under the impression that the D4 and D6 pins at max PWM output whatever voltage the PSU outputs, so 12V in my case, and that the center row of pins on the servo headers are constant 5V. I can’t find any source for the PWM pins being 12V though, so I could very well be wrong. Regardless, I could always switch the pins to be D8 and D9 instead to get 12V for spindle on/off and speed.

In my last post, I was assuming an output of 12V at max PWM, from whatever pins are set up. Because of this, I would need to limit the PWM to a max of 10V average (could smooth with a simple LC circuit if needed). I’m wondering what is the best way to set this limit.

I figure my first option is to set the maximum RPM in marlin to 120% above the real maximum of my spindle. So if my spindle can be set to 12000 RPM at 10V, I’d set it to 14400 RPM in marlin. That way when my controller (Estlcam) and gcode ask for 12000 RPM, marlin will output (12000/14400)*12 = 10V.

Or I could just set marlin’s max to 12000 RPM and somehow offset the PWM that Estlcam writes to gcode by 10/12. I’m not sure if it can do that, I haven’t gone through the settings with a fine tooth comb yet.

Could an of-the-shelf component like this be used to control the spindle speed? The only potential issue I see is that Mega Pin 6, the default pin for spindle control for Ramps, falls a bit short of 1KHz at 976Hz…and that is not timer you would want to mess with since it handles millis() micros() and delay().

Thats is the exact off the shelf device I have ordered from ebay… It should work. I won’t know for a month!

So I am using D4 for spindle speed which is the default for a RAMPS/mega2560 combo I believe. That appears on the second set of “servo” pins on the RAMPS board, second set from the reset button. The D4 pin is used because it is specifically a PWM capable pin I believe. I haven’t tried switching to using the D8 pin. Looking at the schematic for the RAMPS board, it looks possible to use D* to get a 12V signal, BUT it would still be a PWM signal. You would still have to convert it to a DC voltage for the 0-1V input on the spindle power controller. That could probably be done by sending the signal through a resistor to a capacitor to filter it to smooth (enough) DC. It may also be possible to choose a resistor value high enough that you end up with 10V DC out of a nearly 100% duty cycle 12V PWM signal if you get what I am trying to say.

Something like this
image
With the D8 input on the left and the 0-10V output on the right. Not sure what the values might be. I may get a chance to experiment with this at some point to see.

That said, I REALLY like the idea of my spindle and my arduino being opto isolated so I will be trying the off the shelf converter like the one mentioned in @robertbu post below (above?)

I should also add that I did some fiddling with setting min max values in Marlin for the LCD controls and I got some very strange results… I think the defaults are 5000 and 30000 for LCD RPM control of spindle speed or something… Well since software can set from 0-50000 I figured that was the way to set the LCD min max. Things were not scaling right on the LCD settings…

I admit to lazy here… I don’t use LCD to set spindle speed, I use software to set it. So I said to hell with working on that. Wouldn’t surprise me that given that RPM didn’t work correctly because of a float issue in the code, the same issue may apply as soon as you set a max above 32767 or something strange like that and I just got too lazy to track that one down…

If you want it now and have a Prime account, one like it are available on Amazon for about $10.

Yeah I have prime. Call me cheap. My $5 from eBay is $5 canadian. Amazon is $14 Canadian. Mine is working fine fir now so I will be patient. It does me good to learn patience.

Big hurdle this morning. My first aluminum cutting.

Huge wohoo moment. Failed yesterday and I figured out my DRV8825 chips were overheating. Y axis stopped. Yeah I had the mill plough through 4mm cutting through the part until I could hit the reset button.

Dropped my drive voltage from above .8V to .7V and ran the same GCODE to completion this time. May add a cooling fan to the RAMPS setup as insurance.

2 Likes

So in having a discussion with someone I know, I’ve learned a few things about the RAMPS board that makes this annoying. First is that the servo pwm is actually 5V. The pwm to 0-10V DC converter would probably work fine with this. Second is that the heater headers (D8-D10) are switched ground, not switched 12v, which makes controlling the spindle difficult for reasons I still don’t perfectly understand haha.

So to overcome these things, here’s what I’ll probably try to do:

This is a combination of a pull up resistor, a voltage divider, and an RC filter. I’m a little flaky on some of the details because I don’t have the background, but I’m assured it makers sense lmao. The internal resistance of the 0-10V input on the PSU is 90k ohms, so that’s taken into account in the voltage divider, along with the pull up resistor.

Also of note is that the spindle pwm from D9 has to be inverted in marlin because it’s switched ground. I’m told that during its off cycles, it’s actually full 12v, which is not what we want when the output is ground.

“It may also be possible to choose a resistor value high enough that you end up with 10V DC”

This requires to know the exact current being drawn, V = I*R. I think I’d rather make a voltage divider that doesn’t depend on current, and is very flexible with what resistors you use. The output voltage is also perfectly proportional to the input.

“Failed yesterday and I figured out my DRV8825 chips were overheating”

Wow, do you have heatsinks on them? I’ll be using the a4988’s I have on hand, with heatsinks and a fan. That only gives me 16x microstepping, but that’s already like 0.01mm, so I don’t care much about that.

Depending on the ramps, it is actually floating when it is off. It switches between off and floating. The rambo is tied through an LED to 12V, but I think the ramps isn’t.

I get continuity between the positive terminals on the heater headers and the 12V input when the board is turned off, so at least in my case it seems to be as I described before.

I agree with that. But I just am saying the (-) side switches between floating and ground. You just may be able to use a pull up to 10V on the ground and it can switch between 10V and ground (but still be inverted).

Oh wow, I had a major brain fart, I don’t know why I tested the positive terminals when that wasn’t a question. I even stated it earlier, switching ground.

I’ll check the ground pins lol.

Don’t know if this is what you’re looking for but I found an inverter circuit I posted in this thread that worked to drive a +12v pwm signal from the fan output on the RAMPS board.

FWIW, you cant do this on a rambo. The (-) side is connected through a resistor and led to 12V.