SimpleFOC Demystifies Precision BLDC Motor Control

Brushless DC (BLDC) motors are standard fare in low-precision, speedy RC applications. The control schemes needed to run them slowly or precisely go deep into motor theory and might put these motors out of reach for your next homebrew robot project. [Antun Skuric] and crew aim to change just that. They’ve taken the field-oriented control algorithm and encapsulated it into a compact Arduino library, added a host of examples, and minted a stackable BLDC motor control shield to boot. The sum of their efforts is captured into the SimpleFOC Project in the aim of bringing precision BLDC control to a wide community of new hackers.

Field-Oriented Control is a BLDC motor control scheme that involves using a microprocessor to control the stator winding current in such a way that it always applies torque to the rotor. Doing so requires that your processor measure both motor current (think: shunt resistor) and rotor position (think: encoder). Implementing the algorithm, though, can get a bit tricky since it touches bits of linear algebra, motor physics, and control theory. But that’s the magic behind SimpleFOC. With the library at your fingertips, you don’t have to! And with that, the hardest part of brushless motor control has been made simpler with a solution that’s almost plug-in-and-play.

SimpleFOC has been implemented to extend to a variety of possible implementations. While you can certainly design your own control board, you can also start with the SimpleFOC motor shield for a single motor pulling up to 5 A of current. From there, you’ve got a pretty wide range of micros to choose from as the library has been extended to work on the Arduino, Teensy, STM32, and a few other microcontroller families. For implementation details, theory, and setup, there’s a healthy set of documentation to reference. And if you’re looking to share your project or ask questions, you can pop into the community forum for some high-fives and tips. Best of all, the source code has been offered for your enjoyment under a generous MIT License.

While the project kicked off last year, it’s undergoing continuous improvements including added support for current sensing and torque control in addition to position control. With a healthy community emerging around the project, we’ll keep our eyes peeled for more projects that build off of this fantastic reference design.

If BLDC motor control has your interest piqued, have a look through our archive for other BLDC motor control projects, including motor/controller hybrids, anti-cogging control schemes, and other low-speed position controllers. And if you’re up for a real challenge, why not 3D print the motor too?


