Cruisers Forum
 

Go Back   Cruisers & Sailing Forums > Engineering & Systems > Lithium Power Systems
Cruiser Wiki Click Here to Login
Register Vendors FAQ Community Calendar Today's Posts Log in

Reply
  This discussion is proudly sponsored by:
Please support our sponsors and let them know you heard about their products on Cruisers Forums. Advertise Here
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 11-03-2020, 13:07   #196
always in motion is the future
 
s/v Jedi's Avatar

Cruisers Forum Supporter

Join Date: Feb 2009
Location: in paradise
Boat: Sundeer 64
Posts: 19,323
Re: Designing yet another BMS (yaBMS)

Did some more work on the code:

- added a third "alert" level
- created a struct type variable for the settings that can be saved in EEPROM
- added support for real time clock incl. interrupts
- added power saving support

Code:
/*
      yaBMS - yet another BMS by s/v Jedi

      simple bms for LiFePO4 house batteries

      uses INA219 sensor to measure cell voltages
      uses TMP36 sensor to measure cell temperatures
      uses DS3231SN real time clock module for time keeping, logging and wakeup interrupts
      uses SSD1306 as OLED display
      
*/

typedef struct {
                                        // LiFePO4 charge temperature range is 4C - 57C
  int8_t Charge_loTempWarning;          // stop charging (normally <= 7C)
  int8_t Charge_loTempAlert;            // signal low temperature alert (normally <= 6C)
  int8_t Charge_loTempCritical;         // disconnect charge bus (normally <= 4C)
  int8_t Charge_hiTempWarning;          // stop charging (normally >= 54C)
  int8_t Charge_hiTempAlert;            // signal high temperature alert (normally >= 55C)
  int8_t Charge_hiTempCritical;         // disconnect charge bus (normally >= 57C)
  
                                        // LiFePO4 discharge temperature range is -20C to 71C
  int8_t Discharge_loTempWarning;       // stop non essential discharge (normally <= -17C)
  int8_t Discharge_loTempAlert;         // signal low temperature alert (normally <= -18C)
  int8_t Discharge_loTempCritical;      // disconnect load bus (normally <= -20C)
  int8_t Discharge_hiTempWarning;       // stop non essential discharge (normally >= 68C)
  int8_t Discharge_hiTempAlert;         // signal high temperature alert (normally >= 69C)
  int8_t Discharge_hiTempCritical;      // disconnect load bus (normally >= 71C)

                                        // LiFePO4 voltage range 2.5V - 3.65V
  float Charge_hiVoltageWarning;        // stop charging (normally >= 3.50V)
  float Charge_hiVoltageAlert;          // signal high voltage alert (normally >= 3.55V)
  float Charge_hiVoltageCritical;       // disconnect charge bus (normally >= 3.65V)
  float Discharge_loVoltageWarning;     // stop non-essential discharge (normally <= 3.15V)
  float Discharge_loVoltageAlert;       // signal low voltage alert (normally <= 3.10V)
  float Discharge_loVoltageCritical;    // disconnect load bus (normally <= 3.00V = 10-15% SOC)
  
} CellProfile;

#include <Wire.h>                       // i2c communications
#include <Adafruit_INA219.h>            // voltage sensor
#include <Adafruit_GFX.h>               // graphics library for oled display
#include <Adafruit_SSD1306.h>           // oled display
#include <LowPower.h>                   // power saving features
#include <RtcDS3231.h>                  // real time clock

// cell sensors
#define cell0pinTemp A0                 // analog input pin for cell 0 temperature sensor
#define cell0addrINA 0x40               // i2c address for cell 0 voltage sensor
#define cell1pinTemp A1                 // analog input pin for cell 1 temperature sensor
#define cell1addrINA 0x41               // i2c address for cell 1 voltage sensor
#define cell2pinTemp A2                 // analog input pin for cell 2 temperature sensor
#define cell2addrINA 0x44               // i2c address for cell 2 voltage sensor
#define cell3pinTemp A3                 // analog input pin for cell 3 temperature sensor
#define cell3addrINA 0x45               // i2c address for cell 3 voltage sensor

