Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

In-development: Inexpensive Custom BMS for Tesla Battery Modules

This site may earn commission on affiliate links.

wk057

Former Tesla Tinkerer
Feb 23, 2014
6,491
17,080
X
Greetings!

Figured this would be a good place to just throw out some notes on one of my projects, a custom battery management system for the Tesla battery modules I'm using in my off-grid solar project. (See that thread for details on that project).

After some tinkering, it seems that I'm not really able to use the BMS slave boards that came with each module after removing them from the car. I tried a bit, as have some others, and without having a working car with the battery pack exposed or some other shenanigans figuring out how to talk to and to utilize those boards seems futile. I've noticed that the boards themselves have been doing something on their own occasionally. They do draw minimal power from the module constantly, and I caught some of them in the act of bleeding power from cell sets (FLIR saw the resistors that were warm) even without being connected to the car's BMS. So, I've been leaving the originals installed for that reason for now.

My setup, however, is only 12 cell sets in series vs Tesla's setup that is 96 sets in series. So balancing and monitoring isn't as critical, but will be needed long term for sure.

I've set out to replace the little boards on each module with something a little more useful. Tesla was kind enough to make them modular, as they only have two plug-in connections on the back of the board: One with 7 wires for reading the voltages of the 6 cell groups and one with four wires that go to two temperature sensors. Simple to just pop the board off and unplug it, leaving these plugs for use with my custom boards.

Took some digging, but I found the exact part used for those connectors. The one is S15B-PASK-2(LF)(SN) for the 15 pin version used for the cell connections and the other is similar with less pins S04B-PASK-2(LF)(SN) for the temperature sensors.

Having finally found the proper connector I ordered a bunch of each so I'd have them in my development inventory.

I ran through some ideas for how to do up a replacement board. I decided that for the first version I'd want to do something that I could assemble by hand without going too crazy, so, definitely mostly through-hole components (no super tiny surface mount stuff). That pushed out the core chip Tesla uses on their board, the BMS chip by Texas Instruments, since it's a super-hard-to-solder-by-hand chip.

Personally, I love the 8-bit Atmel AVR micro controllers and have been using them for various projects for at least 15 years. Most of them, even the "tiny" ones have multiple 10-bit analog-digital converter inputs that when used with clever software and calibration can have effective an effective accuracy of 14 to 16-bits. Plenty for this.

So, long story short I decided I would go with two ATtiny85's to do some cell voltage measurements and some yet to be determined AVR (depending on what I have a bunch of) for a "brain" on the module. The ATtiny's would be powered by the ~12V of three of the six cell sets on the module, and then be electrically isolated from the "brain" microcontroller (probably optoisolation, but likely will find a lower power method for the final board. Tesla's board uses RF isolation I believe, which is neat.). Only need a couple of data lines (tx/rx) to each, so, should be simple.

Each ATtiny would be responsible for measuring the voltages of its three cell groups. Since the ATtiny runs at up to about 5V, will use an efficient converter on each to drop the ~12V 3-cell voltage down. Then using a resistor network drop the cell voltages down to levels manageable by the on-chip ADC. However, the ATtiny can only accurately reference readings to its ground... This is trickier than it sounds measuring cells in series. :)

The ATtiny has a reasonable accurate and reasonably stable 1.1V reference voltage that can be used with the on board ADC. In practice it varies from about 1V to 1.2V, but is stable at whatever it is. So, external calibration during production and correcting in software is pretty easy and accurate.

A resistor based voltage divider will consume some tiny amount of power... but it's super cheap (literally two resistors...). So the idea is to drop Cell0's voltage from up to ~4.2V down to ~1.1V, Cell0+1's voltage from ~8.4V to 1.1V, and Cell0+1+2's voltage from ~12.6V to 1.1V. With me so far?

