Semi-DIY BMS: Active Balancer + Microcontroller

Cal

Solar Addict
Joined
Apr 28, 2020
Messages
684
I don't see why you can't add a resistor divider to Vbat to scale voltage below 36V.
 

BiduleOhm

Electronics Sorcerer
Joined
Jan 30, 2020
Messages
1,871
Location
France
Here's a first crack at adding low pass filtering to the current sensor. Based on the guidance in the ADS1115 data sheet about max filtering resistance value (NMT 1k), I started there. I fed both the Vref and Vout signals through 1k resistors, and then tried a bunch of different capacitor value on the signal line. The plot below shows the effect of filtering on the measured values (measurement interval = 133ms, single sample per measurement here, so no 'digital' filtering). EDIT: I should add that all measurements are taken with a 30A charge coming from a Growatt inverter.

All four of the capacitor values show below have a significant effect. I believe the 10uF cap (red points) corresponds to a low-pass of 16hz, while the 47uF cap (orange points) would be 3.4hz. Not sure what I should be using as my lower limit for frequency. I imagine that I want to avoid filtering out any real/meaningful spikes in the current? So maybe 22hz / 7.2hz is a good balance?

Well, you can't really design a filter by trying random values ^^

First you need to know your sampling rate, because that will determine the limit you must be under to not alias. Then you need to know what is the highest frequency (or transient lowest duration since we're talking current measurement here) you want to be able to measure.

Calculating the filter values after that is very easy, but you really need to know them to be able to do it ;)


Another thought is to make sure you aren't creating a peak charge circuit by having too large a capacitor/resistor ratio. That would negatively effect the accuracy, by skewing it higher. I am not sure what the internal circuitry looks like on the current sensor, so it may not be an issue.

The datasheet says a few Ohms of output impedance so that wouldn't be a problem ;)


Anything else I should look at to make the RC filter more effective? I'm currently using cheep electrolytic caps. Would a different cap type behave differently?

Yes, for example you can split the filter into two to have a better slope, and you definitely don't want to use electrolytics here. But all that is to be done only after you determined what I said just above, else it would like putting paint before the house is built...
 

Luthj

Photon Sorcerer
Joined
Jul 1, 2020
Messages
954
By split in two I assume you mean a two stage filter?

1615931690065.png

schroederjd, you seem to have a handle on what you need to do. There are a number of good tutorials for designing one (or just about any circuits II coursebook), and they are pretty easy to tune. Determine your target frequency, and your desired sample rate. The rest is just a bit of math.

My initial thoughts is that you don't need to get too deep into the weeds here. Anything in the ball park should result in a acceptable result. While trial and error isn't ideal, you can get pretty close that way. But I am not an expert by any means!
 

BiduleOhm

Electronics Sorcerer
Joined
Jan 30, 2020
Messages
1,871
Location
France
By split in two I assume you mean a two stage filter?

1615931690065.png

Yes, exactly ;)

NB: of course in that case you need to divide the resistor value by 2, so 510 Ohms here, and that means multiplying the capacitor value by 2 too. But having twice the slope thanks to that is a good ROI I think.

For the caps I'd go with ceramic X7R (or C0G if you want to get really fancy) and 10 V or more because of capacitance reduction with DC biais (not a problem with C0G tho).

For example with 510 Ohms and 47 µF the fc is 6.6 Hz and the step response time to 99 % is 0.11 s (and 0.47 s to 99.99 %). BTW a very nice calculator for RC filters: http://sim.okawa-denshi.jp/en/CRtool.php ;)


My initial thoughts is that you don't need to get too deep into the weeds here. Anything in the ball park should result in a acceptable result. While trial and error isn't ideal, you can get pretty close that way. But I am not an expert by any means!

Yep, I would go for something around a few Hz for the fc, it should be well below the sampling frequency and more than high enough to catch everything you want to capture.
 
Last edited:

schroederjd