// OLED display setup
#define SCREEN_WIDTH 128                // OLED display width, in pixels
#define SCREEN_HEIGHT 64                // OLED display height, in pixels
#define OLED_RESET     4                // Reset pin # (or -1 if sharing Arduino reset pin)
#define OLED_ADDR   0x3C                // i2C address of display

// Interrupt Pin Lookup Table
// (copied from Arduino Docs)
//
// CAUTION:  The interrupts are Arduino numbers NOT Atmel numbers
//   and may not match (example, Mega2560 int.4 is actually Atmel Int2)
//   this is only an issue if you plan to use the lower level interupt features
//
// Board           int.0    int.1   int.2   int.3   int.4   int.5
// ---------------------------------------------------------------
// Uno, Ethernet    2       3
// Mega2560         2       3       21      20     [19]      18 
// Leonardo         3       2       0       1       7

#define RtcSquareWavePin 2              // Uno
#define RtcSquareWaveInterrupt 0        // Uno
#define BatteryTestInterval 300         // test every 300 seconds

// normal mode:
CellProfile lifepo4 = {7, 6, 4, 54, 55, 57, -17, -18, -20, 68, 69, 71, 3.50, 3.55, 3.65, 3.15, 3.10, 3.00};

// storage mode:
// CellProfile lifepo4 = {7, 6, 4, 54, 55, 57, -17, -18, -20, 68, 69, 71, 3.25, 3.30, 3.65, 3.25, 3.20, 3.20};

// cellTemp reads the ADC sample and converts it to the measured temperature.
//
class cellTemp {
public:
  cellTemp(uint8_t Apin=A0) : ADCpin{Apin}
  {
  };
  int ReadTemp() {
    return ((analogRead(ADCpin) * 5.00 / 1024) - 0.5) * 100;
  };
private:
  uint8_t ADCpin;
};

// cellVoltage is a descendant of the INA219 sensor class. It reads the absolute 
// voltage, i.e. 6.4V for the 2nd cell and 9.6V for the third etc.
//
class cellVoltage : public Adafruit_INA219 {
public:
  cellVoltage(uint8_t INAaddr=0x40) : Adafruit_INA219{INAaddr}
  {
    begin();
    setCalibration_16V_400mA();
  };
  float ReadVoltage() {
    return getBusVoltage_V();
  };
private:
};

// cell inherits from both cellTemp and cellVoltage. 
//
class cell : public cellTemp, public cellVoltage
{
public:
  cell(uint8_t cellNr=0, uint8_t pinTemp=A0, uint8_t addrINA=0x40) : cellId{cellNr}, cellTemp{pinTemp}, cellVoltage{addrINA}
  {    
  };
  float ReadCellVoltage(float offset)
  {
    measuredVoltage = ReadVoltage();
    cellVoltage = measuredVoltage - offset;
    return cellVoltage;
  };
  float getMeasuredVoltage()
  {
    return measuredVoltage;
  };
  float getCellVoltage()
  {
    return cellVoltage;
  };
private:
  uint8_t cellId;
  float measuredVoltage;
  float cellVoltage;
  bool ChargeError;
  bool ChargeWarning;
  bool DischargeError;
  bool DischargeWarning;
};

// battery_4S is the object for a battery with four cells in series. It manages the four cells it gets passed to it's constructor
//
class battery_4S{
public:
  battery_4S(const cell cell0, const cell cell1, const cell cell2, const cell cell3) : c0{cell0}, c1{cell1}, c2{cell2}, c3{cell3}
  {
    c0.ReadCellVoltage(0.0);                        // first cell voltage has no voltage offset
    c1.ReadCellVoltage(c0.getMeasuredVoltage());    // second cell voltage needs first cell measurement substracted
    c2.ReadCellVoltage(c1.getMeasuredVoltage());    // third cell voltage needs second cell measurement substracted
    c3.ReadCellVoltage(c2.getMeasuredVoltage());    // fourth cell voltage needs third cell measurement substracted
  };
private:
  cell c0;
  cell c1;
  cell c2;
  cell c3;
};