Then, using three pins on the ATtiny85, take three measurements and extrapolate out the cell voltage. Let's say Cell0 is 3.998V. Then we read Cell0+1 and it's 8.026V. Then we know Cell1 is 4.028V. Then repeat for Cell0+1+2 and maybe we get 12.035V. Subtract 8.026V and we know Cell2 is 4.009V. Obviously the calculations for Cells 1 and 2 will be slightly less accurate than the reading on Cell 0 due to compounded potential error, but with in-production calibration will still be very accurate.

However, as I mentioned, the resistors used for voltage division here will consume a super tiny amount of power (microwatts). The problem is that the power they use is unbalanced between the cells! The resistor that drops the voltages of Cell0 only draws from Cell0, but the next draws from Cell0+1 on top of Cell0's own resistors, etc. Making a BMS that throws the cells out of balance would be bad, so... have to balance things out by adding the appropriate large-value resistors from each cell's positive to it's negative to make sure that the resistors all draw the same tiny amount of power from each cell, thus not throwing them out of balance. This resistor does nothing but waste power, but it is needed to even out the draw of the voltage dividing resistors among the cells. The margin for error at this point, using 1% tollerance resistors, would be in the nanowatt territory and I think can be safely ignored.

So, while not actively balancing, the ATTiny85s, the voltage dividers, and their related components will draw something like 2-3mA from the module continuously as a whole. Each set of cells is something like 250,000 mAh... so, if the modules are left alone for 10 years they might go dead. lol. FOr my system, it works out so that the entire custom BMS system on all of my modules will need about 0.5 seconds of sunlight per day to stay operational. I think I'm OK with that. If we don't have 0.5 seconds of sun per day, cumulative, over a 10 year period I think we have bigger problems that my custom BMS draining the batteries.

Anyway, so, mainly in the planning and prototype phase of this project currently and just throwing this info out there for anyone who cares to read it.

Oh, and some photos. :p


2015-08-05 06.33.38-1920.jpg


Messy work area with breadboard based voltage reading test setup...

--

2015-08-05 06.34.03-1920.jpg

2015-08-05 06.33.58-1920.jpg


Breadboard and the three random 18650 cells in series that I'm using for testing. Along with some actual 1% resistors, the breadboard has what I like to call the poor man's 1% tolerance resistors... basically some 5% resistors that were tested in series to make the right resistance. :p

--

2015-08-05 06.33.48-1920.jpg


Little board I whipped up that breaks out the pins of the ATtiny85 for easy prototyping. Blue header is the AVR ISP connection. The LED is just an I-have-power LED. Bottom connector breaks out all 8 pins of the chip.

--

2015-08-05 06.38.59-1920.jpg


The PCBs I made side by side with Tesla's originals. The ones I made were actually only for size and placement testing. They don't really have many traces because I hadn't gotten that far when a friend told me he had some extra room on a panel he was printing to tag my test board along. I was mainly just seeing how many through-hole components I could cram on the board. ;) I figure I would use RJ45 connectors and normal CAT5 wire to daisy chain my custom BMS boards.

-----

So it's a work in progress. Output from the little ATtiny85 (via software UART) right now:

CELL0: 3998 mV --- ADC1: 3998 mV (1031 mV read / 61441 raw)
CELL1: 4029 mV --- ADC2: 8027 mV (1054 mV read / 62816 raw)
CELL2: 4008 mV --- ADC3: 12036 mV (1020 mV read / 60813 raw)

The readings it's giving are within 3 mV of what my meters and scope are telling me, so.... success! :)

All thanks to this super ugly calibration function:
Code:
#define mV_calc_cal(vin,vread) (float)(((float)vread/((float)vin-(float)vread)+1)*1/((float)vread/((float)vin-(float)vread)))*(float)((1.0/65.536f)*1.1f)

Can probably simplify that a little more... but meh. Takes known readings from calibration with an external reference voltage (vin/vread, run through the resistor network) and uses that to basically tune to the actual internal reference voltage and the tolerance of the resistors. Pretty sure it's right, and is working well in my testing so far. I have a bunch of scrap paper with algebraic equations working that out... who says algebra isn't useful?!

