Latest News

Welcome to MV Tanglewood. Please fill out the "Follow this blog by email" (to the right) to receive notifications of updates to the blog. Thanks, and enjoy!

Sunday, November 18, 2018

Building a Battery Management System (BMS)

I've been building a Battery Management System (BMS) for my LFP battery system, and this article will go into more detail about what it does, and the equipment involved.

I'm not building my own BMS because I want to.  Well, maybe a little bit, but it's really because I'm concerned about support and repair 3 to 5 years from now.  Most of the companies building stand-alone BMSs are tiny outfits, and I doubt their longevity.    Several have already come and gone, and I know one guy's who's whole battery system shut down because of a small failed part, the company is defunct and he's stuck, quite literally, until he can buy and install a whole new BMS.  That's really incompatible with distance cruising, so I want something that is built from readily available, industrial components from companies that have been around for a while, and are likely to still be around in the future.  I want to use products where there are many more, much larger customers, who will scream much louder than me if things break and there are not fixes available quickly.  And I want flexibility so I can make changes, and experiment with different approaches to power management.  As much as anything, this is a learning experience for me.  That's the fun part.

All this led me to Programmable Logic Controllers, or PLCs.  They are made by many very large companies, and are used to control everything from elevators, to building heating and lighting, to pretty much every manufacturing facility on the planet.  You don't see them, but they are everywhere.  Our Nordhavn 60, for example, had one at the heart of the hydraulic control system.

Another nice part about PLCs is that all the parts communicate using an industry standard protocol called Modbus.  It works over a standard RS-485 link, or over TCP/IP using ethernet.  So any PLC can connect to sensors and displays from other vendors, and it all works.  And if you look closely, it turns out that many of the electrical devices on a larger boat support Modbus as well.  Victron's devices, for example, are all accessible and controllable via Modbus.  Same for Dometic chillers, FCI water makers, variable speed motor controllers, main engine controls, generator engine controls, etc.  All that stuff can be monitored and controlled via a PLC, if you want.

Sounds good, doesn't it?  I though so, but where to begin?  I had never touched a PLC before, let alone program one, or had any idea who's to use.  So how did I decide?  I looked at some of the bigger names like Siemens, Schneider, Eaton, Rockwell, and Allen-Bradley, but they were pretty expensive.  And I looked at a couple of off-brands that were pretty affordable, but started to feel a bit too much like buying a BMS from a small company.  Then I noticed that both ABT and Delta-T used IDEC PLCs in their hydraulic controls and fan controls, so I checked them out.  I figured if those two companies were happy with IDEC, they would likely fulfill my needs too.  They aren't cheap, but are more reasonably priced, and the company has been in the business for a very long time.

IDEC PLC components

IDEC control displays

So about a year ago, I bought an IDEC PLC to start experimenting and learning about them.  Since there were a wide range of possible applications, I decided to get a very full featured model that would act as a development system for most anything I had in mind.  I got one with 40 input/output channels, ethernet, multiple plug-in expansions modules, plus Canbus J1939.  The J1939 support was with an eye towards pulling data off the engine controls, and hopefully NMEA 2000 as well.  And I also got a color touch screen to use as the control panel for operation.


IDEC HG1G 4.3" color touch screen

Over the following year I played around with three different applications; wiper control that would be more flexible than the off-the-shelf controls, automated fog horn control, and steering station selection and take-control for steering controls through the auto pilot.  Individually, none could justify the cost of a PLC, but combined it starts to look really attractive.  All were successful, and served the bigger goal of teaching me how to program a PLC.

Main screen for control of wipers, horn, batteries, and auto pilot.

That brings us to the BMS which would be a real, live application, not just an experiment.  And one that would be controlling and protecting an expensive battery bank.

The first step was to create clear requirements, and sort them into features that are essential from day one, features that need to follow shortly after, but that don't prevent initial deployment, and things that are nice features, but not essential for prolonged use.  We used this approach extensively in industry when developing products, and it really forces you to clearly articulate what is minimally required to have a viable product.  In this case, it helped identify what's needed before I place the batteries on line.  In a condensed form, here's the list:

  • Voltage measurement for each series wired battery cell, or group of cells.
  • Alarming and control based on cell voltages.  Note that these actions will take place if any cell exceeds the limits.  Any one cell exceeding the limits can cause the entire battery bank to get shut down.
    • Over voltage alarm and emergency battery disconnect.  This is an action of last resort to save the batteries by disconnecting them
    • Over voltage alarm and battery reconnect.  At this point the cell voltage has lowed to a point where it is safe to try reconnecting the bank.  Note that this only comes into play when the bank has been previously disconnected.
    • High voltage alarm.  This is a warning saying that a cell has exceeded the high voltage level.  This warning should help provide early detection of issues that could lead to shutdown of the battery bank.
    • Under voltage alarm and battery reconnect.  At this point the cell voltage has raised to a point where it is safe to try reconnecting the bank.  Note that this only comes into play when the bank has been previously disconnected.
    • Under voltage alarm and emergency battery disconnect.  This is an action of last resort to save the batteries by disconnecting them
  • Display of individual cell voltage and status, plus bank voltage
  • Programmable voltage for all of the thresholds above.
  • Email when there is any change of status.