// create global variables

// every LiFePO4 cell or group of parallel cells get their own cell object here
//
cell cell0(0, cell0pinTemp, cell0addrINA);
cell cell1(1, cell1pinTemp, cell1addrINA);
cell cell2(2, cell2pinTemp, cell2addrINA);
cell cell3(3, cell3pinTemp, cell3addrINA);

// the battery object is created and receives the cells as parameters
//
battery_4S house(cell0, cell1, cell2, cell3);

// the display object is created
//
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Instance the RTC
//
RtcDS3231<TwoWire> Rtc(Wire);

void wakeUp()
{
    // dummy interrupt service routine
}

void setup() {
  Wire.begin();                                       // initialize i2c communications
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);     // initialize display
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextWrap(false);
  display.setTextSize(2);
  display.setCursor(0, 0);
  display.println("  yaBMS   ");                      // print static text
  display.setTextSize(1);
  display.setCursor(0, 20);
  display.println("Cell0:");
  display.setCursor(0, 30);
  display.println("Cell1:");
  display.setCursor(0, 40);
  display.println("Cell2:");
  display.setCursor(0, 50);
  display.println("Cell3:");
  display.display();                                  // refresh display

  // set the interupt pin to input mode
  pinMode(RtcSquareWavePin, INPUT);

  //--------RTC SETUP ------------
  Rtc.Begin();
  RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
  if (!Rtc.IsDateTimeValid()) 
  {
    Rtc.SetDateTime(compiled);
  }
  if (!Rtc.GetIsRunning())
  {
    Rtc.SetIsRunning(true);
  }
  Rtc.Enable32kHzPin(false);
  Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeAlarmBoth); 
}

void loop() {
  RtcDateTime alarmTime = Rtc.GetDateTime() + BatteryTestInterval;    // Alarm 1 set to when the hours, minutes, and seconds match
  DS3231AlarmOne alarm1(
            alarmTime.Day(),
            alarmTime.Hour(),
            alarmTime.Minute(), 
            alarmTime.Second(),
            DS3231AlarmOneControl_HoursMinutesSecondsMatch);
  Rtc.SetAlarmOne(alarm1);
  Rtc.LatchAlarmsTriggeredFlags();                                    // throw away any old alarm state before we run
  attachInterrupt(RtcSquareWaveInterrupt, wakeUp, FALLING);           // setup external interupt 

  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);                // Enter power down state with ADC and BOD module disabled.
    
// Apparently we aren't sleeping anymore
  detachInterrupt(RtcSquareWaveInterrupt);                            // Disable external pin interrupt on wake up pin.
    
// Read sensors etc.

}
s/v Jedi is offline   Reply With Quote
Old 11-03-2020, 13:33   #197
Registered User

Join Date: Aug 2009
Location: oriental
Boat: crowther trimaran 33
Posts: 4,425
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by hzcruiser View Post
The on resistance of a MOSFET depends on a lot of factors, but as a ball park figure, it's around 150 mOhm for P-MOSFET, which is too high for currents above 10A.
There is no reason to use p channel mosfets
Quote:

The N-channel-MOSFETs have an Rds(on) of less than 10 mOhm (e.g. 4 mOhm for the IRF1404). The heat dissipation is R*I^2, or as an example, 400*R for 20A or 4W.
And just putting 5 or 10 in parallel is not as trivial as it may seem.
You can get mosfets with less than 1 mOhm in packages that can dissipate 4W without even a heatsink for $3. Even cheaper 60 cent mosfets in to220 package have resistances below 3 milliohm.

