Closed-loop DC motor to act as a stepper motor

One of the things that I hate the most about 3D printing is that these machines are usually working in open loop and, sometimes, a tiny error happens that ruins a long print. Most 3D printers use one or more stepper motors to move each axis. Steppers are a good solution to the problem, they are easy to control and have lots of torque (compared to similar sized DC motors) but they may skip a step occasionally. The problem then is the print head is no longer where it is supposed to be but slightly off. From there on the print is misaligned and most likely will be useless.

Any type of motor can be equipped with an encoder to check its location at any time. However that adds an additional cost to the equipment and requires extra software to handle this new information.

One idea that has been mentioned many times in RepRap forums is that if steppers were replaced by DC motors with encoders that will allow the accurate position control that offer the steppers, the machines could be made more reliable and, perhaps, cheaper. However, it is difficult to beat the simplicity and elegance of a stepper-based bot and this idea has not gone further that some tests. (Actually, DC motors were used early on by RepRap machines and replaced by steppers for the extruder but only with an on-off control and not closed-loop).

Only recently, it seems a commercial manufacturer (that is not to be mentioned here) started using a closed-loop system for their extruder motor with the idea of providing a better output quality.

I was curious about this same idea, but given that steppers can be bought for $10 each and the driver electronics for a couple of bucks now, it was unclear whether a closed-loop around a DC motor with encoder could be built cheaply enough. After seeing an ad on Aliexpress I bought five DC motors with encoder to give the idea a go.

In order to control a [brushed] DC motor you need an H-bridge electronics and a micro-controller that will perform the control logic, including a PID control loop. Given that I was planning to replace steppers, the first test seemed to create such a system that could replace one stepper and do the test on a working 3D printer before going further.

Unfortunately, the motor driver I selected, a $1 L9110S off eBay, caught fire while trying to adjust the PID loop gain. This chip does not have a thermal shutdown circuit and the capacitor they put at the output will cause the chip to destroy itself if polarity is changed fast enough (as when your motor oscillates around the set point when you have an unstable control loop).  Next driver was $2 L298 and this one is working nicely with the small motor I use.


This motor I am using is likely not well suited for driving the axis of a 3D printer unless it is geared down a bit, but it is cheaper than a stepper and it includes the encoder (though I had to create a hood to cover it). The L298 is a dual H-bridge chip, so it could be used to control two motors. But my initial idea is to just have one motor per Arduino board, as this way I can use the two external interrupt pins, one for one of the encoder inputs and the other for the step input. The software is to be interfaced to a regular 3D printer controller by means of the STEP and DIR[ection] pins like a regular stepper driver.  For the moment I am not supporting the ENA[ble] pin but that would be easy to do if needed. The software includes a PID loop that tries the motor location to be always at the desired location (that will be changed by the action of the STEP and DIR pins above). Besides, the software is reporting the current location and target each second through the serial port. It also allows a new target location to be set through the serial port. Do not use any end of line marker for that, just the plain integer number of the new location.

I have created this software by merging several pieces found on the net, like the servostrap project, the Arduino PID and Autotune PID libraries (though I failed to make the latter work properly). 

Next step is to gear down the motor to use it on the x-axis of my Prusa i3. But that will take a still a while. Though I have found this other motor with a built-in driver and encoder that might be a better, higher-power motor.

Other people are using a faster processor to do the whole printer out of DC motors. It is amazing how cheap 32bits processors have become :-)

This is my first print using this contraption on the x-axis of my home Prusa i3:


I had to create this part for the mechanical attachment.


Comments

Ivan said…
Hi Miguel, thank you for sharing.
misan said…
You're welcome.
Anonymous said…
What quadrature encoder are you using?
misan said…
The one that the motor came with: It's a 448 line encoder disk. It provides two signals in quadrature.
Anonymous said…
will it be better to use the 888 lines encoder disk?
misan said…
I am afraid the 888 line value is a type the vendors kept spreading. In theory the more lines the better resolution, so to answer your question: yes, it will be better (buy be warned you may be lied to).
misan said…
This comment has been removed by the author.
misan said…
I am afraid the 888 line value is a typo the vendors kept spreading. In theory the more lines the better resolution, so to answer your question: yes, it will be better (buy be warned you may be lied to).
Unknown said…
I made a simulation with isis but it doesn't work correctly the DC motor keep running in the same
direction
misan said…
Then just swap the two signals from the encoder.

Popular posts from this blog

VFD control with Arduino using RS485 link

How to get sinusoidal s-curve for a stepper motor

Stepper motor step signal timing calculation