Category Archives: Motor Controllers

Universal Motor Controller – rev 1.0

This is the front and back 3D model of the Rev 1.0 of my Universal Motor Controller. I will be leaving the non-isolated RS485 for now. I want to do some changes around the MCU layout later anyway as I actually have a lot of spare pins here, but lack space to support a com adapter. This board is 80 x 40mm and only 2-layer PCB with a lot of functionality.

Design doc is located on the Download page!

Universal Motor Controller – PSU

The HEXFET on my Universal Motor Controller is 30V, so I decided to change my existing DC-DC to 12V out and add a classing LM1117 for the 3.3V. The LMR14206 based DC-DC is basically so small that it is not much larger than LM1117 on PCB space. It is restricted to ca 800mA, but it will only drive the gate drivers, MCU and com etc so it should be sufficient.

I did find a few DC-DC converters with a different range on Voltage/Ampere, but they also use more PCB space. Jumper J5 and J11 allow 12V to be connected directly if your using 11.1V battery etc. The issue is that the Gate drivers need 10+ V to operate and as the DC-DC will drop 1-2V we might get a challenge using 11.1V LIPO batteries so I added the jumpers in case they are needed.

I would have loved to operate from 5V and up, but to do that I would need a very powerfully step-up DC-DC converter as we would feed the motors as well. It is doable, but it add to the size. We will be looking at optimizations later anyway.

This 2nd diagram is also part of the PSU and show the adapter connector as well as the P4SMA suppression diode from Vishay. This will break down around 27ich V and suppress any unwanted pulses. These diodes are life savers, but they take some time to react which is why you must add an adapter board with either a capacitor or battery. What will happen is that capacitors will take the edge of the pulse giving the suppression diode time to suppress the pulse. If you have a large capacitor or battery that will need tom be “filled up”, meaning that the diode will only react if the battery or capacitor is overrun.

If you recall my previous breakdown and discussion I concluded that a 24V motor can spike up into 20x (480V). The HEXFET’s will basically short those spikes and might be feeding them into the PSU part. A capacitor/battery can charge that energy, but we have a suppression diodes around to prevent that these spikes do damage. The basic adapter Board is only a specialzed vero Board to allow mounting of hole-through capacitors.

Universal Motor Controller

I designed this universal motor controller capable on driving DC-, Stepper-, BLDC- and even AC – motors earlier. The design parameters was 12-24V at 15A. This is quite a capable controller, but I did a mistake that limit the controller to 12-20V since I connected the Gate Drivers to the Motor PSU directly. To compensate for this I need to modify the design and implement a separate 12V PSU. As I correct this I also want to consider some additional changes.

I am considering is to replace the RS485 with an isolated RS485 due to the amount of energy involved. The 3rd change is Ethernet on a separate adapter board. Basically I want to copy the modules I use on the Universal Adapter as soon as I have tested them.

I am not sure about Ethernet. Ethernet sound nice due to the functionality, but it is a clumsy, 4-wire 1:1 solution. RS485 is slower, but it is a 2-wire network. It actually makes more sense having dual RS485 to be honest. CAN & Ethernet is easier to deal with using an adapter board- RS485 is considered a lower level of communication than CAN because CAN have protocols like CANopen, J1939 etc. The reality is that if we use RS-X that changes.

What I probably should do at some point is to create a “Ethernet” on top of RS-X by using a dual RS-X connection. But, that is fun for later…

So the modified design will be

  • STM32F405RG MCU, 168Mhz, 32bit M4, 1MbFlash, 192KbSRAM
  • 4 x separate half bridge drivers, 30V @15A
  • Current sensors on all
  • BEMF sensors
  • PSU Voltage Sensor
  • Separate 3.3V supercap to sustain MCU in power dips.
  • 3 x hall sensors
  • 2 x temperature sensors.
  • 1 x resolver
  • 2 x end sensors
  • 1-2 x RS485
  • Adapter board for battery/caps
  • Adapter board for CAN/Ethernet/Wifi


  • Solenoid driver
  • DC Motor driver
  • Stepper Motor Driver
  • Brushless 3-Phase motor driver

32xServo Hat Revision 1.1

32xservehat_1_1Not very exiting, but it has taken me most of the day. This is the revision 1.1 of the 32xServo Hat. Just for the record – the red lanes are actually ground plane so it will all be covered with GND – I just switched it off for the picture.

  • Added optional TVS diode on PSU for better protection.
  • Added 100uF and 100nF capacitor on PSU for spike cutting.
  • Adjusted pin header positions to better fit 3×4 headers.
  • Adjusted the lower 16 channels as they where a bit close to the bottom edge.
  • Added TVS on all 32 channels for protection of the MCU.
  • Changed all LED’s to 0603 package.
  • Added weak pull-up on nRESET.


The lower 16 channels can use 3×4 right angle connectors allowing the Hat to be used in a stack. I finally found a good price on 3×4 right angle down to ca 10 cent each – still looking. You can still use classic 2.54 Pitch pin headers that is even cheaper.

Revision 1.0 is actually ok to go, so I will try putting this into production & sales since a lot of people have asked for it. It will be exiting to see what assembly prices I can achieve. PCB & Components are probably ca 10.- USD all together.

MC4X15A – High Side Current Sensor

The original current sensor logic will use a shunt between the lower HEXFET and ground (low side current sensing). This is fine for 3-phase, DC or Stepper motors, but it will not enable measuring of current on a single, stand alone Half-Bridge.