Putting 5 or 10 in parallel is relatively trivial, and with this you could handle 600 amps.

You can switch the bank using mosfets, a selector switch is not needed, and these also often have contact resistance higher than mosfets.

Quote:
Relays have a contact resistance of about 2 mOhm, but on top of that you need to connect to their tabs, just like you would to the FET. Hence one challenge with FETs is to get the current to the legs with as little losses as possible.
My point as you have verified is the contact resistance of the relay is higher than the on resistance of the mosfet. So you have more heat here than generated by the mosfet.

A chinese bms i got on ebay rated for 45 amps works on 12v lifepo4 battery running angle grinder through inverter is working fine. This bms cost $16 and does load balancing, over/under voltage and over current/temp protection. It uses all mosfet and has low on resistance.

Sorry but contactors/relays are obsolete. Maybe 10-15 years ago they were not. They cost more and have worse efficiency today.
seandepagnier is offline   Reply With Quote
Old 11-03-2020, 13:55   #198
Registered User

Join Date: Sep 2015
Posts: 445
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by boat_alexandra View Post
Sorry but contactors/relays are obsolete. Maybe 10-15 years ago they were not. They cost more and have worse efficiency today.
Lol.

a) Power contactors have an order of magnitude less resistance than you are discussing.

b) Wait until you see a silent cascade-closed failure on a FET array before you decide what is obsolete.
nebster is offline   Reply With Quote
Old 28-05-2020, 19:48   #199
Registered User
 
hzcruiser's Avatar

Join Date: Aug 2008
Location: Sydney, Australia
Boat: Roberts 45
Posts: 1,039
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by s/v Jedi View Post
Did some more work on the code:

- added a third "alert" level
- created a struct type variable for the settings that can be saved in EEPROM
- added support for real time clock incl. interrupts
- added power saving support
Sorry for the late reply, I was tied up sailing and then repairs (as it so happens on a boat).

Was wondering how the yaBMS is coming along?
__________________
Fair winds,
heinz

https://www.timantra.net
hzcruiser is offline   Reply With Quote
Old 29-05-2020, 01:12   #200
always in motion is the future
 
s/v Jedi's Avatar

Cruisers Forum Supporter

Join Date: Feb 2009
Location: in paradise
Boat: Sundeer 64
Posts: 19,323
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by hzcruiser View Post
Sorry for the late reply, I was tied up sailing and then repairs (as it so happens on a boat).

Was wondering how the yaBMS is coming along?
I have also been busy with many other boat projects so not much progress. Replacing the refrigeration aboard has turned into a mega project with half the galley torn out and redesigned
Attached Thumbnails
Click image for larger version

Name:	F91C636C-C071-4710-9478-ECA80BDDE2AA.jpg
Views:	102
Size:	411.4 KB
ID:	216032  
s/v Jedi is offline   Reply With Quote
Old 29-05-2020, 22:46   #201
Registered User
 
hzcruiser's Avatar

Join Date: Aug 2008
Location: Sydney, Australia
Boat: Roberts 45
Posts: 1,039
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by s/v Jedi View Post
I have also been busy with many other boat projects so not much progress. Replacing the refrigeration aboard has turned into a mega project with half the galley torn out and redesigned

Yes, saw that on FB, sure looked like a huge job well done! Also saw the comments about those handles and the possibility of bruising yourself.
__________________
Fair winds,
heinz

https://www.timantra.net
hzcruiser is offline   Reply With Quote
Old 29-05-2020, 22:52   #202
always in motion is the future
 
s/v Jedi's Avatar

Cruisers Forum Supporter

Join Date: Feb 2009
Location: in paradise
Boat: Sundeer 64
Posts: 19,323
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by hzcruiser View Post
Yes, saw that on FB, sure looked like a huge job well done! Also saw the comments about those handles and the possibility of bruising yourself.
Yes I guess everyone has drawers and doors without handles
s/v Jedi is offline   Reply With Quote
Old 30-05-2020, 07:50   #203
Registered User
 