Solar Addict
Joined
Nov 12, 2020
Messages
175
Thanks for the feedback guys. Yeah, I definitely understand that the "guess and check" method isn't how this kind of stuff should be done, but when you're learning as you go, it helpful (and it's fun!).
First you need to know your sampling rate, because that will determine the limit you must be under to not alias. Then you need to know what is the highest frequency (or transient lowest duration since we're talking current measurement here) you want to be able to measure.
Sorry if this is a stupid question, but what exactly do we mean by 'Sampling Rate' in this context? The interval at which I'm collecting data, or the 'output data rate' of the ADS1115? My plan is to collect data at 1 sec intervals (possibly 500ms), but I may sample multiple times at each interval for smoothing purposes.
 

BiduleOhm

Electronics Sorcerer
Joined
Jan 30, 2020
Messages
1,871
Location
France
Sorry if this is a stupid question, but what exactly do we mean by 'Sampling Rate' in this context? The interval at which I'm collecting data, or the 'output data rate' of the ADS1115? My plan is to collect data at 1 sec intervals (possibly 500ms), but I may sample multiple times at each interval for smoothing purposes.

It's the rate at which the ADC runs (at that's configurable, see the datasheet for more info), not the rate after averaging, etc. (that would be the measurement rate or something else, but not the sampling rate).

That means you have a bit less than 500 ms per measurement, let's say 400 ms to be safe, and so if you sample at 128 S/s for example that means you can average around 50 samples which should be plenty enough.
 

schroederjd

Solar Addict
Joined
Nov 12, 2020
Messages
175
Hi everyone, Quick update, along with a Op-Amp related question.

I tried out the 'split' RC low-pass filter, and wow did that make a difference. I can basically run it with no digital filtering at this point the noise is so low. And that's with the cheep electrolytic caps. I've ordered a few ceramic caps. We'll see what those do when they come in.

Regarding the Op Amp: I went ahead and ordered an OPA198 for use in my pack voltage sensing circuit. After much reading, I'm starting to get a handle (top level) on how to set up a voltage follower, but I wanted to confirm a couple things: First, based on the data sheet, the OPA198 can be used with a single supply, and it's 'rail-to-rail'. The recommended operating range for Vs is 4.5 to 36V. So, does that mean I can use +5V for V+ and ground for V-, as long as my input voltage is well within that range? Or do I need to plan for supplying the op-amp with >5V?

BiduleOhm, I noticed a circuit in your schematic that seems to produce a 'dual supply' of +12V and -12V. Is that for powering all the op-amps?
 

BiduleOhm

Electronics Sorcerer
Joined
Jan 30, 2020
Messages
1,871
Location
France
tried out the 'split' RC low-pass filter, and wow did that make a difference. I can basically run it with no digital filtering at this point the noise is so low. And that's with the cheep electrolytic caps. I've ordered a few ceramic caps. We'll see what those do when they come in.

Perfect ;) never fix in software what you can fix better in hardware 😁

However I still recommend to do some averaging to have a better resolution. It's almost free so why not.


First, based on the data sheet, the OPA198 can be used with a single supply, and it's 'rail-to-rail'. The recommended operating range for Vs is 4.5 to 36V. So, does that mean I can use +5V for V+ and ground for V-, as long as my input voltage is well within that range? Or do I need to plan for supplying the op-amp with >5V?

NB: I recommended the 189, not the 198, so I'm not sure if it's just a typo or if you ordered the wrong one but you might want to check that.

It has a rail-to-rail output but the inputs only include ground, and they can only go up to (+Vcc - 2.5) V. So if you want to put 5 V in an input you need to power it with at least 7.5 V. Sorry, I forgot to mention that earlier.

Note: all op-amps can be powered by a single supply or a dual supply. They don't care if they get 24 V or + and - 12 V for example, all that changes is where your system ground is, but from the op-amp perspective it is powered by 24 V in both cases.


BiduleOhm, I noticed a circuit in your schematic that seems to produce a 'dual supply' of +12V and -12V. Is that for powering all the op-amps?