I may work in an automatic calibration circuit if space permits, but probably will just plug each board into a test rig and calibrate them that way.

More soon. Going to work on the bleed circuit next. My plan is to dump into resistors like Tesla does, as well as an LED when the bleed is active because.... why not. Gives an indicator as well as serves a purpose (wastes power to balance the cells).
 
Awesome!
Don't you need some high power resistors to dump power too? Or does it bleed the power so slowly that it doesn't matter much?

The Tesla version uses 43 ohms of resistance spread across 4 resistors to bleed just 100mA or less than 0.5W. I'm probably going to do close to that, maybe about 0.75W including the LED. It doesn't need to be fast, really.

But to answer your question, not really. Just some normal 1/4W resistors should be fine.

Edit: I'll note that the cells in a module are very nicely matched and don't really drift out of balance too badly. In my setup I've pushed/pulled several MWh with my battery bank so far, and the worst module that is out of balance in manual checking is off by like 80mV.
 
I ran through some ideas for how to do up a replacement board. I decided that for the first version I'd want to do something that I could assemble by hand without going too crazy, so, definitely mostly through-hole components (no super tiny surface mount stuff). That pushed out the core chip Tesla uses on their board, the BMS chip by Texas Instruments, since it's a super-hard-to-solder-by-hand chip.

Personally, I prefer SMT these days, certainly for resistors and such. Even things like that QFP I would class as far from "super-hard" to hand-solder, especially if you give it slightly bigger pads on the PCB. The techniques are really quite easy to learn. Seems a shame to shut yourself out from parts that are made for the job.

However, as I mentioned, the resistors used for voltage division here will consume a super tiny amount of power (microwatts). The problem is that the power they use is unbalanced between the cells! The resistor that drops the voltages of Cell0 only draws from Cell0, but the next draws from Cell0+1 on top of Cell0's own resistors, etc. Making a BMS that throws the cells out of balance would be bad, so... have to balance things out by adding the appropriate large-value resistors from each cell's positive to it's negative to make sure that the resistors all draw the same tiny amount of power from each cell, thus not throwing them out of balance. This resistor does nothing but waste power, but it is needed to even out the draw of the voltage dividing resistors among the cells. The margin for error at this point, using 1% tollerance resistors, would be in the nanowatt territory and I think can be safely ignored.

I normally do battery voltage monitors with a P-FET on the top side so you can turn them off when not actually measuring.
 
Personally, I prefer SMT these days, certainly for resistors and such. Even things like that QFP I would class as far from "super-hard" to hand-solder, especially if you give it slightly bigger pads on the PCB. The techniques are really quite easy to learn. Seems a shame to shut yourself out from parts that are made for the job.

Oh, don't get me wrong. I *can* solder the surface mount parts just fine. It's just much more tedious than just dropping in some through hole stuff and being done. Especially when doing ~30 or so boards. When/if I ever decide to produce a production version I'll *definitely* use surface mount components. I'm likely going to use SMT resistors for this project anyway, just time wasn't on my side when I whipped up that size-test board I showed. I literally had about 2 hours to get the layout to my friend so he could cram it into some free spots on some panels he was doing for work. (Ie, free for me)

I normally do battery voltage monitors with a P-FET on the top side so you can turn them off when not actually measuring.

I thought about doing a way to shut it down, but I want to constantly be monitoring and logging things anyway at about the ~5 second level. This way I can build a lot of data for more accurate SoC prediction and the like. Also, when we're talking about μW's on a setup with ~1.9 * 10^11 μWh of capacity... it's just a rounding error at the end of the day anyway.
 
Oh, don't get me wrong. I *can* solder the surface mount parts just fine. It's just much more tedious than just dropping in some through hole stuff and being done. Especially when doing ~30 or so boards. When/if I ever decide to produce a production version I'll *definitely* use surface mount components. I'm likely going to use SMT resistors for this project anyway, just time wasn't on my side when I whipped up that size-test board I showed. I literally had about 2 hours to get the layout to my friend so he could cram it into some free spots on some panels he was doing for work. (Ie, free for me)

