An Open Source 3-Phase Motor Controller

I'm interested in electric vehicles, but I'm an engineer, so I can't leave well enough alone and use an off-the-shelf motor and controller for my car. In the beginning, I modified an industrial motor drive to run the 3-phase AC induction motor. Unfortunately, most industrial drives don't have suitable control algorithms. Most run as speed controllers, while cars work better when torque is the control variable-- driving a car where the pedal controls the speed of the car, rather than the acceleration is quite interesting.
So, I've set off to design my own controller. I've started this page to document my successes and failures. None of this is new technology, but it's hard to find all the information needed in one place, especially for hobbyists. With that in mind, I'm trying to include as much information as possible, even where it might seem obvious. This information, including schematics and code, is free, subject to the standard disclaimer.
I'm using a three-step approach. First, build a shield for the popular Arduino microcontroller development platform that will control a small 3-phase motor. A "Shield" is a board that snaps on to the top of the Arduino board and has connectors for signal and power. A lot of people sniff at the Arduino platform (Hi Hackaday commenters!) because it's a beginner's tool, but really it's a great way to work out ideas. Eventually, I'll outgrow the 8-bit, 16MHz AVR processor of the Arduino and need to move to a faster processor (probably an ARM), but for now the Arduino is great.
The second step is to design a replacement for the control board in my car, while using the existing power electronics. The third step would be to design a complete inverter with control & power electronics in a nice package.

Some Theory

This section outlines briefly how 3-phase induction motors work. The controller hardware should be usable for other types of motors (3-phase brushless, and maybe switched reluctance) with a change in software, but induction motors are the cheapest, most robust, and easiest to find.
Induction motors work on the principle of a rotating magnetic field caused by exciting three sets of stator windings in the correct sequence, usually by a sinusoidal voltage with a 120 degree phase angle between each set of windings. This rotating magnetic field induces a current in a conductive rotor (usually a cylinder of aluminum or copper containing some steel laminations) if the rotor speed is not matched with the speed of the rotating magnetic field. This current interacts with the magnetic flux to generate torque.
A basic way to operate a 3-phase motor is then to make the rotating speed of the field (the synchronous speed) slightly higher than the desired operating speed of the motor. For instance, a 2-pole motor operating at 60Hz would have a synchronous speed of 3600 rpm, and most such motors have a rated speed of about 3500 rpm. This speed difference is called slip.

For our application, though, we are interested in controlling torque, not speed.
To make things a bit easier to calculate, we can say that the magnetic field ("flux" to be precise) in the stator is essentially the same as that in the rotor, and then say that the torque is proportional to the cross product of the flux with the stator current.

The flux produced by the stator windings goes like Volts*seconds (per turn of the stator coils, but those are constant). This means for a given flux, the applied voltage must increase with increasing speed. This is why most basic motor controllers work in V/Hz mode- they apply a sinusoidal voltage that is proportional to the requested speed.

There are a lot of methods out there for controlling 3-phase motors, for the basic sinusoidal PWM V/Hz control up to very sophisticated (and complicated) proprietary algorithm. For this exercise, we will use the Direct Torque Control (DTC) method. This method was independently discovered by Manfred Depenbrock and Isao Takahashi & Toshihiko Noguchi in 1984, and was commercialized by ABB. The way this works is by using the time integral of the voltage as a flux estimator, and the cross product of the stator current and the flux as a torque estimator.

In DTC, the torque can be increased by applying a voltage to the stator windings so that the angle between the flux vector and the current vector increases. The torque can be decreased be stopping or slowing the flux vector, allowing the current vector to "catch up". I'll be adding some animations about how this works. For now, here's an animation of a six-step inverter powering a delta-connected motor. The inverter is on the left, and the motor is represented by the thick triangle on the right. The red line is the stator flux vector, and the black line is the voltage vector, which depends on the state of the inverter switches.

Some hardware

I've designed an Arduino Shield using the excellent free software KiCad, and sent the boards out for a small-batch fab. I assembled the shield by hand-soldering with a soldering iron. Even though all the parts are surface-mount, this is easier than you think. Here's a speeded-up video (no sound):


And here's the assembled shield:

The linear regulator chip I ordered was a D2PAK instead of a DPAK, so I had to install it sideways to get it to fit

And here's a video of the whole thing driving an AC servo motor with the six-step algorithm:


I've set up a Google code project for this design over at:

It's still pretty rough, but it's a start.