Yes, I use a DC/DC converter (U930 on the schematic) to take the battery voltage and generate the main +12 and -12 V rails, but since it's quite a nice converter it's also somewhat expensive. In your case it should be cheaper to generate a 9 or 12 V rail from the existing 5 V with a DC/DC converter, or to use another method depending on what power sources you already have in your system (just thinking that since you only need a few mA you could use a high voltage linear regulator fed from the battery).
 

schroederjd

Solar Addict
Joined
Nov 12, 2020
Messages
175
However I still recommend to do some averaging to have a better resolution. It's almost free so why not.
Makes sense. I'll likely keep averaging, but keep the sample size fairly small to minimize the total sampling time.
NB: I recommended the 189, not the 198, so I'm not sure if it's just a typo or if you ordered the wrong one but you might want to check that.
Yup, that's a typo...I ordered a 189.
It has a rail-to-rail output but the inputs only include ground, and they can only go up to (+Vcc - 2.5) V. So if you want to put 5 V in an input you need to power it with at least 7.5 V. Sorry, I forgot to mention that earlier.
So, I'm only planning to use this op-amp for the pack voltage measurement. If I assume the range I want to measure is 40 - 60V (2.5V - 3.75V at the cell level), I could use a divider with an R1:R2 ratio of 25:1, which would put my Vout (from the divider) range of 1.53 - 2.31V (which keeps me in the range of -Vcc to +Vcc - 2.5). With the 25:1 divider, and using the ADS1115 in the +/- 4.096 (1x Gain) range, my resolution would be 3.25 mV (0.125 mV/step * 26). That seems like it should satisfy my functional requirements. In that case, it sounds like I should be ok supplying the Op-amp with the same 5V supply that I'm using to power the rest of my components.

For reference, I purchased a Mean Well Isolated DC/DC converter to supply the 5V components. Let me know if I missed the mark on that one.

Yes, I use a DC/DC converter (U930 on the schematic) to take the battery voltage and generate the main +12 and -12 V rails, but since it's quite a nice converter it's also somewhat expensive. In your case it should be cheaper to generate a 9 or 12 V rail from the existing 5 V with a DC/DC converter, or to use another method depending on what power sources you already have in your system (just thinking that since you only need a few mA you could use a high voltage linear regulator fed from the battery).
If I've missed the mark on my calculations above, I'll look into adding another DC/DC converter (or linear voltage regulator) to power the op-amp.

Once again, thank you for the input!
 
Last edited:

BiduleOhm

Electronics Sorcerer
Joined
Jan 30, 2020
Messages
1,871
Location
France
Yup, that's a typo...I ordered a 189.

Ok, perfect ;)


So, I'm only planning to use this op-amp for the pack voltage measurement. If I assume the range I want to measure is 40 - 60V (2.5V - 3.75V at the cell level), I could use a divider with an R1:R2 ratio of 25:1, which would put my Vout (from the divider) range of 1.60 - 2.40V (which keeps me in the range of -Vcc to +Vcc - 2.5). With the 25:1 divider, and using the ADS1115 in the +/- 4.096 (1x Gain) range, my resolution would be 3.125 mV (0.125 mV/step * 25). That seems like it should satisfy my functional requirements. In that case, it sounds like I should be ok supplying the Op-amp with the same 5V supply that I'm using to power the rest of my components.

Yep, it should work fine ;)

With averaging you'll have even higher resolution (but not higher accuracy).


For reference, I purchased a Mean Well Isolated DC/DC converter to supply the 5V components. Let me know if I missed the mark on that one.

Ok, then if you really need another rail in the future the best is to use another small DC/DC converter fed from the 5 V rail.
 

schroederjd

Solar Addict
Joined
Nov 12, 2020
Messages
175
Another quick update. I still haven't placed the order for the blancer through Heltec. Since Heltec doesn't have this specific item on the website store, I have to go direct through the rep. The time change is dragging things out terribly. On Monday, I asked him to paypal me the invoice, on Tuesday, he asked for my shipping address, which I provided a few hours later, this morning, he asked "USA, right?" (yes, I forgot to put USA on my address...), and again, I responded a few hours later. At this rate, I'll have the order placed sometime in 2022.