hzcruiser's Avatar

Join Date: Aug 2008
Location: Sydney, Australia
Boat: Roberts 45
Posts: 1,039
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by s/v Jedi View Post
Yes I guess everyone has drawers and doors without handles

__________________
Fair winds,
heinz

https://www.timantra.net
hzcruiser is offline   Reply With Quote
Old 19-06-2020, 02:00   #204
Registered User

Join Date: Nov 2014
Location: Germany
Boat: Beneteau Sense 43
Posts: 176
Re: Designing yet another BMS (yaBMS)

Quick question: after reading this interesting thread I was wondering where I can find the yaBMS documentation. Does a github project or a website exist? (No, I am not on Facebook and will not join.)

Background: I already have a BMS solution, but I need a SignalK compatible, inexpensive, low power and small battery cell monitor which I can add to our three 4S LiFePo4 banks.

I figured no such thing already exists, so I am about to build one myself. After initial thoughts about the ADS1115 (where I came to the same conclusion already discussed in this thread - should have read it earlier...) I am now thinking about following the approach with the ATTiny85 and attaching them to a ESP8266 which then hooks into SignalK via SensESP.
I'd like to avoid duplicating work on the voltage sensor and possibly adopt your solution. Pointers welcome...
mbartosch is offline   Reply With Quote
Old 26-01-2021, 12:01   #205
Registered User

Join Date: Nov 2020
Boat: Starlight 35
Posts: 7
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by s/v Jedi View Post
Yes I guess everyone has drawers and doors without handles
s/v Jedi, Did you get any further with this?
gregcope is offline   Reply With Quote
Old 26-01-2021, 12:06   #206
Senior Cruiser
 
newhaul's Avatar

Cruisers Forum Supporter

Join Date: Sep 2014
Location: puget sound washington
Boat: 1968 Islander bahama 24 hull 182, 1963 columbia 29 defender. hull # 60
Posts: 12,245
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by s/v Jedi View Post
Yes I guess everyone has drawers and doors without handles
Actually yes finger holes and grooves

https://www.westmarine.com/buy/white...pack--12482964
Attached Thumbnails
Click image for larger version

Name:	12482964_2_1500.07122018100016.jpg
Views:	65
Size:	103.3 KB
ID:	231315  
__________________
Non illigitamus carborundum
newhaul is offline   Reply With Quote
Old 26-01-2021, 17:17   #207
always in motion is the future
 
s/v Jedi's Avatar

Cruisers Forum Supporter

Join Date: Feb 2009
Location: in paradise
Boat: Sundeer 64
Posts: 19,323
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by gregcope View Post
s/v Jedi, Did you get any further with this?
No, I did not... have been way too busy with other projects. Right now I’m running without BMS.

I did find another candidate for running the code on: WIO Terminal. It’s a neat little package complete with screen, push buttons and a bunch of sensors.
__________________
“It’s a trap!” - Admiral Ackbar.

s/v Jedi is offline   Reply With Quote
Old 28-01-2021, 08:41   #208
always in motion is the future
 
s/v Jedi's Avatar

Cruisers Forum Supporter

Join Date: Feb 2009
Location: in paradise
Boat: Sundeer 64
Posts: 19,323
Re: Designing yet another BMS (yaBMS)

Some things have changed since I started this project. For starters, I ended up with eight cells in series instead of four. This cancelled my favorite solution of using the INA219 for voltage measurement as it can’t deal with the highest voltages of eight cells in series.

Also, it bothered me that it’s precision was limited by the 12-bit ADC aboard.

I have gone through all the options available including every path that includes galvanic isolation (voltage to frequency conversion would win that) but it becomes a bit involved to replicate that eight times, especially when isolated dc-dc converters are needed for each cell sensor.