13 thoughts on “SimpleFOC Demystifies Precision BLDC Motor Control

  1. Nice! I’ve always been interested in using brushed and brushless motors for precision applications, but never wanted to dive into all the hassle. This is the perfect solution. Thanks!

  2. Actually…. If you have an encoder you can get good speed / position control without any maths at all (If we redefine PID as arithmetic instead). Simple block commutation and closed-loop control works fine.
    I am not trying to detract from this project, more being pedantic about some of the statements in the article.
    FOC should be stiffer, though, and less dithery (technical term ;-)

    1. FOC is a special case of a vector control algorithm which forms a proper rotating magnetic field instead of simply switching the currents on and off.

      The more general version is doing the same without the assumption of permanent magnets, for example in an induction motor. The generalized algorithm first calculates a field excitation vector which is necessary to magnetize the rotor in a particular direction. It basically generates a current which flips the magnetic field back and forth along some direction. Then it calculates another vector which is 90 degrees off from the first, which is the torque generating vector, and sums the two together to figure out a resultant vector which then rotates around the motor.

      It keeps measuring the actual phase currents (or encoders) to figure out how fast the motor is actually turning, to keep the field and torque vectors aligned with reality. The magnitude of both vectors however can be arbitrary, so you don’t need to drive so much field current in the rotor when you don’t need any torque, so the efficiency is greatly improved, and any induction motor behaves like a BLDC motor. With an actual PM motor then, the calculation simplifies to the FOC algorithm because the field excitation vector just denotes where the rotor is pointing and the excitation current becomes zero. However, even with a PM motor, you can apply field excitation to -weaken- the magnetic flux, which means you can alter the effective velocity constant of the motor as needed.

      So the whole thing is basically generating sinusoidal three phase currents, and keeping a set phase advance from the motor position by the information from an encoder. From there it can operate in two ways: torque control which changes the magnitude of the torque generating vector, or voltage control which keeps giving it the full beans for whatever voltage you give the motor, so it behaves like a brushed DC motor.

  3. Controlling such a motor with an encoder isn’t all that difficult, aside from the fact that an encoder doesn’t give you any position information immediately after startup.

    The hard part is doing it without the encoder, it other shaft position sensors; it simply isn’t true that FOC requires an encoder. This is possible by observing the motor current while driving it, with an estimated rotor position and speed; the actual current together with the expected current gives an indication of the error in the position and speed estimates, allowing for constant corrections.

    In cases where the load torque doesn’t abruptly change, and the motor can start with near-zero torque from a standstill, as is the case with pumps, propellers, etc., this is a very reliable way of driving motors. Starting with full torque does usually require some kind of sensors, commonly hall sensors.

  4. I have actually had pretty bad luck using CUI capacitive encoders for servo applications. Not sure what it is but they just don’t perform as well as standard optical encoders, especially at stiffer, higher update rate tunes. I have tried them with different controllers and always end up with the same issues. Pop on an old HEDS style encoder and my issues go away. I have read that the capacitive encoders can have lag from rotation to signal out, which would make sense with the issues I get.

    Speaking of tuning, that motor in the video is really poorly tune which he kind of mentions and makes a bad example. The motor sitting there hunting after a move is a dead giveaway. Also the poor movement at slow speeds. The PID parameters need some serious tweaking.

    1. We are aware of this issue with CUI encoders in the LinuxCNC project, it has been noticed that they have a phase lag, which causes problems with closed-loop control. (I think this was proved by putting two encoders on the same shaft)

  5. Lot’s of good comments here already, so just a few more notes:

    Field Oriented Control of 3 phase BLDC motors can be Sensored or Sensorless.
    Sensored FOC designs would include Hall Sensors, or an Encoder, or MEMS sensors.
    Sensorless would depend upon proper sampling of the motor phase currents either through shunt resistor(s) or Isolated Current Sensors. To perform the Sensorless function, the motor has to be spinning at a rate fast enough to generate enough Back Electromotive Force (BEMF) to be measured and controlled. In addition, at START, there needs to be an alignment of the magnetic fields to achieve a known starting position. This can be achieved with a big slug of current for a very short amoun of time. There are other proprietary algorithms to discover the magnetic relationship when an alignment jerk of the motor is not possible or not desirable.

    Sensored FOC is of great use when the motor is moving slowly or for a movement through a precise arc. BLDC motors like to spin, so you need to go to greater lengths to get precise control over a discrete position. The Hall Sensors only give you 6 locations around the unit circle. Your algorithm must interpolate between those two points. A load change in between those two points may throw off the understanding of where the motor thinks it is. An encoder (quadrature, optical, resolver, BiSS, etc.) will give you batter resolution. Add to the encoder an INDEX spot and you’ll have an absolute sense of the motor rotation. Using MEMS accelerometer + gyro can give you excellent control as well. A great example here is managing a 3 motor, 3 axis gimbal.

    Sensored or Sensorless FOC can provide a great reduction in current draw in the motor compared to open loop control and is one of the great benefits of taking the extra time to develop the design. Another benefit is excellent response to speed or torque change requests.

    To learn more, ST Microelectronics offers a series of 5 MOOC sessions on BLDC motor control. The first in the series can be found at:

    1. You can also do sensorless by trying to apply a field excitation to the motor and observing how the current responds.

      The trick is that the neodymium magnets will saturate the iron in the stator, so it will basically have no inductance for current going one way, and lots of inductance the other way. Trying to magnetize the motor like it was an induction motor will then result in an asymmetric current waveform to a symmetric excitation, and you can scan the motor to find out where the rotor is pointing. Once that is done, you can start applying the torque vector which goes sideways to the PM field.

      At standstill, you can’t apply torque and measure the rotor position at the same time, but switching rapidly between the two allows you to drive the motor arbitrarily slow.

      1. Or, technically you can, but you always get less torque out because the torque vector has to “wobble” out of the correct angle to make the field excitation current.

  6. This all sounds great . I design and build motors and have a great design for a 50 kW motor that I will gladly share. I need a 50 kW 400 battery volt controller to.go with it…any offers. FYI it is 3 phase pm type. Very high efficiency due to use of micro chrystaline lamination.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.