It seems as if building a motor controller is somewhat of a MITERS rite-of-passage. Inspired by Ben’s and Bayley’s motor control work, I decided to embark on my own motor control adventures. This morning, I pressed the 3pcb button for a batch of 10 boards.
IRSM005-800MH half bridges with integrated gate drive
- STM32F446 microcontroller
- INA193 shunt amplifiers
- LMR14006 buck regulators
Planned board specs:
- 40v max
- 40a continuous phase current
- Control over SPI or Serial
- 8-pin JST-PH connector for programming (ST-LINK + UART)
- 6 pin JST-PH for halls/encoder (SPI3 port)
- 6 pin JST-PH for control (SPI, i2c, serial. Same as the VESC)
I actually started work on this almost a year ago, over the summer at Amazon (summer o 2016). When I wasn’t flying quadrocopters or riding my skateboard I was working on this. The original goal with this ESC was to use it as a quadcopter ESC, with the hope of fitting it in the standard 36mm square quadcopter control board package. This proved to be near impossible and went out the window pretty quick, but we’ll get there.
Designing a motor controller, and having it work, is not easy. This blog post is long, but it does the effort I have put into this project justice.
My summer strategy was to build the hardware first and think about the software later, as I don’t have a lot of experience register-twiddling. So, time to get on my EE game. I had never even sent out a PCB before. I attempted to reflow a hand-etched PCB once in high school, but ended up burning it so hard that it delaminated. Now equipped with the help of some MITERS knowledge I was ready to begin anew.
The first step was to find the mosfets and the gate drivers. Preferably, in one package. Currently, digikey has 6835 gate drivers, 676 power modules, 42,664 single mosfets, and 6430 mosfet arrays in stock, an overwhelming number of options. One proven option was the DRV8302 chip which Ben uses in his motor controller, however I looked for something with a smaller footprint in the interest of the small footprint necessary to fly on a quadcopter. One promising combo was the DRV8302 plus a triple or quad half bridge module, but all of the fet arrays I found had RdsOn’s of several ohms (not desirable). After much searching I managed to stumble upon the IRSM005-800MH, a cool half bridge with an integrated gate driver all in a 7x8mm package. The specs on the chip are pretty good too: 40v, 80a, 2.7 milliohm. I selected this half bridge for my motor controller.
One thing I had never done before was create a footprint in eagle. While not too difficult, it proved to be a bit of a pain as the dimensions of the pin layout are all relative to each other instead of from a single origin. Not only that, but the dimensions of the pads on the bottom are bottom-view, so the dimensions need to be flipped to create a valid top layer layout.
To work around this, I used the age-old trick of “make a solidworks model and then use the measure tool”. This worked quite nicely.
The layout in eagle:
With this out of the way, I moved on with PCB design.
This blog is written in such a way that it shows not only the finished final product, but also the journey. The journey is rarely as shiny as the final product. I make the point to be honest and show everything. Here you will see some of my duller engineering. Present below in chronological order are each board design which I have made. The finished board design at the end, however the journey to get there was very long. We will start at the beginning…
V1: 6-30-2016. before I discovered the IRSM005 modules, I experimented a bit with UCC27201 gate drivers. Needless to say, I did not go very far.
V2: 7-3-2016. First board with the IRSM gate drivers. Also visible is the 36mm square board, which represents the outline of the proposed ESC. It is clear that space is pretty tight. The second set of fets was an experiment to see if it would be possible to fit a second ESC on this board.
V3: 7-11-2016. Some new components have been added and a second microcontroller has been added to the now 100mm square board. At this point I had realized that with my then current skillset, it was unreasonable to try to build a finished ESC. Therefore I demoted this board to a test design, a sandbox board that I could solder stuff to and experiment with. I also realized that a 36mm square board was a incredibly difficult benchmark to hit, so I lengthened the board to 40mm. In order to fit this, I had to get rid of the gate resistors and replace them with traces. This would not have been good if I were to actually build this controller. The gate resistors on these chips gave me quite a bit of headache during this project, as they effectively increase the package size by 2mm on each side.
The V4 board was unfortunately corrupted. However I can assume that very little progress was made, as the V5 board looks pretty similar to the V3.
V5: 7-12-2016. Very similar to V3, with a few more traces connected. I settled on the STM32F303CC microcontroller, as it is theoretically capable to sensorless FOC using the STM32 FOC library. I read a great deal about the FOC library, and found it to have an awesome range of features.
V6: 7-16-2016. Here I have flipped the fets to the back of the board, to have more space for everything else. I’ve also added an LMR16006 voltage regulator to step the bus voltage to 5v, and then a separate 3.3v linear regulator.
V7: 7-17-2016. BAM!! Board is done. Using the 10 dollar 3pcb 100mm square to its fullest, I decided to test a whole second ESC layout at the same time, and add some pin headers for other prototyping at the same time. I also added some random text “Dude esc”. While this may seem a joke, it was actually a test to see if 3pcb would really print everything on the board precisely as I had sent it- turns out they will.
With everything at least in a state where I was ready to test, I pulled the trigger and made the gerbers. I sent this board to 3pcb and they promptly charged me a $40 paneling fee. I modified the board to make it a bit less obviously paneled, added in some additional text, and sent it in again.
A week later:
With the summer rapidly ticking away, I didn’t ever get the chance to assemble this board in Seattle. Back to MIT it was for some orientation shenanigans with Mike.
Working on projects while simultaneously being an MIT student has proven to be really hard for me. Over the first half of fall semester, I attempted to solder on one half bridge. The low side gate driver got stuck on and therefore that was the end of that for the next few months. Unfortunately the trail goes a bit cold here, when I put this project on hold to work on this one.
Fast forward to: IAP. While on a trip to visit family in Florida, I was out of reach of any bridgeports and therefore revamped the motor control efforts. This time, the quadcopter use case was dropped for good, now with the intent of motorizing the mill. Some of my earlier mill designs featured SK3-shaped brushless motors on the lead screws, this is why.
Continuing the saga, we move to ESC v8. The goal with this ESC was to iron out the power stage. The broken out pin header micro proved to provide a nice degree of flexibility, so I decided to keep it. I expected and hoped to be able to jump some wires together and have this ESC work.
V8: I had learned a lot by making the V7 sandbox PCB. The 100mm square size dual ESC was fun and allowed to examine which design looked better off of the computer screen. The upper design looked vastly easier to solder, so I simply deleted the lower design and continued with the upper one. The V7 design passives also proved to be a pain to solder, so I bumped the passives here up to 0805 and even used through-hole diodes. I removed the switching regulator for simplicity.
V9: This board took only two tries to get something I was happy with, due to its simplicity and large size. I used a double row header in the middle of the board, with the left row as the input to the half bridges and the right side as the output from the micro. I hoped it would be possible to just jump some of these wires to various pins on the micro, allowing me to sort out pin configurations later. Also included on this board were INA193 current sense amplifiers. I also included a bunch of pads at the top of the board where ground alligator clips could be connected, as I had often ended up with an ugly pigpile of ground clips clipped to each other when testing the previous boards.
I sent out for this board on 12-31-2016, and then it managed to sit on my shelf buried for 3 months. One can see the misumi box of mill parts precariously piled on the PCBway box of motor control boards. When will I ever finish? probably never.
Fast forward to about a month ago, with two months having passed since my version 2 board arrived.
I got word through the MITERS grapevine that Jared was building a motor controller based on the FNA25060 power module, an amazing 600v 50a IGBT module with the goal of controlling Bayley’s infinite supply of hoverboard motors. I began to think motor controllers again, and briefly considered designing a new motor controller around this chip as well for hoverboard motors. The hoverboard motors really are not very powerful on 40v, which the IRSM005-800 chips could barely do. Reluctant to ditch the IRSM005 chips entirely, I searched for option other than designing a whole new controller. I searched through the International Rectifier power module database and did a sort by package “PQFN 7×8” to see if there were other options in the same footprint- and to my surprise I found the IRSM005-301MH, a version of the same chip rated for 100 volts at 30 amps- the perfect hoverboard motor controller chip. The motor controller was back on!
Time for: spring break, motor control edition. After my one class on the Friday before spring break, I went straight to MITERS and began soldering.
Friday afternoon and night was spent soldering up one of the V2 PCBs. My first attempts at soldering the 7x8mm PQFN package were just as ineffective as they had been in the fall, made worse by the fact that the MITERS solder paste syringe was broken so I had to use a normal soldering iron with a MITERS-style sharp-point-broken-off chisel tip. I soldered one board with no luck:
I tried soldering another, with no luck. My methodology of testing was to use a function generator on the low side and observe the resultant low side gate drive output. No success for the rest of Friday night.
Saturday morning came with some new insight. It turns out I had actually been scoping the mosfet gate rather than the gate drive output (basically the wrong side of the gate resistor, which I hadn’t installed yet). I had assumed the the pin closer to the logic side of the chip was the gate drive output, rather than the other way around. I had just figured LO should mean Low Output, whereas in fact it is the gate for the low side fet. It turns out that on the 100v version in fact these pins are switched from the 40v version (LO is actually the low side gate driver output) and make more sense.
Here is the pinout for the 40v version which I am currently using:
Another issue was bad soldering. My eyesight has definitely gotten worse since coming to MIT, but when I looked really hard I was able to see that some of the logic pins had not been soldered all the way.
One failed board, upon closer inspection:
After thinking and experimenting for a little while, I figured out that the reflow actually happened in two steps, first as the outer pins soldered and then again as the central ground pad soldered. When this pin was not reflowed, the blobs of solder were slightly elevating the chip just far enough to not make the logic pins touch and reflow even when the solder was melted. I also found that lightly pressing the chip onto the board once all of the solder had melted helped all of the pads touch and flow.
I wrote down these instructions for myself after soldering the U fet. By following them, I was able to solder the V and W fets on the very first try.
Steps for soldering IRSM005 fets
- goop a bit of solder onto signal pins on the PCB, you will get solder on big pads as well
- Goop a bit of solder onto big pads. You will get too much on there, accept it
- Get solder braid and wick off the excess pad solder until there is only a bit left
- Repeat on fet itself. Try and make it so that the little pads have a ton of solder on them. Like sticking off.
- Put board on reflow thing
- Drop on one drop of flux
- Place fet on top of thing. Align pads
- Turn on preheat
- Turn on hot air.
- Wait several seconds. It will move a bit as the pins solder, then move again as the pads solder. Press down a bit to ensure connection
- Solder on gate resistors, buck cap and diode, etc
By following these instructions I had zero issues on the V and W fets, got them to solder perfectly on the first try. The two big things I had been missing was having enough solder on the smaller logic level pins and waiting for the solder to fully reflow before removing the hot air. The chip would visually move twice, and only then was the solder fully melted.
With all three gate drivers on there, I began the process of testing. I used a little resistor bridge which would bring the phase output to the middle of the supply voltage and ground, enabling me to easily see if either the high or low sides were active without removing any wires (at least that was the thought….). The four ground tabs at the top of the board proved to be amazingly useful, making the testing setup a lot less sketchy.
All the low sides worked great immediately! Success! But, the high sides proved to be a bit more troublesome. They only worked when the logic supply was about 5v higher than the bus voltage, indicating problems with the buck cap system. I tried soldering on an additional 1uf “bonus cap” on top of the 0.1uf 0805 buck cap, and this modification did absolutely nothing. At this point I had made quite a bit of progress for the day and decided to call it quits for the night.
Sunday morning! (and by morning I mean 2pm!). A good sleep brought new thoughts: my little resistor phase floating divider was only causing the phase to be (weakly) pulled down to half of the power supply voltage, not ground. This would mean that the phase was not going low enough to properly charge the buck capacitor. By simply removing VCC from the resistor divider, only the pull down was active… and bam it worked. All 3 phases, high and low, were confirmed to be working on the scope. A huge milestone.
By now it was Sunday night. Next step was to write some sketch a$$ open loop block commutation code. The pin headers enabled me to easily connect an F401 Nucleo (of which miters had many) and after a bit of head banging with incorrect pin assignments I connected an NTM 2830S “infinity” motor.
Bam. And the motor even spun.
I used a huge 2 ohm resistor in series with the power just to make sure the current didn’t explode anything, as there was zero protection against shoot-through in my code. But hey it even worked. Apparently this resistor was used by Charles to test his original Ragebridges.
I also soldered up the switching regulator on one of my V1 boards, and surprisingly it happened to work as well!
I used a random resistor as a load. The output was 5.08 volts.
The V2 PCB did have a space for a microcontroller to be directly attached, however it was the pinout for the STM32F303CC, an LQFP 48 package. At this point it had become clear that the STM32F303 was no longer the right microcontroller to go with, mainly due to the lack of support in Mbed. Ben recommended the STM32F446 (in an LQFP 64) as a replacement. I chose to go with this to simplify the firmware development process, as I would only have to change a few pins to make Ben’s code work on my ESC.
With the V2 PCB power stage working and therefore the PCB having served all it could, I moved onto design on the version 3 controller, which (fingers crossed!) will be very near to the finalized product. For this V3 design, I needed to tackle the last major problem: mounting the microcontroller and connecting all the correct pins directly rather than attempting to jumper things in after-the-fact.
I had no idea how to do this with an STM32 chip as I had never used anything besides the ATmega328. I began by researching Ben’s Cheetah V2 controller (which uses the 446) and the VESC (which uses the 405, which has a very similar pinout to the 446). I used my 34″ 21:9 monitor and 14″ secondary monitor to their fullest as I reversed engineered both controllers at once, referred back to the datasheet for the pin functions, and noted them down in my google doc. The VESC features a 6-pin header for i2c, SPI, and serial on the SPI1 bus, a feature which I liked and therefore copied. I consulted Ben on what pin configurations to use. In order to make his help more applicable, I used a pin configuration almost identical to his board, so the PWM registers should be easier to set up because I can just copy his code.
And therefore we move into another eagle CAD saga!
ESC V10: The return of the switching power supply and the surface mount diodes. The STM32F446 dangles at the bottom, not yet connected to anything.
V11: The board has been condensed and tetrised together. This board (minus the parts that had not been connected on the right hand side) was 40mm square, marvelously small. A second switching regulator has been added, and the two connected in series. The first regulator steps down to 12v to power the gate drives and the second switches down to 5 for general 5v, which is then taken to 3.3v for the micro by a linear regulator. The three pin headers (counterclockwise) are: encoder input (SPI or quadrature with indexing), programming (ST-link + UART on top), and a general purpose SPI/I2C/Serial bus for control. On this version of the ESC the power planes and shunt resistors were all on the bottom of the board, not yet placed in this design.
V12: no changes since V11 design. However, I had begun to realize a major problem with this design. The current shunt amplifier output from either amplifier ran directly next to the gate resistor from one of the mosfets, and therefore would likely be corrupted from the huge switching currents present in the gate drives. I consulted Ben and Bayley. Ben recommended turning the fets 90 degrees, and Bayley stated “It will work if you reduce your expectations.”
V13: Things got a bit funky here. I rotated the fets 90 degrees but it just didn’t look very good. I then tried a bunch of weird things, like rotating the fets 25 or 45 degrees and tetrising the passives around them.
V14: Same as V13, despite staring at it for a while.
V15: I decided to try going with the rotated fets. Here they are aligned along the edge of the board. Unfortunately the board was looking like it was going to be bigger than 40 mm square 🙁
V16: The sideways fet layout is mostly completed. However, it doesn’t fit super well, and the vias are kind of long. Ugh.
V17: Well, it fits… but does it look nice? not really. Everything is connected but it just kind of looks ugly. The current shunts were brought into the center of the board, so they were away from the gate drivers. However, this caused the ground plane needed to be pretty ungainly and messy.
So, V17, done. But man it just looks ugly. Could we make it better? I wasn’t super happy with this orientation of FET, it just hadn’t worked out quite as nice as I had hoped it would. I decided to try going back to original orientation in V18. At worst case it wouldn’t work and I’d have to go with this design.
V18: Taking Bayley’s wisdom to reduce my expectations, I tried the original fet orientation while bumping the PCB size from 40mm up to 45mm square. This gave me a ton of space to add features. I liked the battery plus plane on top from the V17 design but everything else about the V12 design. The extra 5mm allowed me to put the current sense amplifiers on the bottom of the board as well as the critical noise sensitive traces coming from them. I read somewhere that “armoring” these traces with ground vias would reduce noise, so I added vias all around each of the two shunt amplifier output traces.
This layout just turned out NICE. Everything just fit into place and the resulting design was quite beautiful.
A brief diversion: On a whim I designed a derpy breakout for attinys, labeled as the “attiny13a derp board” in my eagle library:
It is designed to fit attiny13s through attiny85s. The attinys are the cheapest AVR micros available on digikey. I figure this board will be useful for random dumb stuff like headlight controllers and maybe an RPM sensor. Moving back onto real stuff.
V19: The final board! Everything is the as V18 except I realized there was nowhere on the board I was using the 5v output. So I got rid of it and changed the output voltage of the switcher to 3.3v.
Done! After a solid week of designing away my spring break, I sent in this board to 3pcb Saturday night at 3:29am. After reviewing, I purchased them at 4pm on sunday.
Wow, what a relief.
DONE WITH THAT!
As soon as the PCB and digikey order arrives, it will be time to start soldering…. Stay tuned!!!!