In the end I have decided to come back to the simplicity of the Texas Instruments INA219 but another version, the INA226. This version ticks all the boxes: it allows up to 36V measurement, has a 16-bit ADC (0.5mV resolution), doesn’t require galvanic isolation and it is available in little break-out circuit boards that can be piggybacked on a PCB for $8 a piece: https://www.amazon.com/dp/B07T597W1J...v_ov_lig_dp_it

I’m gonna need more than eight I2C devices but iirc the Teensy3.2 has two I2C ports. I’m not sure yet if my little 1” display is gonna be big enough for 8 cells but I think it is. The Teensy also has a CANbus controller so I could add a tranceiver chip for a remote display and control unit. I got a WIO Terminal (check that out!) but don’t think it has CANbus.

We’re now Bahamas-bound but next return in Florida I’ll build the hardware and start actual testing on our new battery. Which works great
__________________
“It’s a trap!” - Admiral Ackbar.

s/v Jedi is offline   Reply With Quote
Old 28-01-2021, 09:46   #209
Registered User
 
Dsanduril's Avatar

Join Date: Aug 2011
Location: Petersburg, AK
Boat: Outremer 50S
Posts: 4,229
Re: Designing yet another BMS (yaBMS)

Just curious, as I'm starting down the same road, have you looked at anything like Analog Devices ADBMS6817 (datasheet)? Can monitor 8 cells at 16-bit, has an additional 7 GPIO pins that can be used for temperature probes. Uses SPI, so that changes things on the controller side a bit.

Their whole solution includes an additional Coulomb counter for SoC and current measurement and an SPI isolator so you can have the battery-side comms completely isolated from the controller side.

Overall seems like a pretty slick configuration. Only thing I see that I don't want is the cell balancing, but it appears it can be turned off.
Dsanduril is offline   Reply With Quote
Old 28-01-2021, 11:13   #210
always in motion is the future
 
s/v Jedi's Avatar

Cruisers Forum Supporter

Join Date: Feb 2009
Location: in paradise
Boat: Sundeer 64
Posts: 19,323
Re: Designing yet another BMS (yaBMS)

Quote:
Originally Posted by Dsanduril View Post
Just curious, as I'm starting down the same road, have you looked at anything like Analog Devices ADBMS6817 (datasheet)? Can monitor 8 cells at 16-bit, has an additional 7 GPIO pins that can be used for temperature probes. Uses SPI, so that changes things on the controller side a bit.

Their whole solution includes an additional Coulomb counter for SoC and current measurement and an SPI isolator so you can have the battery-side comms completely isolated from the controller side.

Overall seems like a pretty slick configuration. Only thing I see that I don't want is the cell balancing, but it appears it can be turned off.
I have been eying the 6804. My big worry is soldering that $20 IC and how many attempts I need for one to survive
There is an evaluation board but that costs $150. Also, you should check out this project: https://www.instructables.com/Arduin...gement-System/

I may try it anyway as I’ve been watching some SMT soldering videos and got myself a new soldering station so I have a better chance at it :-)
__________________
“It’s a trap!” - Admiral Ackbar.

s/v Jedi is offline   Reply With Quote
Reply

Tags
Arduino, BMS, lifepo4


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modern Yet Cheap - Bluewater Worthy Yet Fast ? kman07 Dollars & Cents 21 31-05-2019 10:10
Yet another LFP and BMS build tanglewood Lithium Power Systems 0 19-11-2018 07:40
LiFe(Y)PO4 BMS Dessign - good reading for DIY BMS developers CatNewBee Lithium Power Systems 10 20-09-2018 00:15
yet another cyclone Alan Wheeler General Sailing Forum 3 04-03-2005 04:51
yet another new guy undrsol Meets & Greets 10 06-02-2004 08:17

Advertise Here


All times are GMT -7. The time now is 14:09.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.