An alternative way of doing this that fix this issue is to measure the current on it’s way out as indicated below using “high side current sensing”.


In this schematics we introduce the shunt on the PWM Out and take advantage of INA210 being a high side sensor. I connected BEMF to the left side of the shunt due to routing logistics. With a 0.001 Ohm shunt this error should be constant and very small.

High side current sensing is more responsive to changes in the current flow and adds no disturbance to system ground. The main disadvantage is that because the shunt resistor is not at system ground, a differential voltage must be measured which requires the precise matching of the proper differential amplifier. However, this disadvantage is eliminated with the use of a precision current shunt monitors like INA210 or similar.


Transporting the current out proved to be easy as I mounted the shunt opposite the high side HEXFET using it as a path out. The disadvantage is that as the HEXFET heats up so will the shunt. If this becomes an issue I will extend the length and move the shunt to the right. INA210 is mounted opposite the low side HEXFET and will have the same issue, but reading the datasheet it should have max ca 1% temperature drift error. Current sensing is most critical for 3-phase control, but keep in mind that we measure all 3 phases. As adding all three phase currents should give 0 (zero) we have a sensor error indication implemented.

3-phase Micro – cable issue


I was initially quite happy with the way this cable fitted, particularly as I found a trick on how to solder these. But, this is how it looked after having fiddling with it for a day. I could add a proper micro match connector, but they are a bit expensive.


Another solution is to add a cable holder on the PCB at the end to avoid that handling the cable is exposed as stress on the solder points. In this case I need this cable since I am connecting to a motor with a special connector, but for the micro PWM driver that have the same issue it might be an option to simply use 2.54 pitch connectors. It is nice to have things small, but they need to be functional as well. The challenge is to find a solution that is practical and don’t drive size or cost to much.


3-Phase Micro – printf


int main(void)
  int x=0,y;
  char buf[100];
  printf(“\nBasicPI Micro 3-Phase Controller!\n”);
    printf(“%d tick\n”,x);

The 3-Phase micro controller use a RS485 (RS-X) connector. I have not enabled the RS-X package yet, but I always start with a simple printf implementation and a terminal program. This is in 99% of the cases the only debug I need. It will be implemented on top of RS-X as well. Just nice to see that the MCU actually is ticking before we start digging into running the motor – this gives me eyes to look what is happening. My apologies for the formatting of the C main above – I need to find a better way to show source code annotations…

4 x Half Bridge Driver

I really like routing electronics. It is something relaxing about this task that I find very enjoyable. I started routing on pen & paper single layer some 30+ years ago, so having access to a professional EDA and 2 layers are a dream. I would like to upgrade to 4 layers to get two layers assigned to ground and power to increase signal qualities, but I am amazed with what I get away with on 2 layers.


This is the filters, TVS and protections circuitry on the 4 x Half Bridge driver connecting up to the terminal connectors. I decided to make a combined board with MCU and jumper to take out all signals for now. I will simply avoid mounting everything for some of the tests.


This is the backside of the same Connectors. One of my challenges was space as wanted to add a 6,1V TVS diode on every signal Connected between the driver and the MCU due to the effects involved. I did not thing I would make it, but as I looked at the terminal jumpers that are hole through I realized that I could just attach a 4 x TVS array on the “other layer”.

It don’t look much as it is done, but it actually is quite a bit of work before the rat-nest of wires come nicely together. In this case I changed schematics to adapt it to the PCB. Having terminal Connectors like this between driver and MCU also makes it easy to use these as tes poits connecting a Logic Analyzer/Oscilloscope. I will need an adapter board due to the tight 1.27 Pitch thought – I will be back with a complete board a bit later.

Current Sensor Design


This is my current sensor. INA210 comes with a fixed gain of 200. Other variants have different gain. I like this concept because it saves me passive components and space on a critical area + the resistors on the chip have better accuracy. R16 and C5 is the low pass filter. INA210 is bi-directional and high side. The Circuit above is low side design since I Mount IN- to ground.


This is the PCB snip. R1 (cyan) is the current shunt. The two place via connectors are the IN+ and IN- measuring the current. I am real happy with this layout because the sensor leads are so short that it will minimize noise introduction. Notice that I am deliberatly placing the place-via on the solder pads on the shunt With virtually no distance to the INA210. The low pass filter is added closer to the MCU/Connector. The layout of this worked out even nicer than I hoped, so I will be curious to test this one to see what I get out on noise vs. signal. I am actually amazed as to how much I get out of a two layer PCB – assuming this Works as expected.

I decided to add 4 current sensors and BEMF sensors because the current sensors will be heated as well and if they fail or give errors (drift) while heated they might cause a more serious error. I basically need to test them as I burn the circuit + it’s cool to have them mounted.

The values I plan is 0.001Ohm shunt and INA210 that gives 200x gain. This giver 0,015V at 15A and 3V out to the ADC while the shunt use 0,225W. I am a bit concerned that the shunt is to small, so might need to increase the shunt and reduce gain to get a better signal – we will see. The drawback of increasing the shunt is that a shunt with 0,002 Ohm uses 0,45W, a shunt with 0,005Ohm 1,1W etc. The effect usage on the shunt need to be keept as low as possible.


I have only been using SMD components for ca 1 year. I started with 1206, continued with 0806 and now I only use 0603. INA210 is SC70-6 body (X4 above) – the two resistors R2 and R3 are 0603 size to give an impression of how small this actually is. I am however not even worried about these anymore – a bit of training and patience does that to you.