Welcome! Log In Create A New Profile


RAMPSSB: Closed Loop DC servo drivers for RAMPS

Posted by SZiv 
RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 17, 2017 04:30PM
Hey everyone!

So I've had it up and "finished" for a while now, but I figure I should probably get some feedback from the reprappers.

I've seen quite a few people working on "closed loop" 3D printer controllers, but most of them were never published, or had some really obscure BOM, and I had yet to find a sort of black box step/direction/enable --> closed loop quadrature DC motor controller available for purchase for a reasonable cost. I only use Cartesian ramps, so the DC servo motors would only be on the X and Y axes, and the Z and E axes can stay steppers, because there's really no reason to change that. So I made this board, which is an expansion board that slots over the X and Y stepper sockets on a RAMPS board and turns them into DC encoder motors. It can also be used with other systems as a 2-channel blackbox converter by just attaching the 5V, GND, STP, DIR, EN, Power and Enstop pins.

I used two Arduino Pro Micros as the processors, and stacked a L298N DC motor driver on top of the board as a driver. other than those two parts, its just the PCB, pin header, and the rest is optional. everything can be bought for about 20 bucks + the cost of the board, which is cheap from seeedstudio, but best bought in bulk

The final product is really bulky, and the firmware needs some work, but seems to behave correctly, and the hardware doesn't seem to have any issue. On the RAMPS side, this expansion board is treated just like a stepper motor.

More information and building instructions on the wiki: reprap.org/wiki/RAMPSSB
Source code and firmware on the Github: [github.com]

Does anyone here that knows more about control theory than I have any input or ideas on how I can make this system (specifically the firmware) better? Any suggestions?
Re: RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 17, 2017 11:55PM
IMHO, on a well built and dialed in printer the extruder motor is the weakest link. Even worse, when you beef up the X and Y axis to make people think, they can print faster then. sad smiley
As long as the closed loop-algorhythm hasn't found a way into printer firmware it wouldn't make sense to use an external closed loop driver for extruders.
Re: RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 18, 2017 10:00AM
Cool solution. I agree with o_lampe -I think 'killer app' for the servo motor application would be extruder. Servo equipped extruder would allow for lighter effector/gantry and/or quicker retraction speeds. Even more interesting would be to track movement of the filament itself, not the motor, to eliminate elasticity/slip errors when feeding filament. Overall, I think we need a single servo version of the add-on, perhaps in pololu footprint so it's universal smiling smiley

Btw, do you move the motor every step received, aggregate x steps before movement or fit movement into time slots?

Edited 1 time(s). Last edit at 11/18/2017 10:10AM by newbob.
Re: RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 18, 2017 10:10AM
I was originally thinking of doing something for the extruder, but figured I would tackle the x and y first.

I hear you on the single. I've been thinking of doing a smaller one for single channel use.

My thought for an extruder is a DC gearmotor, but attaching the encoder to the filament. I'll see what I can whip up. Anything else that would be cool to see?
Re: RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 18, 2017 11:27PM
Is it really necessary to use two arduino Pro micros to control two dc-motors? How many I/O pins do you need for each encoder?
Is there an alternative for the L298N?
Re: RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 18, 2017 11:39PM
The killer isn't the IO pins, it's the number of Interrupts required and the processor speed.

Working at these speeds requires an interrupt on the Encoder channel 1 and channel 2 lines, the endstop, the step pin and maybe the direction pin. That's 5 interrupts, and the Pro Micro is the cheapest decent processor I can find (~$5) that has 4 interrupts. In theory I could go with a more expensive processor (like a Teensy) that can handle both channels, with all the inturrupts required, but why spend $30 for a processor when you can just buy 2 for $10 that get the job done. I've been using a 2000RPM 24V DC motor with a 2000 ct/rev encoder on it, and it hiccups a little bit at that speed with that many inturrupts, but with most simple 100 ct/rev motors it does just fine.

Same deal with the L298N. It's nice because it's mass produced to the point that it's dirt cheap and it works. Its a bit on the large side, but it can pump out 2 amps per channel, and I don't really see a reason to not use it.

It's also worth noting that I am going to see if I can crush the RAMPSSB down into a square the size of an L298N and make it a single channel version. I've got the board fired up, and hopefully I'll have that out in a bit.
Re: RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 19, 2017 01:01AM
Alright, done!

I smashed everything in the RAMPSSB into a small single channel board (StepServo) that fits under a L298N driver board and takes inputs from jumper wires. Seems kind of basic, but everything is there. The firmware is identical.

Github is here: [github.com]
Still have to do the Wiki

I've got parts on order to see if I can make a DC motor extruder with it. Stay tuned.
Re: RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 19, 2017 06:36AM
Why do you need an interupt on the endstop pin? The firmware takes care of the endstop and stops firing step pulses when hit. Adding a second control loop is redundant.
IMHO,the dir pin doesn't require an interupt neither.
Am I wrong?
Re: RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 19, 2017 06:43AM
ESP32 has two cores, can have one interrupt per core (I'm not sure if Arduino supports it) and costs $7:


I think a benefit of using single processor would be keeping relative movement of XY in sync.
Re: RAMPSSB: Closed Loop DC servo drivers for RAMPS
November 19, 2017 10:49AM

It's partly due to the coding method I use for the firmware. It needs to know where "0" is, in order to reset the encoder ticks to a known zero point. With some cleverer coding than what i'm doing, it may be be possible to do without the inturrupt on the endstop.


The Dir pin doesn't require an an endstop but it helps. The issue is that still puts us at 3 interrupts, which is above most ATMEGA328ps.


Good call. Never occurred to me to use the ESP32 series. I figured anything with processor speeds that high would be out of budget, but it looks like you can get something nodeMCU-like for about 10 dollars, which isn't that bad at all.

You also make a good point about syncing. I thought about that, but I'm not sure if the RAMPS board does any syncing, or how it outputs it's step signals.

I've got a ESP32 on order to mess with. I'd say best case scenario it may be able to do both channels, and worst case scenario, its only 2 dollars more for a lot more processing speed, so it will definitely be able to destroy one channel and clean up these hiccups I'm having.
Sorry, only registered users may post in this forum.

Click here to login