For me, i've found the opposite - I can smear paste and skillet reflow the board quickly, so as long as I'm doing enough that I can accept the 10-20% yield fallout from my rather casual technique, SMD is easily faster. I do try to stick with larger SMD components, though - 0805 and QFP. There's definitely a speed penalty for hand-placing QFN or (even worse) 0403 parts, especially if I had a drink with dinner :)

Some of my smaller projects have been a pretty good deal on macrofab.net, but their PCB price is a bit higher than dedicated PCB sites in my experience, so it might less compelling for this board.
 
For me, i've found the opposite - I can smear paste and skillet reflow the board quickly, so as long as I'm doing enough that I can accept the 10-20% yield fallout from my rather casual technique, SMD is easily faster. I do try to stick with larger SMD components, though - 0805 and QFP. There's definitely a speed penalty for hand-placing QFN or (even worse) 0403 parts, especially if I had a drink with dinner :)

Some of my smaller projects have been a pretty good deal on macrofab.net, but their PCB price is a bit higher than dedicated PCB sites in my experience, so it might less compelling for this board.

Yeah, I've honestly not had any need to do much hand SMT stuff in larger quantities. Usually some one off parts for small projects. I hand soldered (cooked) some super tiny BGA chips (~200 pins.......) not long ago, but I cheated a put tiny vias under all of the pads so that it would kind of snap into place, which worked. :p

As for PCBs, I can't really beat the price I get: $0 if I don't mind random quantities at random times and can have my layouts available within a short time (like, 90 minutes) of being asked.
 
  • Like
Reactions: NiallDarwin
These days, I do all my prototyping SMT. Soldering through hole is too tedious.

I use solder paste, template, tweasers and an electric skillett. Once you get it figured out small parts are a breeze and boards go together very fast. I built the first ~200 OpenEVSE boards 5 - 10 at a time with this method...

Skillet Reflow - Reflow Skillet - SparkFun Electronics

Stencils are $25 - OHARARP LLC

Solder paste - SMD291AX Chip Quik Inc | SMD291AX-ND | DigiKey

- - - Updated - - -

For me, i've found the opposite - I can smear paste and skillet reflow the board quickly, so as long as I'm doing enough that I can accept the 10-20% yield fallout from my rather casual technique, SMD is easily faster. I do try to stick with larger SMD components, though - 0805 and QFP. There's definitely a speed penalty for hand-placing QFN or (even worse) 0403 parts, especially if I had a drink with dinner :)

Some of my smaller projects have been a pretty good deal on macrofab.net, but their PCB price is a bit higher than dedicated PCB sites in my experience, so it might less compelling for this board.

I agree, 805 is a great size; 1206 is a breeze; 0403 is not a problem with a little care (speed penalty). With a little care and practice yeald losses of 5% are achievable.
 
Oh yeah, no way I'm going to do 200 by hand. :p Kudos on that.

I was seriously considering getting full professional assembly work done with surface mount component based boards and everything for this because it's 36 total boards I need. That's really more than I want to make by hand to begin with. But I figure it'll be fun. :)

As an added bonus, the wife knows how to solder through hole stuff :p
 
I was seriously considering getting full professional assembly work done with surface mount component based boards and everything for this because it's 36 total boards I need. That's really more than I want to make by hand to begin with. But I figure it'll be fun. :)

You should definitely get a macrofab.net quote if you were considering professional assembly. Assuming they've fixed some of the issues I ran into (I was a pretty early beta tester), it should only be 15 minutes or so to do enough to get a price.

I definitely understand doing it by hand for the fun, though :)
 
You should definitely get a macrofab.net quote if you were considering professional assembly. Assuming they've fixed some of the issues I ran into (I was a pretty early beta tester), it should only be 15 minutes or so to do enough to get a price.