While waiting for the OpAmp and a few other components to come in, I've added a second ADS1115 to accommodate 4 temp sensors (2 for the pack, 1 for ambient, and 1 for the BMS). Was surprised how easy it was to add another slave to the I2C bus. Just needed to change the address of the second ADS by bridging the ADDR and SCL pins. I do have a multiplexer handy. Not sure on the pros/cons of using a 2nd ADS vs. MUX.

Photo of the current breadboard layout is below. The 4-pin Molex housing comes from the current sensor. The purple/green pairs go to two NTC thermistors. The yellow and black wires go to the pack main + and - for voltage sensing. Getting pretty full. I've also taken a crack at drawing up the circuit in Eagle. That took a bit of figuring out. Schematic is attached for your interest, but it has a long way to go.

1616099285739.png
 

Attachments

  • semiDIY_BMS.pdf
    20 KB · Views: 10

schroederjd

Solar Addict
Joined
Nov 12, 2020
Messages
175
If your objective is to just measure current and battery voltage then INA226 might be a great alternative. It contains a 16-bit adc, so current measurements are very accurate when using a shunt.

I ended up including an INA228 chip with my latest mouser order, just to try it out. The 228 seems to be pretty close in specs to the 226, just with an 80V upper voltage limit. I couldn't find any of the TI 80V chips on a pre-soldered breakout, so I'll have to try my hand at soldering it on to a DIP breakout myself. No experience with soldering anything that small, so very high likelyhood I'll botch it and move on...

Thanks again for the suggestion. If I can get it working, this certainly does provide a simple solution for current and voltage measurement. The only obstacle is that I'll need to adapt it for hall effect sensor (rather than shunt). Not sure how that will work, but should be fun to try.
 
Last edited:

BiduleOhm

Electronics Sorcerer
Joined
Jan 30, 2020
Messages
1,871
Location
France
Look up drag soldering tutorials ;)

Well, the whole point of using a INA22x is to be able to use a simple and cheap shunt instead of something else.
 

schroederjd

Solar Addict
Joined
Nov 12, 2020
Messages
175
Look up drag soldering tutorials ;)

Well, the whole point of using a INA22x is to be able to use a simple and cheap shunt instead of something else.
Understood. I really just bought it as a backup plan in case I can’t get all these separate circuits to work as needed. In that case, I may end up abandoning the Hall effect sensor and going with a shunt.
 

mnm1501

