Motor controller design question

Something I’ve wondered about design of things like the ODrive controller. For context, I’m a software engineer and know very little about EE / circuit design.

As I understand it, the ODrive has a little microcontroller that runs the firmware and controls the power transistors. In principle it seems like you could run this control program (the firmware) on a general purpose computer (assuming it had a suitably real-time OS), with something like GPIO for encoder input / power transistor control.

I assume there’s reasons we don’t do this, but I’m curious why? I could imagine at least the current arrangement might simplifying wiring.

1 Like

Hi @ahupp :slight_smile:

You’re quite right, there is no /fundamental/ reason that a motor drive cannot be implemented in pure software on some general purpose computer. The main reason we use microcontrollers, as you guessed, is real-time performance, particularly in terms of low-latency (the time it takes to react to an input, usually measured in nanoseconds) and determinism (aka “jitter”): i.e. the standard deviation of the time it might take to execute a given piece of code, given interrupts and other factors.

High-throughput general purpose desktop CPUs like x86 are utterly horrendous for latency, because of their heavy use of caching, virtual memory, branch-prediction, low-level firmware interrupts, and other “features” which mean that whatever software you write, either the OS, firmware, or hardware can screw up your timing. They might be fast in terms of throughput (but power hungry and expensive) but they are terrible for latency, and the latency is unpredictable, ie they have high jitter.

To make matters worse: Modern Intel x86 chips have a nasty thing called Intel Management Engine, which is a background OS baked into the chip that you cannot disable, which may fire interrupts in the middle of your code even if written at “kernel” level. It basically means that x86 is useless for any ‘real time’ applications.
As to why Intel ME exists: Ask the CIA. :stuck_out_tongue:

Whereas on a microcontroller like STM32, we can be certain that the assembly instructions that we compile and load will never be interrupted or preempted by anything else, so we can know for certain how long each piece of code will take to run. This is essential for a digital control system implementing PID control loops, but also it is safety-critical for any software-controlled inverter: If the software were to lock-up at any point, it could start a fire.

There’s also a second reason: An STM32F4 microcontroller as used in ODrive costs about USD$3, whereas a low end Intel chip costs $50. :stuck_out_tongue:

Third reason: Intel chips don’t really have GPIO. They are so power hungry that any spare pins are used for power supply, which can reach hundreds of amps for a high end Intel chip. So any GPIO is abstractd via PCI-express to smaller microcontrollers running their own firmware, like ODrive. :slight_smile:

That said, it’s possible that you could control FET gates and current sense ADCs from your Intel chip, but you’d be wasting GHz-capable GPIOs on kHz signals, and there’s always the possibility (and likelihood) that system-level complexity of the x86 system will come to bite you.


Towen covered most of it. The other big one: Peripherals. The STM32 chip odrive uses includes:

  • Hardware timers that can count the quadrature encoders directly (no software involvement)
  • Other Hardware timers that are specifically designed for 3-phase center-aligned PWM motor control output, with particular safety functions built-in
  • ADCs built-in that can trigger interrupts or dump directly to memory via DMA (again, no software involvement)
  • CAN peripherals built in
  • Etc.

Yes, we could run the logic very very quickly on the x86 processor, but we would have to go out and buy a hardware timer, external ADCs, and external CAN … etc. I’m not exactly sure what x86 has built-in for peripherals but I doubt it has dedicated motor control timers :slight_smile:

The good news is the next generation of embedded processors changed process nodes, so instead of the low ~ 100MHz range, we’re seeing 600 MHz in low cost. Of course you can also get more expensive Cortex-A and Cortex-R chips that are deterministic and powerful in the GHz range for $$$ (and typically fewer peripherals we’re interested in)

Thanks for the detailed explanation, makes a lot of sense. My main interest here is that in a moderately complicated system I could imagine having lots of these little embedded controllers, and it would plausibly simplify the BOM if you could have one handle everything (whether that be a little embedded device or something more substantial). But sounds like that might be more complication than its worth unless you really expanded the number of peripherals it supported as well.

Perhaps, but from a systems perspective, modularity is really important. Just like in code, you don’t want to repeat yourself by defining one big function that does lots of things that are all the same.
Also, from a reliability and safety perspective, you want to avoid common cause failures that is, a failure on one part of the system causing a problem somewhere else. If one axis’ control loop locked up, in a monolithic system it could cause all others to fail too.

Then there’s cost and BoM complexity: Imagine a 10 axis ODrive: On the GPIO map instead of having two encoder headers, you have 10. That’s 50 wires to route on the PCB just for encoders. Then there’s 10 sets of FETs to place, etc. ODrive has 24 MOSFETs for 2 axes, this would need 120. Each has to be carefully placed on the PCB. And imagine all of the power and signal wiring going to such a huge, expensive board. Not good.
Suddenly your BoM has jumped from 100 parts to 1000.
And if one of these boards goes up in smoke due to a wiring issue, you’ve blown a big hole in your budget.

That’s why ODrive V4 is actually going backwards from here: It will be a single-axis controller. That makes ODrive as a system much more modular, so that we can reduce the noisy motor wiring by placing the drive right on the back of the motor, with the only wiring being power and comms, which can both be in a bus configuration.

As I’m just now working through how to wire everything up, this is exciting change. What is the eta on v4?

1 Like

“soon” ™


Ask @madcowswe