Building a 100% DIY ESC for motors

Joined
May 25, 2018
Messages
197
About a week ago, I decided that I was going to build an electric bike. I was looking at kits, and all of the cheap ones have cheap controllers (go figure!). As a result, I decided to build my own. Right now, I have been soldering for a day and it is looking pretty nice. All 3 channels test out fine, and I am hoping to run about 1.5Kw through it when it is finished. I will be using a "1000w" motor, modified (drilled holes) for higher sustained amps.

Here are the specs:
Controller: Teensy 3.2 @ 72MHZ
MOSFETs: IPB049NE7N3 [N-channel, 75v and 80A rated] and IRF5210STRLPBF [P-channel, 100V and 40A rated X2 in parallel].
Max voltage: Theoretically 75, but I'm using it at 50.
Max current: Theoretically 80 amps, but I'm not using a huge heatsink, so probably less.

nlfJAy6.jpg

5CcIqB0.jpg


After I finish building the controller, I will release the code and a tutorial so that you can build your own. If you buy better MOSFETS / more MOSFETS / a bigger heat sink, you could build one heck of a controller (for racing maybe) by paralleling the MOSFETs. I will be using a 100x35x10mm heatsink from eBay, as well as thermistors in the motor and by the MOSFETs to prevent overheating.

My one question at this stage is: Do I need a bigger capacitor? I will be using this with a low-resistance Lithium Ion pack (17AH, 12S8p 18650).
 
FWIW, if you run into issues with the powerstage or control of your ESC (a pretty common problem), there are a few existing DIY ESC designs here on ES, including a few for the Lebowski brain chip, that may help you work out fixes.

It's pretty rare to use P-channel FETs; just about everything uses only N-channel for one reason or another. Any particular reason for them on your design?


Regarding cooling the motor, there's a few threads, especially the Definitive Testing of heating / cooling of hubmotors thread started by Justin LE, that have good info (ideas and testing results of those ideas).

But unless you're running the 1.5kw continuously, you probably won't actually need to cool the motor--if it's just bursts now and then during acceleration, it'll probably be only a few hundred watts the rest of the time.
 
You will probably find you need a heat sink if you want to run more than about 20A. You can do the math for the conduction losses and get an idea for the heat dissipation, but there will also be switching losses. I2R using the Rds of the FET.

Most designs use N channel FETs on the high side just to get lower Rds devices or maybe they are just cheaper. Requires a floating or bootstrapped gate driver for the high side. P channel avoid the need for the floating gate drive.
 
amberwolf said:
It's pretty rare to use P-channel FETs; just about everything uses only N-channel for one reason or another. Any particular reason for them on your design?
P-channel FETS seem easier to use up front since they are enhanced (turned on) by pulling the gate down relative to the drain supply, so no generation of voltages higher than Vbatt is needed. And that seems easier to designers.

However, this is no longer really true since drivers with integrated charge pumps to create the higher voltage are now readily available.
 
thorlancaster328 said:
As a result, I decided to build my own.

Why? Are you a good enough electrical engineer to outperform professionals? A low cost controller can mean they cut corners and used cheap crap, but it can also mean they solved otherwise expensive problems and optimized the design for you. You have to be pretty capable to discern the difference.

I've had no problems with cheap commodity controllers so far. Cheap bikes, sure. But electrons don't know how much their circuits cost.
 
Thank you everyone for the advice. I've heard of the high-side N-channel driver chips, but I wanted to do this the 100% DIY way. I already had ~90% of the required parts in my storage drawers (everything except the FETs).

In hindsight, I probably should have used just N-channel FETs and a driver IC. The P-channel ones were a good deal more expensive for similar specs and using a high-side driver IC would have been much cheaper.

