January 12, 2014

3D Printer Motor Control - Part 1

So I've been moving forward with my 3D printer plans slowly but surely. I've mainly been focusing on the drive axes up to this point, more specifically the details of controlling the motor. As outlined in my 3D printer post, I am planning on using closed loop position control with brushless DC (BLDC) motors, rather than the standard open loop control with stepper motors.

My first thought was to simply replace a stepper motor in the typical belt drive assembly with a BLDC motor and then add an encoder... somewhere. I never decided where to put the encoder because it wasn't long before I realized that that particular approach wouldn't work too well, at least without its fair share of software complications. One of the specs on every BLDC is the number of poles, or pole-pairs (there are always twice as many poles and there are pole-pairs). While not exactly the same, [number of poles] x 3 (or [number of pole-pairs] x 6) can be considered to be the equivalent of the number of steps per revolution in a stepper motor. The problem is that the number of poles on a BLDC is quite small in comparison to a stepper motor, so driving an axis directly wouldn't have the required positioning accuracy, at least not with a much more complicated motor control software. (The robotics industry has figured it out and use it all the time. It's roughly the equivalent of micro-stepping, I think...)

I thought through a few other design ideas all centered around some kind of speed reduction (gears, pulleys, threaded shafts) which has the advantage of increasing the effective number of steps in a revolution by the same factor that speed is reduced by. For example, an 8:1 gear reduction means that for every 8 revolutions on the input shaft (motor end), there is 1 revolution on the output shaft (connected to the drive axis). The speed is reduced by 8 while the effective [number of poles] x 3, or "steps per revolution" is multiplied by 8. Eventually, I landed on this design for one of the drive axes. It uses a 14 pole "medium speed" motor (1200kv), a 8:1 gear reduction from the motor to drive shaft (yellow and green features), and a 10 threads per inch shaft for even further speed reduction (torque multiplication). All in all this would give 80 motor revolutions per inch of travel, plenty (overkill?) of positioning accuracy without the need for any micro-stepping.

But I still had two problems. One, to get good low speed torque and accurate positioning out of a BLDC motor it really should be a sensored motor, meaning it has 3 hall effect sensors in the motor aligned so that as the magnets of the motor rotate the sensors will tell the controller when to turn on or off each of the three phases in the motor. (See the first 4 pages of this application note for a good explanation of BLDC commutation). The problem I had here is that the only sensored motors I could find were either far too few poles or way too expensive. One possible remedy to this problem, I thought, was to use the signal from the encoder to commutate the motor, thus negating the need for a sensored motor. The other problem was that I underestimated the price of quality encoders--the cheapest ones I found of acceptable quality were $40 and ENORMOUS (see that big black bulk in the image above?), smaller packaged encoders were in the $80+ range. It was almost enough to drive me back in the direction of stepper motors.

But one day as I was discussing the matter with a friend at work it dawned on me: it should be possible to design a small (cheap) circuit board that mounts to the motor and adds sensors to an otherwise sensorless BLDC motor. I did some research and found that other people have similarly hacked their motors and so I drew up a quick PCB to fit my motor. As I was going through that process I had a second epiphany: I should be able to use the sensors on the motor in a similar way as an encoder to get position feedback! It would be a much coarser encoder than I was planning on, but if I had a properly geared drive system so that I didn't need "micro-stepping" than I was never going to use that extra encoder resolution anyway.

I finished designing the PCB, which was small enough that it only cost a few dollars, and added high quality hall effect sensors. The end result was something around $6 for a sensored hack to my motor, and it worked perfectly (see here for the details of the design process). The downside to these sensors is that they will only work with a specific motor.

 After some further design work, I came to the conclusion that if my motor had enough torque, enough poles, and I used a high enough threads per inch threaded rod for the drive shaft, I could do direct drive from the motor to the shaft, greatly simplifying the design of the drive system. My newest design uses a much slower/torque-ier 22 pole motor (390kv) with added hall sensors, no encoder (66 counts per revolution provided by hall sensors), and a 1/4"-16 ACME threaded rod. This setup gives me slightly better than 0.001" [0.025mm] positioning accuracy along the direction of the axis (assuming everything else about the structure is perfect). I also upgraded the linear bearings to be sturdier and more readily available.

Another aspect that I'm happy with on this design is that being direct drive I eliminate some concerns I was having about backlash in my gear system. That is, if the gears don't perfectly mesh then whenever the direction of rotation reverses there's some "dead space" where the motor is turning (and reading position changes) but the drive shaft isn't actually doing anything. In practice all gears have some amount of backlash. There's ways of dealing with it in "zero backlash" which are actually two gears loaded under a spring to take up the backlash, but those are expensive and hard to come by. But with direct drive I don't have to deal with any of that.

Also, with this design the motor sits prominently up on top of the axis, visible for all to see. This is further accentuated by the fact that the motor is an outrunner, meaning the part that rotates is the outer most diameter of the motor, which will look pretty cool watch.


  1. Damn. You do good work. Can't wait until you finish the printer.

    1. Appreciate the good vibes. Custom motor driver circuit boards are in the works.

  2. Well, I am afraid that your controller will have difficulty to control the motor at current setting. This is because that the system will take the pulse and direction signals as its input. It has to rotate one "step" whenever get one pulse at the direction indicated by the direction signal. In your design, one "step" equals to one "count" of the encoder on the motor. This will be a tough job for the closed loop controller to make the motor move precisely just one unit of the resolution without overshoot or undershoot (i.e. no oscillation) . Tp resolve the issue. it is necessary to give some "room" to the controller. For example, for each input pulse, the motor rotates 10 encoder counts in desired direction to move corresponding axis with one unit of positioning resolution (e.g. 10um)...

    1. I think I understand where you're coming from, and it's quite possibly a true statement (not entirely convinced, but I don't have that experience yet). With the most recent design above, the 0.001" positioning tolerance is a theoretical best case. But even if I only got 0.005" positioning accuracy I'll still be happy.

      Another thing to keep in mind is that classical control systems have been used on brushed DC motors for ages where you only have 2 or 3 "steps" per revolution, and no special effort is required to deal with the space when the magnets are between windings. They're usually used in conjunction with a gearbox which helps on the positioning accuracy, but basic principles remain unchanged from my design.

  3. At present, in the world we have seen various types of 3D printing strategies; the fundamental procedure is comparatively consistent from one to consequent. In additive manufacturing, three-dimensional objects are created from a material in either liquid or particle type. I see that you describe very clearly about 3D printing and 3D printing materials. Thanks for sharing such kind of nice and wonderful collection
    3D printer manufacturers

  4. I am very enjoyed for this blog. I feel strongly about it and love very important information. The idea of a homemade manufacturer is admittedly returning to the forefront. Like the manner the net leveled the taking part in the sphere, resolution the challenges of reach and sanctioning everybody to play, that’s what's happening with producing nowadays. Thanks for sharing

    3D printer and printers