New Member
Joined
Nov 29, 2020
Messages
12
Hi, I am also looking into how to pass my battery info to my Growatt SPH5000 Hybrid inverter. Have you guys had a look at the DIYBMS (https://github.com/stuartpittaway/diyBMS), currently configuring these to replace the DALY BMS currently installed on my 4 x 48V packs & want to build a concentrator to monitor the 4 packs & push the data to the Growatt Inverter. I have a tonne of MODBUS experience having worked in the metering & software space for the last 12 years. I am now starting to play with Canbus hopefully using a ESP8266 or ESP32 as the brains to emulate the Pylontech parameters that seem to be the most generic Canbus for different inverters. Would love to see who out there is heading down a similar path.
 

schroederjd

Solar Addict
Joined
Nov 12, 2020
Messages
175
Hi, I am also looking into how to pass my battery info to my Growatt SPH5000 Hybrid inverter. Have you guys had a look at the DIYBMS (https://github.com/stuartpittaway/diyBMS), currently configuring these to replace the DALY BMS currently installed on my 4 x 48V packs & want to build a concentrator to monitor the 4 packs & push the data to the Growatt Inverter. I have a tonne of MODBUS experience having worked in the metering & software space for the last 12 years. I am now starting to play with Canbus hopefully using a ESP8266 or ESP32 as the brains to emulate the Pylontech parameters that seem to be the most generic Canbus for different inverters. Would love to see who out there is heading down a similar path.
Hi mnm1501. Your timing is perfect. I took my first crack at communicating with my Growatt (SPF 3000 LVM 48P) yesterday, and realized very quickly that I have absolutely no idea what I'm doing. I have no experience with CANBUS or MODBUS, and to be honest, I'm not even sure which one the Growatt uses for BMS communication. I had originally planned to use the UART to CAN module that came with my BMS, but I'm now thinking that the Growatt uses RS485 (the manual provides very little detail, but the cable detail shows RS485A and RS485B connectors (not CAN-L and CAN-H). So, maybe I need a UART to RS485 Module? And does the growatt use the CANBUS protocol transmitted via RS485? Or maybe I just don't understand the distinctions between CANBUS, MODBUS, RS485, etc.

Well, you can probably tell from my questions that I'm a total novice, so any and all help with this would be greatly appreciated.
 

schroederjd

Solar Addict
Joined
Nov 12, 2020
Messages
175
So, after posting about my balancing issues on another thread, it was pointed out by several members that my core balance issue was likely not related the my BMS's low balancing current, but rather an issue with the bank itself. After analyzing some fairly strange individual cell voltage profiles during charging, I realized (with the help of Steve_S) that I likely had at least one bad connection. Turns out there was likely two, and after re-cleaning and re-installing those bars, I seem to have a much more stable pack.

So, all that leads me to a fairly significant change in my overall design: For the immediate future, I'm going to see if the TinyBMS's 150mA balance current is adequate, and design my "semi-DIY BMS" around using the TinyBMS for individual cell voltage monitoring and balancing. Still going to move forward with ESP32 as the main brains of the system, with protection features managed by the MCU (and in some cases, redundant protections via the BMS).

The big issue I still have with the TinyBMS is the current measurement. The ripple from the inverters results in terrible aliasing in the TinyBMS's current measurements (at least +/- 10%). Using my new found RC filtering knowledge (thanks BiduleOhm), I'm going to take a crack at adding a low pass filter to the TinyBMS's current sensor. I've already determined through a bit of experimentation the 'load impedance' (may not be the right term) of the BMS's ADC is too low to use a passive filter (even with < 100 ohm resistor in line, I see a measurable drop in signal voltage).

I've already tried out an active filter design using the OPA189 Op-Amp that I purchased for voltage measurements. It seems to work exactly as expected. The noise drops to almost zero using a target cut-off frequency of 3hz (4k7 ohm resistor + 10 uF ceramic cap). I could use some help selecting an appropriate Op-amp for this application. In trying to keep this as simple as possible, I would love to be able to supply the OpAmp using the 5V supply that powers the sensor. That way, I can simply put it in line with the sensor cable, which already has a 5V supply line. I also need a dual channel amp, as the sensor has separate low and high range signals.

After poking around mouser, I stumbled upon the MCP6292-E/P. This device has a common mode input voltage range of Vdd + 300mV to Vss - 300mV. So, with a +5V supply, that's 0.3 - 4.7V input range (the TinyBMS's current sensor has a signal range of 0.5 - 4.5V). It's also available with dual inputs in a DIN package. My problem is that I don't understand Op-Amps well enough (at all, really...) to know if the other key specs are aligned with the application.

Any input would be appreciated.
 

BiduleOhm

Electronics Sorcerer
Joined
Jan 30, 2020
Messages
1,871
Location
France
I also need a dual channel amp, as the sensor has separate low and high range signals.

An op-amp already has differential inputs. Check this section for more info on that ;)

If you want a nice op-amp with true rail-to-rail inputs and output, low Vos, low Ib, etc... I recommend the OPA991 (also available in dual and quad versions if needed). The one you selected has quite a high Vos, at worst it'll add a 0.2 % error on your current measurement just because of that.
 

schroederjd

Solar Addict
Joined
Nov 12, 2020
Messages
175
An op-amp already has differential inputs. Check this section for more info on that ;)
The LEM DHAB S/133 sensor that came with my BMS is a dual range sensor (0-75A, and 0-750A), so it actually has two completely independent signal output lines: one with a sensitivity of 27mV/A, and one with 2.7mV/A). That’s why I think I need a dual input op-amp. I’ll read through your linked info to make sure I’m not missing something on that.

I’ll check out the OPA991. Thanks for the recommendation!
 
Top