Questions answered:
1. I am not a professional electrical engineer by any means, but I have designed a similar circuit in the past to power my brushless RC car. It worked flawlessly until it died in a wreck. I also plan on adding some very non-standard features, including as an integrated motor temperature probe and an on-board diagnostic system. It'll also be able to work with Hall sensor wires and phase wires wired willy-nilly.
2. This is not just an e-bike controller, but also a learning experience. Next time, I'll just but a cheap controller (the Teensy alone costs more than a Chinese controller) and add some really beefy external MOSFETs on a large heat sink.
3. I feel like 20 amps without a heat sink is accurate, but I will be adding a 100x10x35mm heat sink when it arrives. My motor can't handle more than 35 amps, so heatsinked it'll be just fine. There's also a thermistor for protection of the MOSFETs.
4. I used ESD protection while soldering the MOSFETs.
More lessons learned:
1. Put tape on the back of the MOSFETs to prevent accidentally soldering to them through the board. I did this and had to destructively remove one of them to fix the problem. Luckily I ordered a spare.
2. Use higher power resistors. I had to switch out a 100 ohm resistor for two 50 ohm ones in series because the 100 ohm one started smoking during testing.
3. Test, build, and test again. Incremental building saves many headaches down the road.

Here is a picture of my controller up to this point. I got a sensored RC motor running smoothly and the 128-step PWM gives super-fine control.

HWKqZ84.jpg
 
Here is the math for the power dissipation at 20 amps:
Low side (N Channel):
4.9 mΩ * 20A * 20A = 1.96W through 1 FET = 1.96 watts per FET*1/3 duty cycle = 0.65 watts average per FET.

High side (P channel, 30mΩ because 2 FETs are paralleled)
30 mΩ * 20A * 20A = 12 watts through 2 FETs = 6 watts per FET*1/3 duty cycle = 2 watts average per FET.

Pretty good, but I would say 20 amps with no heatsink is really pushing it, especially for the P-channel side. Add in switching losses, and the MOSFETs would probably be fried at this current without a heatsink. Add a 5°C/W heatsink, and the temperature rise would only be about 26°C or 47°F.

Given that both FETs have a 175°C max junction temperature, a temperature rise of 80°C would be a safe limit for rise above ambient (100°C heatsink temperature with thermal grease). Given that the temperature rise can safely increase sixfold with a heatsink, the current can increase 1.75x (about the square root of 3). That gives a whopping 35 amps of sustained current, with no air flow. It would of course be higher when riding and air is flowing.

I did not account for switching losses or the effect of air moving over the heatsink, but I'm pretty sure that the motor will overheat before this controller does. I will be putting a thermistor in the battery, controller, and motor and overheating will tell the controller to dial it back before something goes poof.

Edit: I tested the circuit with a loaded motor and it handles 10 amps nicely with no heatsink. 15 amps would be about the safe limit with no heatsink. 20 would be pushing it.
 
Now I see why they always use N channel FETs on the high side. 30mOhms is quite a bit. And more expensive. But if used within it's rating, nothing wrong with it.

Keep in mind with a bike, the load stays high much longer than for a RC car, especially climbing hills. Overkill on the heat sink is always good. Fan cooling isn't bad either, but noisy.
 
I finished up the controller today and decided it was time for a test. At 13.5 amps, it registered only a 10°C increase from ambient.
Given that I can tolerate roughly an 80°C increase from ambient (100°C thermal limit), the controller can run 8x hotter.
As heating is proportional to the square of the current, I calculate a maximum continuous current of 38 amps continuous.

I am considering spending $26 on a new set of P-channel FETs. The high-side resistance would go down from 30mΩ to 10mΩ and the current capacity would go up to around 70 amps continuous. About half the capacity of VasilliSK's Nuclear controller for under $100 (excluding my labor of course).

Am I correct in assuming that the power dissipation of the controller only depends on current, not voltage? These tests were at 12 volts and the bike will run at 48.

As for the fan cooling, I can control it through a transistor depending on power output and temperature.
 
The conduction losses are the primary source of heat and only depend on current. Switching losses will go up with voltage. Overall, you won't see much change with higher voltage unless your switching times are too slow.
 
Thanks for the info on switching losses, Fechter. Given that the frequency is low for the MOSFETs (22khz), I shouldn't need to derate the controller much, if at all.
The controller now has a fan and a soon-to-be-waterproofed enclosure for protection and cooling. The "snail blower" puts out a LOT of air.
B9WbA1x.jpg

The only thing yet to arrive is the 12v switching regulator from China. Next post, I'll show the specs and decide if it was worth it (in about a week).
 
