DIY Programmable BMS (now using ATtiny/Arduino)

Batteries, Chargers, and Battery Management Systems.
dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 02 2013 10:09pm

I finally figured out where the added current draw was coming from, I forgot to disable the ADC before shutting it down when going to sleep. Once I did that, sleep mode works great. I'm measuring about 40uA draw (@3.8V), of which about 35uA is the reference. Once I switch it to power the reference off of a pin only when needed, I should be below the 10uA mark.

One interesting phenomenon I've noticed is that if I sleep for more than 2 seconds (ie 4 or 8 seconds), the current draw attributed to the microcontroller goes up substantially. At 4 seconds asleep I measure 35uA from the micro, and at 8 seconds asleep I'm measuring 30uA. It's very consistent as well, I can switch back to 2s, and the current drops back to 5uA. The simple solution is just to stick to 2 seconds between readings, but I'd still like to know why it's doing that.

Njay   10 kW

10 kW
Posts: 836
Joined: Sep 09 2010 10:43am
Location: Portugal

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by Njay » Oct 03 2013 4:39am

Interesting phenomenon. Are you sure it's the micro? Is the watchdog disabled?

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 03 2013 7:42am

Watchdog is enabled, I'm using it as an interrupt source to wake up. Not that I've never been wrong before, but I'm pretty sure it is the micro. I'm measuring current by watching the voltage across a 1k resistor in series with the circuit, and the only thing I'm changing is the watchdog timeout period. I've changed the timeout from 500ms, 1s, 2s, 4s, and 8s several times, and when it's 4s or 8s the current jumps, otherwise it's steady at 40uA. There are brief jumps when it wakes up of course, but otherwise it's constant. According to the datasheet, power down current with watchdog enabled should be around 5uA at a Vcc of 3.8V (fig 21-123 of http://www.atmel.com/Images/doc8183.pdf) so accounting for the reference I'm right on target until the timeout goes above 2s.

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 03 2013 7:35pm

Moved the reference power to a pin that's switched on only for reading the ADC... current draw is now 5 microamps. To put it in perspective, that's 1 Ah every 23 years.

Self discharge will be the dominant factor in power consumption with this design.

User avatar
Alan B   100 GW

100 GW
Posts: 7740
Joined: Sep 11 2010 7:43am
Location: San Francisco Bay Area, USA
Contact:

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by Alan B » Oct 03 2013 8:51pm

Nice! That's the way to get it down.

Does it still do that funny higher power drain on certain delays?

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 03 2013 9:08pm

Yep, still doing that. No clue why yet, I'm going to try the AVRfreaks forum and see if anyone there has encountered it, otherwise I may just contact Atmel and see what they say.

User avatar
Alan B   100 GW

100 GW
Posts: 7740
Joined: Sep 11 2010 7:43am
Location: San Francisco Bay Area, USA
Contact:

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by Alan B » Oct 03 2013 9:38pm

Is something odd going on with the timer that you are using? Overflow or ? Is the sample rate verified to be as you expected?

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 03 2013 10:18pm

Alan B wrote:Is something odd going on with the timer that you are using? Overflow or ? Is the sample rate verified to be as you expected?
Sample rate is exactly what I would expect, just higher current consumption when sleeping longer than 2s.

User avatar
Alan B   100 GW

100 GW
Posts: 7740
Joined: Sep 11 2010 7:43am
Location: San Francisco Bay Area, USA
Contact:

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by Alan B » Oct 03 2013 10:49pm

You are using the watchdog timer? I didn't think that timer went very long. Perhaps they are extending it with software and the chip isn't shut down all that time?

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 04 2013 8:20am

Yep, watchdog timer. The watchdog prescaler allows up to 8s sleep time, as far as whether or not they're achieving the 4 and 8 second periods by some alternate method I don't know, certainly plausible though. I didn't see anything of the sort in the datasheet, but that doesn't necessarily mean anything.
wd-prescaler.png
wd-prescaler.png (61.75 KiB) Viewed 4108 times

User avatar
Alan B   100 GW

100 GW
Posts: 7740
Joined: Sep 11 2010 7:43am
Location: San Francisco Bay Area, USA
Contact:

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by Alan B » Oct 04 2013 10:43am

I doubt they'd change anything like a mode that affected power. But very interesting if they did.

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 04 2013 1:25pm

I even created a program where all it did was go into power down mode, then as soon as the watchdog timer ran out it went straight back to sleep. Same results.

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 05 2013 11:10am

I've been running more tests on the prototype circuit before having the actual PCBs made, although at this point I don't expect any schematic changes.

I'm oversampling up to 12-bit resolution, which seems to be working quite well. It will increase current consumption slightly, but average is still below 10uA over time.

To test the ADC accuracy and make sure the balance circuit turns on when it should, I set the HVC to 4.1V and attached the BMS to a 0.47F supercap to simulate a battery. I ran a 5V supply through ~100ohms to charge the cap, and let the BMS keep the voltage below the 4.1V set point. This should give a pretty realistic charging scenario, a little faster than charging a battery, but if anything it will be a conservative test. (The Arduino in the picture is just there as a 5V supply.)

I was surprised at how accurately it performed, using the min/max function on my multimeter showed the BMS was turning on the balance circuit at exactly 4.1V. After 10 minutes or so of operation, the highest value I recorded was 4.103V from a set point of 4.1V.

Overall I'm quite pleased with how this is turning out. Power consumption is so low it's basically negligible, the design can be configured easily for any HVC/LVC settings, and it's cheaper than the old analog version.
4_1v_hvc_test.JPG

Chuechco   10 mW

10 mW
Posts: 29
Joined: Aug 22 2013 2:09pm
Location: Germany

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by Chuechco » Oct 05 2013 1:58pm

These are good news!
Your 1.2V reference has a tollerance of 1%. Are you lucky that the one you soldered in was a very precise model or did you measure the exact voltage and copied it in your firmware?
You said you oversampled it to 12-bit. Does it mean you just took several measurements in a row and calculated the average?
How much balancing current do you have?
I think there might be an issue with the accuracy of the measurements when all the cell modules are shunting. The balancing wires will have a voltage drop. In order to measure accurately you would need to stop shunting all at once. The attinys would need to be synchronized for this. Another possibility would be to have two cell wires for each cell-module. How will you solve this?
I am planning to build a similar BMS, that's why I am asking.
Johannes

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 05 2013 5:10pm

The 1% tolerance on the 1.2V reference (1.235V to be exact) is pretty generous based on what I've measured, at room temperature they are typically right on 1.235V or within a few mV. I haven't asked TI, but I suspect the 1% covers a wide range of operating conditions. These will typically be used in a pretty narrow temperature range and current relative to the limits. You could certainly get better accuracy by programming the exact value into the firmware, but I don't think it will be necessary.

Atmel AVR121 has a good explanation of oversampling, but you are basically correct that it's just averaging a bunch of measurements together. The way I did it was to add up all the samples (16 for 12-bit) and then right shift the result by 2 bits.

Balance current is limited to about 800mA by the transistor I chose, but more practically I think 500-600mA would be the most I would want to put through it for thermal reasons. I built it with a 10ohm resistor which gives you around 250-300mA. It would be simple to add a higher current FET and shunt a few amps, but for most people that wouldn't be necessary. I'm going to design a "master" board as well that will be able to throttle back the charge current once the pack gets close to the end of the charge.

The voltage drop across the balance wires is definitely something to keep in mind. On the PCB I'm using big fat traces and copper floods to minimize the effects, but you're correct that it could possibly effect measurement accuracy. Keep in mind though, that it's not really necessary to balance cell voltage to perfection. The goal is to enable the cells to reach full charge at the same time, which can still be accomplished even with a little uncertainty due to interconnect impedance.

I attached a rendering (thanks to OSHpark) of the layout, as you can see there is as much copper as I could fit in there, both for heat transfer and to minimize the voltage drop during balance.

If you're interested in some bare boards let me know, I'm going to make them available to the public once complete. Price should be pretty low, $10-15 each I expect. Schematics and code will be open sourced.
Attachments
ATtiny-BMS_PCB-render.png
ATtiny-BMS_PCB-render.png (190.84 KiB) Viewed 4099 times

Chuechco   10 mW

10 mW
Posts: 29
Joined: Aug 22 2013 2:09pm
Location: Germany

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by Chuechco » Oct 06 2013 7:33am

One cell module looks to be 25-30mm wide, right?
So for a 16s, the BMS will be more than 40cm long and the mainboard will add even more. Do you plan to put it into a bicycle frame? Whats your plan

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 06 2013 9:48am

25mm each. My plan is to stack them vertically. Plenty of room in a bike bag for that. There will be holes for spacers in the corners. Overall board dimensions are approximately 100x150mm (4x6"). Not coincidentally, it's also very close to the standard eurocard size, for which there are countless enclosures out there that you can slide the boards into.

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 09 2013 11:03am

FYI, I've started a new thread for the higher level discussion of this design (size, balance current, etc). This thread has evolved into a discussion of the details, and I thought it would be a good idea to separate the two somewhat. It can be found here: http://endless-sphere.com/forums/viewto ... 14&t=54318

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 14 2013 6:43pm

I am planning on ordering a small batch of boards to experiment with, if anyone is interested in 1 or more the cost will be $10 per 6S board, plus $5 flat shipping regardless of the number of boards ordered. PM me if you're interested and I'll send you my paypal email address.

BOM, schematic, source code, and a parts list will all be published online to make this as easy as possible to use. I've also printed the component values on the board itself to make assembly easier. Many of the components are common values that most people tend to have on hand. Total BOM cost, not including the Arduino and programming cable is about $85 for enough to populate enough for a 24S pack. To program the boards you'll need an Arduino and a 6 pin cable to plug into the Arduino ICSP header.

I would suggest anyone interested in these be comfortable with the Arduino programming environment or willing to learn. I'll provide as much support as I can and any necessary code updates, but I won't be able to walk everyone through it in detail.

I've also added code to the firmware that allows the user to ramp up balance current via the onboard PWM controller depending on cell voltage. There is a "soft" HVC point at which balancing starts, and slowly ramps up to 100% at the "hard" HVC point. I personally use it to start balancing my LiFePO4 pack at 3.5V at a low level, and increase the balance current to the full amount at 3.65V.

LVC and HVC are both opto isolated, open collector suitable for use with standard controller brake inputs.
ATtiny-BMS-pcb-render.JPG

User avatar
Alan B   100 GW

100 GW
Posts: 7740
Joined: Sep 11 2010 7:43am
Location: San Francisco Bay Area, USA
Contact:

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by Alan B » Oct 14 2013 7:23pm

Nice!

Have you seen the SparkFun pogo pin adapter kit for AVR 6 pin programming? It should work on your board.

https://www.sparkfun.com/products/11591

Using this adapter allows programming without needing a plug/socket on the pc board, the spring loaded pogo pin adapter is held against the board pad holes for the few seconds of programming, and then moved along to the next position. It may not be what you want for development where many programming cycles are needed, but for loading code into a lot of micros it is quicker and lower cost than soldering in all those plugs. I'm planning to use one on my boards for production units.

LVC wiring

Wiring to ebrake inputs can be problematic if regen is in use. In that case hitting LVC will throw the ebike into regen braking which could be an unfortunate surprise. If you are using regen you might want to connect the LVC from the BMS boards across the throttle output to ground instead, clamping the throttle off. If regen is not programmed into the controller the ebrake input will do the same thing, so either configuration will work in that case.

dmwahl   10 kW

10 kW
Posts: 613
Joined: May 06 2009 9:41am
Location: Madison, WI

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by dmwahl » Oct 14 2013 10:00pm

I will have to pick up one of those adapters, I was going to make my own but at that price why bother. Thanks for the heads up.

Good point on the regen controllers, I don't consider those "standard" since I don't think most people use them. Still good to make people aware of. The point of the output is to have an active low signal that can be used in multiple ways.

powersupply   100 W

100 W
Posts: 215
Joined: Apr 14 2013 8:04am
Location: Santa Monica

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by powersupply » Oct 14 2013 11:11pm

dmwahl, off the bat, I noticed a few things and I just let them out as they are.

Please consider some mounting holes which would not collide with possible sliding rails of eurocard enclosures.

Power resistors can get rid of heat WAY much better if you stand them up (in case you have the headroom).

I would also suggest some staggered connectors for folks like me who have 4s1p (or 5s) packs.

F.I I am using 13s4p made out of 13 4s1p hardcase packs.

I would solder the socket for the first pack into C1..C5 no problem.
But where do I solder the socket for the 3 pins I removed from the next 4s connector?
This is missing from every approach I have seen.

I think you place your stuff way too close to the edges of your layout.
Just skip one stage , how many would need a 36s unit?

Please keep in mind that I have not really aquainted myself with your design, so if something is off I apologize in advance.
Just posted this as I had the impression that you want to order the PCBs.

How much is the total cost of the BOM for a 13s setting BTW?

Thanks!
Last edited by powersupply on Oct 15 2013 4:47am, edited 1 time in total.

peterperkins   100 W

100 W
Posts: 195
Joined: Jun 06 2008 2:10am
Contact:

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by peterperkins » Oct 15 2013 2:16am

As someone who has built several BMS over the years based on individual pic devices for each cell I have the following comments.

1) Nice project and you have the sleeping current down to very low levels. All looks and sounds quite familiar :)

2) The voltage drop in cell connection leads for remote boards is a significant problem when the bypass load cycles. Unless you have a huge amount of hysteresis/very thick wires then as soon as the load turns on the voltage detected by your chip will be significantly lower and probably turn itself off again.

Also adjacent cells sharing cell wires will also tend to interfere with each other. I strongly suggest bench checking how three modules perform on the bench using say 500mm leads using the ones at the ends fed by say a fixed voltage and the one in the middle fed by a variable voltage so you can tweak it up and down and see how it and the adjacent cell/boards respond. Two wires for each terminal removes the adjacent cell interference issue but not the voltage drop in the wires problem.

I have my slave boards controlled by a master board which commands all the slaves to turn off the loads before any measurements are made by the pics. Once the measurement is made then the slave loads can be turned on according to the voltage for each cell. This negates the voltage drop in the wire and the adjacent cell issues completely. In fact it was the only way I could get reliable operation when the cell wires are fairly thin and over about 300mm.

I use a 1S loop/refresh for routine voltage monitoring when driving.
When grid charging though when the first cell cell starts to balance/bypass you can slow down the bms loop/refresh to say 5s this gives the load maximum time to burn off energy between voltage readings.

My first BMS based on the picaxe chips 08M 12F683 was made of individual boards on each prismatic cell, that never suffered from the voltage drop/adjacent cell issues and has operated uninterrupted for 5 years since the boards were first fitted to the cell. That's a pretty good test.

All the code developed for the various boards etc is in the PD on
http://www.batteryvehiclesociety.org.uk ... m.php?f=53

3) The cell voltage measurements do not need to be accurate to the n'th degree. +/-25mv is fine.

4) I used oversampling on a 10 bit adc and a standalone 1% 1.235v reference on the first two versions of my BMS. Lately I have used the internal Vref reference on the 12F1822 pic which has proved to be accurate enough and simplifies the board quite a bit.
Honda Insight MK1 fitted LIC Lithium Supercapacitors 50x2200F Pack
BCM Fooler, BCM Interceptor, BCM Gauge, Li-Ion BMS System, OBDIIC&C, IMAC&C
http://www.150mpg.co.uk

powersupply   100 W

100 W
Posts: 215
Joined: Apr 14 2013 8:04am
Location: Santa Monica

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by powersupply » Oct 15 2013 4:43am

One major concern I have with using mictocontrollers is their operative reliability.

None of these BMS units -be it DIY or produced- have any type of safeguarding against most common EMF or similar external disturbances.

Even with watchdogs active we could knock out PICs by just holding one of those nasty Nextel phones close to them while calling the phone.

Based on your experiences, did you ever have a unit go berserk and you had to reset it to work again?

User avatar
Alan B   100 GW

100 GW
Posts: 7740
Joined: Sep 11 2010 7:43am
Location: San Francisco Bay Area, USA
Contact:

Re: DIY Programmable BMS (now using ATtiny/Arduino)

Post by Alan B » Oct 15 2013 8:40am

Excellent suggestions and concerns in both posts above.

Post Reply