I definitely understand doing it by hand for the fun, though :)

Hmm... that actually looks pretty cool. I'll definitely look into it, Thanks! :)
 
However, as I mentioned, the resistors used for voltage division here will consume a super tiny amount of power (microwatts). The problem is that the power they use is unbalanced between the cells! The resistor that drops the voltages of Cell0 only draws from Cell0, but the next draws from Cell0+1 on top of Cell0's own resistors, etc. Making a BMS that throws the cells out of balance would be bad, so... have to balance things out by adding the appropriate large-value resistors from each cell's positive to it's negative to make sure that the resistors all draw the same tiny amount of power from each cell, thus not throwing them out of balance. This resistor does nothing but waste power, but it is needed to even out the draw of the voltage dividing resistors among the cells. The margin for error at this point, using 1% tollerance resistors, would be in the nanowatt territory and I think can be safely ignored.

Something I noticed. The ADC on a ATTINY85 recommends a signal with a maximum of 10kOhm output impedance to work reliably (17.8 in the ATTINY85 datasheet, page 129).

That would mean you need to use resistors of the voltage divider that will put your power consumption in the milliwatt range, not microwatt. (> 1.6 milliwatt - higher if you include your balancer).

I tried to build a PbA battery voltage meter earlier this year with an ATMEGA (ATTINY24 I think) using > megaohm resistors... but uhh, no :). Though my scope & fluke could both still pick up the voltage level, the ATTINY ADC couldn't.


This was ok for my purposes, so I didn't investigate much more after the datasheet note - just changed resistors and called it a day. However, if you actually get it to work with higher order resistors, would love to know how you did it. I assume something to do with lowering the ADC sampling frequency using the ADC prescaler select & running on a low external clock.
 
Something I noticed. The ADC on a ATTINY85 recommends a signal with a maximum of 10kOhm output impedance to work reliably (17.8 in the ATTINY85 datasheet, page 129).

That would mean you need to use resistors of the voltage divider that will put your power consumption in the milliwatt range, not microwatt. (> 1.6 milliwatt - higher if you include your balancer).

I tried to build a PbA battery voltage meter earlier this year with an ATMEGA (ATTINY24 I think) using > megaohm resistors... but uhh, no :). Though my scope & fluke could both still pick up the voltage level, the ATTINY ADC couldn't.


This was ok for my purposes, so I didn't investigate much more after the datasheet note - just changed resistors and called it a day. However, if you actually get it to work with higher order resistors, would love to know how you did it. I assume something to do with lowering the ADC sampling frequency using the ADC prescaler select & running on a low external clock.

Yeah, I've used the AVR ADCs for quite a few things in the past. Higher impedance is fine for the most part, especially with low sample rates and input analog voltages with a range that keeps them close to the top 75% of the reference voltage. Combine slow sampling with software based oversampling/decimation and you're usually OK with several hundred kOhms of impedance. I'm shooting for about 1 useful sample per second max, being thousands of actual ADC samples. Resolution doesn't start to take a real hit until you start going over ~800kOhm or so, but even then it is manageable up to maybe 1.2MOhm depending on how accurate you want to be.
 
I find it interesting that Tesla's decision to use small cells rather than the large format ones that other car manufacturers use pays dividends when it comes to cell balancing. Since the cells are so small, you can use simple bleed resistors. You can't do something so simple with large cells since the currents are so much greater.

I take it your BMS will just regulate low voltage cut off, charging curves, and high voltage cut off?
 
I find it interesting that Tesla's decision to use small cells rather than the large format ones that other car manufacturers use pays dividends when it comes to cell balancing. Since the cells are so small, you can use simple bleed resistors. You can't do something so simple with large cells since the currents are so much greater.
Tesla has the most balancing to do since they have the largest pack. Size of the cells doesn't have anything to do with it.