When the regulator arrives, I'll post a schematic and code, along with a short tutorial.
 
The regulator arrived today, and I took the thing out for a test run. The first time I applied a serious amount of power (accelerating on grass), I heard a pop and smoke started pouring out of my rear end. I quickly pulled the battery and inspected the damage. One MOSFET was burnt and charred, and the other two looked OK but tested bad. I have ordered new MOSFETs (rated for 110A continuous) and they should arrive within a week. The old MOSFETs were 60 mΩ and the new ones are only 6 mΩ!

In the meantime, I hooked up the controller that came with the kit. It works, but lacks many of the features that I want, such as a built-in cycle analyst and auto phase advance. It got the bike going, but has less oomph on 12s than my DIY controller had on 6s.

I have realized why my MOSFETs blew up. I was accelerating hard and pushing over 100 amps (full throttle and near stall) into MOSFETs only rated for a fraction of that. I also did not have current limiting hooked up at that time.
 
Cycle-by-cycle current limiting is a good idea. :)

Without it you can get momentary peaks limited only by the inductance and resistance of the wiring, FETs, and motor coils. :/
 
At the time of the incident, the battery that I was using was 25 volts.
The resistance of the motor was 200mΩ, the battery was 35mΩ, and both FETs 65mΩ.

25 volts into 300mΩ gives 83 peak amps. Half that into a 60mΩ FET gives a whopping 103 watts. Bang!

I never thought that surges could be that bad. I'm still getting the 6mΩ FET set though :?
 
thorlancaster328 said:
At the time of the incident, the battery that I was using was 25 volts.
The resistance of the motor was 200mΩ, the battery was 35mΩ, and both FETs 65mΩ.

25 volts into 300mΩ gives 83 peak amps. Half that into a 60mΩ FET gives a whopping 103 watts. Bang!
103w doesn't seem like much, until you figure it's all inside one little die inside the FET body, with only the surface area of the FET to dissipate it, if there's no heatsink. Even if there is, depends on how quickly that heat is developed, and if there is enough time to dissipate it, to conduct that heat out of the die and body into the heatsink and away from the FET.

To make it worse, if one paralleled FET has a slight difference from the other, more current will flow into it. As it heats more than the other, it may get even more than that, and the heating / current increase may cascade and accelerate, so you could get full current thru just one FET. Then when it blows, the other FET has to take the whole load, and it can blow too. :/


As far as the numbers, if you actualy saw over 100A at 25V (including voltage sag at that current) then the resistance/inductance of various things is probably lower than the numbers indicate.


Also, as current switches thru the windings, you may get voltage spikes and induced currents from collapsing fields that are even higher than what you might get from normally expected resistances/inductances/voltages.

Sometimes this sort of thing causes problems in the FET drive circuitry, by induced noise/etc into the gates, causing FETs that shoudl be turning off to not turn off fast enough, or to turn on when they shouldn't, and end up causing shoot-thru that smokes FETs from the current spike (which essentially is full battery current directly thru both FETs in a bridge).

Sometimes designers end up with a lot of noise-control circutry around gates for that reason.
 
thorlancaster328 said:
At the time of the incident, the battery that I was using was 25 volts.
The resistance of the motor was 200mΩ, the battery was 35mΩ, and both FETs 65mΩ.

25 volts into 300mΩ gives 83 peak amps. Half that into a 60mΩ FET gives a whopping 103 watts. Bang!

I never thought that surges could be that bad. I'm still getting the 6mΩ FET set though :?
Without a heatsink connected to the drain tab that mosfet is rated to dissipate about 3 watts worth of heat. Even 1mΩ mosfets will burn after a few mins without a heatsink on the drain tab.
 
I've blown up enough FETs to have an idea how hard I can push them. 2 parallel pairs of 14mOhm parts on a massive heat sink still blow up at around 70A. Thermal calculations can help you find the limits without smoke.

The datasheet will generally have a spec. for maximum dissipation (usually with an "infinite heat sink"). Phase current will be higher than battery current by quite a bit during acceleration, so this has to be factored in. I've measured about 3.5x more on the phases than on the battery but it could be even higher depending on the motor, voltage, etc.
 
I soldered in all new FETs and powered up the board. It worked great driving a small brushless motor from 12v.
Next, I hooked it up to my bike with a 30A fuse. It can handle easily 50, right??
About 10 feet into an easy acceleration, I heard a loud hissing sound from the back of the controller. I quickly powered it off and inspected the damage. Multiple FETs were blown, and the gate driver resistors were all charred and black. I tested the transistors and they were fried too. Approximately half the board is toast. :oops:
I'll start over from the drawing board with only N-channel FETs and gate driver ICs. It's a learning experience... At least the expensive Teensy uC board is fine.

In the meantime, I'll just use the factory controller. It's not all that powerful, but it works okay for commuting.
 
I have done some research into N-channel H-bridge topology and have decided to go that route instead of farting around with P-channel FETs.
Right now I'm considering the LT1160 gate driver IC from Linear Technologies.
Does anyone see any issues with using that particular chip? It's rated up to 75v.
Edit: Darn! They cost $7 bucks a piece on Mouser! I'll have to search for alternatives.
 
thorlancaster328 said:
I have done some research into N-channel H-bridge topology and have decided to go that route instead of farting around with P-channel FETs.
Right now I'm considering the LT1160 gate driver IC from Linear Technologies.
Does anyone see any issues with using that particular chip? It's rated up to 75v.
Edit: Darn! They cost $7 bucks a piece on Mouser! I'll have to search for alternatives.

Welcome to the n-fet life. P-channels are forever gonna be limited by that 3x lower hole mobility in silicon. Can't beat those material properties.

I've been happy with either ST Micro or Infineon (formerly International Rectifier) half-bridge gate drivers. My current project is using the IRS21867, but that's only available in surface mount. No DIPs, sorry!

Here's a Digikey search for half-bridge drivers, independent high/low inputs, through hole mounting:
https://www.digikey.com/products/en/integrated-circuits-ics/pmic-gate-drivers/730?k=&pkeyword=&pv69=80&FV=1b880008%2Cffe002da%2C1e280002&quantity=0&ColumnSort=0&page=1&pageSize=25

The IR2110 looks pretty decent. Up to 500V bootstrap, +2A source / -2A sink, and $3.06 each!
 
I have decided on the NCP5181 driver, the ones recommended by the Lebowski controller project.
My controller will be a 12-FET one, with 8mΩ IRF3205 MOSFETs. It should be able to do 50-60 amps continuous with a heatsink and a fan.
Additionally, this time, I will be cooling the FETs the right way. The tabs will be facing up and separated from the heatsink with a thermal pad and packing tape, as well as active heatsink short detection.

The FETs and driver ICs should arrive early next week. The controller is looking much neater than the old one. I will post pictures and specs when I get the new FETs and drivers.
 
I would recommend only *one* thermal blocking (and electrically insulating) material between the FETs and the heatsink, because every layer you add slows down heat transfer.

You can use Kapton tape for one of the thinnest such materials, or the typical thin silicone pads.

A properly anodized heatsink can also be electrically insulated without such pads, but enough of a scratch into the anodizing could leave a conductive path.

Don't forget to insulate the screws from teh FETs with tophat washers, too, if you use individual ones thru the FET tabs to secure them to the heatsink. ;)
 
For insulating the heatsink, I have decided on a layer of heavy duty packing tape. I placed the heatsink in boiling water and tried to scratch the tape with the butter knife. The tape stayed intact. Next, I tried melting it with a lighter. The tape stayed cool and the heatsink got a little warm. Since the tape is so thin, heat sinking is not an issue. Regardless, I'll have the thermistor glued to one of the FETs, not the heatsink, so that I don't get anything too hot.

Using an untested material for insulation could lead to short circuits if TWO FETs happened to break through the packing tape. To prevent this, I have a protection circuit. A 1k resistor is connected between the heat sink and ground, and a 100k resistor is connected between the heat sink and a microcontroller pin. If it shorts out, a rising interrupt will be triggered, instantly disabling the ESC until power is cycled.

Once all FETs are off, the circuit will be fine. Even with all tabs shorted together, nothing will be blown (except for that 1k resistor, easy to replace).
 
Back
Top