These are the features that I felt were critical to have before placing the battery bank in service.   It would keep me appraised of any changes, and include automatic protection in case things get too out of hand.

The next priority is temperature sensing, but I feel that can wait until a bit later.  In the mean time, I'll monitor battery temperature manually.  Their operating environment is very mild with winter temps perhaps down to 10C (50F), and summer temps of no more than 18C (65F).

As you can see from the list above, the key element is per-cell voltage, and that turned out to be a lot harder than I expected.  There are lots of analog voltage sensing devices available that are compatible with my PLC.  The problem is that they all utilize a common ground signal for sensing voltage.  That means one of the measurement wires needs to be connected to the battery bank ground, and the other to the pos terminal of the battery you want to monitor.  The result is that for the first battery in the bank you are measuring 0-3V.  Then for the next battery you are actually measuring the first two batteries, and need to subtract out the voltage of the first battery.  Then for the third, you are measuring three batteries, and subtracting out two.  And so on and so forth for 16 batteries.

It's a very inaccurate process for two reasons.  First, there are errors in each measurement, and when you then start to add and subtract them, the error range gets larger.  Second, the measurement scale that you need to use is the scale for the whole battery bank rather than the scale for a single battery.  If the sensor is accurate to 1%, then accuracy on a 5v scale is 50mV.  That's pretty good.  But if it's on a 50V scale, the accuracy is now on 500mV.  That's nowhere near accurate enough for LFP voltage measurements.

The bottom line is that you have to measure each cell individually to get the required accuracy, and that means that each measurement channel needs to be electrically isolated from the others.  That way the neg probe can go on the negative terminal of the battery, and the positive on the positive terminal, and it doesn't matter which battery in the string you are connected too.

Finding a voltage sensing device with fully isolated inputs turned out to be much harder than I though, and I only ended up finding one from a company called Advantech.  They have a whole line of industry control devices, including an 8 channel analog input with fully isolated channels.  The range is selectable, including 0-5v, and the accuracy is 0.1%, or 5mV.  Bingo, that's what I needed, and I bought one to try out.

Advantech ADAM 4117 isolated channel (8 ch) voltage sensor

The first pass at the BMS I cobbled together on a scrap piece of wood using whatever wire I could lay my hands on.  I set up 8 battery cells in series as a 24V battery, with each sensor channel connected to a single battery.  That let me get all the components configured and talking to each other, and verify that I was able to measure each battery in the string.  It all worked, and let me move on to programming the various display and control functions.

Proof of concept system assembled on a piece of scrap wood
To make programming and testing easier, I set up a connection for a "simulated" battery.  I installed a relay controlled by the PLC that switches the input to one of the voltage sensors.  Normally it's connect to the battery, but when you push the "Sim" button on the display, the relay switches the sensor input to an external variable voltage power supply that I have.  With that, I can dial the apparent battery voltage up and down and confirm that the PLC responds as expected, sends the desired warnings, and disconnects the battery bank when it's supposed to.

Here's the basic control, as seen through the control screen.  The home screen shows the overall battery voltage, and has buttons to get to the other pages. 

Battery bank voltage screen

The primary status display shows the state of each cell with the voltage, and an icon for alarm status.  A green square shows all good, yellow up or down arrows indicate high or low voltage respectively, and red up or down arrows indicate over or under voltages respectively.

Detailed battery status showing one cell with high voltage

And here is the configuration page for setting various alarm thresholds.
Configuration screen for setting all battery thresholds

Any change in status that lasts more than 30 seconds gets reported via email.  Here's what the body of the email looks like, providing all the same details as the control screen.

Cell Voltage Status
1  3.283 Ok
2  3.284 Ok
3  3.283 Ok
4  3.281 Ok
5  3.283 Ok
6  3.282 Ok
7  3.283 Ok
8  3.283 Ok
9  3.283 Ok
10  3.282 Ok
11  3.281 Ok
12  3.280 Ok
13  3.493 High
14  3.283 Ok
15  3.283 Ok
16  3.283 Ok

Once the basics were proven to work, it was time to build up the real system.  I had an old battery box designed to house eight L16 lead acid batteries that were the power source for an earlier incarnation of the house power system.  By luck, 32 CALB 180Ah cells fit in it perfectly with just enough space left over for wiring and the disconnect relay.

32 CALB 180 cells fit nicely in an 8 cell L16 box

Below is a diagram of the battery layout.  They are configured as 2P16S.  The "2P" means two batteries wired in parallel, which gives 320Ah @ 3.2V building blocks.  Then "16S" means sixteen of those building blocks wired in series, which brings the whole bank up to 320Ah @ 51.2V, or 16kwh of power.

Battery cell layout in 2P16S configuration

For the BMS, I bought an electric box with hinged and latching door, and mounted it to the side of the battery box.  All the BMS components will be in the electric box, with a pass through for wires between the electric box and battery box.

Equipment box to house BMS components

Built up BMS - wires will be dressed up later

One cumbersome part of the build has been fusing all the voltage sense wires.  All are at elevated voltage with respect to ground and to each other, and have very high current capacity delivered from the batteries.  As such, they all need to be fused.

Fuses for all the battery voltage sensor connections.

Another feature I added is an override switch for the main battery relay.  This is for service and for emergencies in case of a PLC problem.  It has three positions;

  1. Automatic where it is controlled by the PLC
  2. Manual Off where it is Off regardless of the PLC
  3. Manual ON where it is On regardless of the PLC
Battery disconnect relay over-ride

Normally it would be in the Auto position, but if I need to update the PLC, which I expect to do pretty often for the foreseeable future, I can switch it to Manual On to maintain battery power to the house and inverter while I mess around with the PLC.

Inside the battery box with the batteries and other high current wires is the main battery disconnect relay.  It's rated for 500A @ 60V, so well suited for the job.  The only down side is that it draws a lot of power when activated, which is all the time.  About 18W to be exact, which is about 150% more than the whole rest of the BMS plus color display screen.  There are some nice, much lower power devices available that others are using for LFP systems, but their max voltage rating doesn't support a 48V system.  So for now I'm stuck with this, but it will be on the top of my list to find a replacement.

Battery disconnect relay and connected battery cells

The results so far are very satisfying.  I have all the required functions working, including email messages when anything changes.  And I have tried slowly charging the bank to an artificially established threshold to verify that the bank disconnects.  I also checked the measured cell voltages against a NIST calibrated Fluke meter that reads down to 1/10th of a mV.  The BMS is reporting battery voltages that are accurate to within 1mV, and a total bank voltage that is accurate to within 20mV.

The next step is to charge the batteries up and manually perform any battery balancing that might be required, then move the package from my shop to the house basement for final installation and connection to the power system.  I'll keep the lead acid bank in place for a while with an A/B selector switch to control which bank is powering the house.  This is, after all, our primary source of power, so I need to be able to get it working in short order no matter what.  Otherwise I have to run a generator all the time which is really wasteful.  With snow cover, the old batteries probably won't come out until spring

I expect a number of people are wondering about cost on this approach.  It's not the cheapest approach - not by any means - but that wasn't a key objective.  Cost definitely matters, but I'm willing to pay more to have something that is maintainable and repairable.  That was the primary goal.  At the same time, I'm not sure it's really much more expensive than some of the packaged systems. 

Right now there are a few things in my system that are more expensive than they need to be, or than is required for a 24V system.  For example, the fancy PLC that I bought was about $650, but not that I'm ready to put this system into production use, I have ordered a simpler model specifically for the BMS that is $350.  For a 48V system, I needed two of the voltage sense units, and only one is required for a 24V system.  I also had to add a 48V to 24V DC power converter to power the BMS off my 48V batteries.   So if you get rid of all that and reduce it down to what's needed for a 24V boat system, here's a rough breakdown:

PLC - $350 (a lower cost model suitable for the BMS)
Display - $310
Voltage sensor - $230 (only one needed for a 24V system)
Fuses and holders - $50
Battery disconnect relay - $300 estimate, depending on what you get.
Enclosure and misc - $200

All told that's what, $1440?  I have been figuring on $1500 to $2000, so I was in the right ball park.

For comparison, the Lithionics 24V BMS sells for around $2600.  So cost-wise I think I'm actually in pretty good shape.  And the nice thing is that if I decide to double the battery capacity, the only cost would be the batteries themselves and another enclosure.