With all production EVs topping out around 400VDC, that's usually around 96 cells in series with as many in parallel as required to hit the desired capacity point.

So you need 96 shunts to balance the pack. I mean you could put a shunt on one of the 7000 cells, but that one cell is in parallel with about 70 other cells so you can't help but pull the entire module of 70 cells down.
 
So you need 96 shunts to balance the pack. I mean you could put a shunt on one of the 7000 cells, but that one cell is in parallel with about 70 other cells so you can't help but pull the entire module of 70 cells down.

But each shunt only bleeds a small amount of current since the cell capacity is so small. ie. Tesla can afford to have a large resistance, small currents and the pack will balance over 24 hours (approximately). But if your cells are 10x the capacity, the same small bleed resistors will take 10 days to balance, all else being equal. I'm talking at the extreme limit of my knowledge here, so please forgive me if my understanding isn't correct...
 
But each shunt only bleeds a small amount of current since the cell capacity is so small. ie. Tesla can afford to have a large resistance, small currents and the pack will balance over 24 hours (approximately). But if your cells are 10x the capacity, the same small bleed resistors will take 10 days to balance, all else being equal. I'm talking at the extreme limit of my knowledge here, so please forgive me if my understanding isn't correct...
Shunts are only hooked up to each group of parallel cells.

90 kWh battery / 96 groups of cells in series = 937.5 Wh / group. With a nominal voltage of 3.75V each group has 250 Ah.

24 kWh battery / 96 groups of cells in series = 250 Wh / group. With a nominal voltage of 3.75V each group has 66.7 Ah.

Each group of cells consists of cells in parallel.

On the 90 kWh pack, it's something slightly over 70 3.4 Ah 18650 cells in parallel to get 240 Ah.
On the 24 kWh pack, it's typically two 33 Ah prismatic cells in parallel to get 66.7 Ah.

(Please note I don't recall the exact number of cells Tesla uses, but it doesn't matter for this example)

Now, you're not going to hook up a shunt to each individual cell in the Tesla pack. It's simply not cost effective to wire up 7000 shunts and control them individually - and because you're dealing with groups of 70 cells in parallel, it doesn't matter and you don't have to. You shunt one of those 70 cells, and you shunt all 70.

Both packs require the same number of shunts - 96 - to balance. But if you want to balance each pack in the same amount of time, the shunts on the 24 kWh pack need to be 3.75 times lower in resistance.
 
Interesting project!

I'm not sure why you are worried about the slight imbalance in discharge caused by the measurement resistors?

Simply measure the cell voltages and only bleed when cells are significantly different. As long as your cells are frequently charged - and it sounds like they will be (solar system?) - you will always have to bleed more energy out of the cell than you would have lost from the measurement circuit so you can simply bleed some cells slightly less than others?

TBH I think cells matched within 1-2% will be fine provided you don't go too high or low on SOC. Cell matching isn't critical, it's just necessary to get the maximum capacity out of a pack from all cells.

I'm in agreement with through hole being awkward. I much prefer to make my prototypes using SMD parts. Much smaller, too, so board layouts can fit a lot more on.

Yeah, I've used the AVR ADCs for quite a few things in the past. Higher impedance is fine for the most part, especially with low sample rates and input analog voltages with a range that keeps them close to the top 75% of the reference voltage. Combine slow sampling with software based oversampling/decimation and you're usually OK with several hundred kOhms of impedance. I'm shooting for about 1 useful sample per second max, being thousands of actual ADC samples. Resolution doesn't start to take a real hit until you start going over ~800kOhm or so, but even then it is manageable up to maybe 1.2MOhm depending on how accurate you want to be.

This has bitten me before, generally I see large DC offsets in the measured voltage... One trick I've used is to have a 100nF capacitor across the lower divider resistor. The capacitor acts as the low impedance source for the ADC. When the ADC is not sampling, the pin is set to high impedance input. You can easily get 1kHz+ sample rates doing this with high impedance dividers.
 
Last edited: