Author Topic: Designing the $5 _charge_ controller  (Read 2201 times)

0 Members and 1 Guest are viewing this topic.

elt

  • Sr. Member
  • ****
  • Posts: 328
Designing the $5 _charge_ controller
« on: August 22, 2007, 10:24:19 PM »
I wrote in this story about my home-built two stage dump controller. The notion was that it had a float mode and an automatic charge mode, though because it has no notion of what the batteries' state of charge is, it doesn't really known when the batteries need a charge or when they only needed to be floated. My notion was that the "stupid" auto-charge mode was better than nothing because it would always charge the battery more than just a float charge and nearly everyone agrees (!) that just float-charging shortens battery life.


The biggest problem, it seems, with making a "real" charge controller is that electronics can't really determine the state of charge. In discussion on that thread, Samoa suggested...


SamoaPower wrote:



Another possibility is to measure Amp-Hours in and out of the battery and simply replace what's used, allowing for charge efficiency, which requires 10-15% more put in than is removed. I would also go beyond this to give a moderate overcharge - sort of like a mini-equalization charge on every cycle.


elt wrote:



I like the notion of recording amps [hours] out and putting them back in (plus a little more for the efficiency factor) though, again, I'm not sure how to tell in general whether a battery is fully charged. The notion of doing what should be a slight overcharge every time solves that as eventually after a few or many cycles the battery would become fully charged.


Wonderful! The problem now is just determining the charge efficiency... whether the batteries really got charged after a charge cycle. I suggest that that can be done the old fashion way (measuring specific gravity of the electrolyte) until you zero in on the number and then you can walk away, perhaps checking on the batteries periodically to see if the numbers are changing though the life cycle of the battery.


Now the charge controller is as simple as counting amp-hours in and amp-hours out and switching the dump controller from float and charge modes as needed.


Here's an overview of what I'm thinking of -




The controller uses two analog to digital converters to sense the (current dependent) voltage drop across two battery cables or shunts. Since most systems have battery cables in them anyway, you can use them for free. The only technical requirement here is that the system wiring needs to be split into separate "source" and "load" sides and the controller's ground needs to be on the "load" side (so that the ADC inputs are always positive with respect to the controller's ground; I don't know of any microprocessors that can measure negative voltages.)


Based on the accumulated amps-hours in and amp-hours out, the controller will signal the dump load to switch from float mode to charge mode.


Note that if battery cables on both the source and load sides are the same, you don't need to do any calibrations since the scale of "x millivolts drop per amp" will be the same on both sides, you only need to subtract or add the ADC readings to get the net charge (or discharge.) If you use different sizes or lengths of battery cables then you will need some sort of "user interface" on the controller to program the relative values of the ADC readings on each cable.


Working with other dump controllers:


I've only really seen two other systems.



  1. There's Amanda's multistage dumper; it already has two stages and uses a count down timer to select which stage is being used. Instead of using the counter to switch between modes, the float/charge signal from the charge controller could be used to select the charge mode.
  2. There's the op amp based controller in Hugh's book and other places... I'm not an "analog guy" so someone else is better suited to suggest what changes to make; however, I have used digital signals to switch resistors in and out to make a pseudo- digital to analog converter so I'm pretty sure it wouldn't involve more than two resistors per op amp to turn the controller into a two stage controller... it would just take me a long time to figure it out.


Practical circuit:


I like the tinyAVR chips from Atmel. Two things they have (on some chips) that really help in this case are the built in 20x gain amplifiers on the inputs of the ADCs, useful because the voltage drops on the battery cables or shunts are pretty low and prescaling them will give much more accurate readings, and the built in temperature measurement that can be used for temperature compensation.


My favorite little 8 pin device (the ATTINY85) is a few pins short of handling the all the inputs and outputs needed for this application but the 14 pin equivalent, the ATTINY84 has plenty to do the job and enough memory to add a serial port data logging function as well.


So, the entire charge controller might consisted of the tiny84 (about $3 USD), a voltage regulator, a button and a LED (for the "user interface" and a board to put the parts on... probably cost between $5 and $10 depending on whether you have to buy a switch and if you want to put an RS232 driver on it for data logging.


Rather using an external temperature sensor to measure the temp of thee battery itself, I'd mount the microcontroller chip on the back of the circuit board and use silicone glue to glue it directly to a battery case.


... as always, input or suggestions are appreciated!


- Ed.

« Last Edit: August 22, 2007, 10:24:19 PM by (unknown) »

elt

  • Sr. Member
  • ****
  • Posts: 328
Re: Designing the $5 _charge_ controller
« Reply #1 on: August 23, 2007, 08:36:35 AM »
Okay, I had that backwards... we had some wind this morning and the DVM on my battery wire was giving negative reading. I guess the way to think of is that the voltage "drop" across the ground wires actually pulls up the ground values with respect to the positive side of the battery.


The point is only one of implementation because the microprocessor can only handle positive voltages on its analog to digital converters. So instead of hooking up the charge controller on the load side of the system, it should be hooked up to the source side of the system.


Here's the corrected architecture:


That also suggests to me that if you run a ground wire along with the float/charge signal to the dump controller that you should put a resistor in series with the ground line to allow for the difference in ground values. (I don't think you'd need to go to an optoisolator until you had more than .5 volt difference. For example, 50 amps of source and 200 amps of load would only be .25 volts and that would be okay.)


Some other thoughts:


Another thread pointed out the relatively large resistance change with temperature. Sure enough, the difference over a 50C temperature range will be about 20%. The formula for copper is


    percentage change in resistance = .00427 * difference in degrees centigrade.


I think that is another good reason to use the same sized cable on both the source and load sides. In that case, change in resistance cancels out (read next sentence) so you still only have to count "units" in and units out. The trouble there is you might use energy at a different temperature than you make it. For example, perhaps you use more energy during the day when it's warmer and charge more at night when it's cooler ... every 10 degrees C would give about a 5% error. While it might be possible to ignore this, there's no particular need to. It's just another number for the microprocessor to multiply while is calculating amp-hours, it's no big deal to take it (temperature) into account and that helps if you want to do data logging.


"Self-heating" in the shut wires was also brought up. For example, if you are using a one milliohm ground cable as shunt and putting 100 amps through it, you will have a .1 volt drop across the wire and it will consume 10 watts. I don't know how much that will heat the wire but my gut feeling is that with that length of that thick of a copper cable that the answer is "not much" and that the self heating factor can be ignore. Perhaps someone with more experience will comment on that.


That does imply, however, that two temperature sensors are needed. One to measure ambient temperature and one to measure battery case temperature. One could add, say, an LM35 for remote temperature sensor but thinking about it, what would the charge controller module do with the battery case temperature if it knew it? Unless the charge controller module can program the dump controller's voltages, there's not really anything that it can do with battery case temperature. I think it's something that the dump load controller (which manages float and charge voltages) should deal with. (And that means that there's no need to glue the charge controller's microprocessor to the battery case to use it's internal temperature sensor, it can be placed in a vented case to measure ambient temperature.


 - Ed.

« Last Edit: August 23, 2007, 08:36:35 AM by elt »

boB

  • Sr. Member
  • ****
  • Posts: 389
  • Country: us
    • boB
Re: Designing the $5 _charge_ controller
« Reply #2 on: August 23, 2007, 12:44:04 PM »
Ed, how are you programming your AT Tiny parts ???

I ordered a bunch of the 28 pin Tinys for a project for my son

and looks like they won't program with the usual AVR  ISP serial system

and it looks like a PATA to make one.  (sort-of)  They were only about

1 buck each from Digikey.  If I order some AVR ATMega8L's, I won't need

these much anymore.  It'd be nice to just be able to use them easily.


boB

« Last Edit: August 23, 2007, 12:44:04 PM by boB »

elt

  • Sr. Member
  • ****
  • Posts: 328
Re: Designing the $5 _charge_ controller
« Reply #3 on: August 23, 2007, 02:20:16 PM »
hi boB,


I mostly use a Dragon though I have and STK500 and others. I really like the source level debugging that the Dragon offers on chips that support debugWire.


Unfortunately, the tiny28's you have don't have SPI modules so they can't support serial programming. There are DIY parallel programmer plans on the net but I'd rather build systems than programmers too...


If you're looking at the mega8, can I suggest the mega88? It's more modern, costs the same and has both 4k and 16k versions available (and supports debugWire.)


When I'm just buying a few, I usually buy from whoever I'm getting the rest of the parts from to save on shipping. Generally though, I find Avnet less expensive than Digikey (or Mouser, they are carrying AVR now.)


Hope that helps.


- Ed.

« Last Edit: August 23, 2007, 02:20:16 PM by elt »

scottsAI

  • Hero Member
  • *****
  • Posts: 884
Re: Designing the $5 _charge_ controller
« Reply #4 on: August 23, 2007, 11:11:25 PM »
Hello elt,


Maybe this will help:

http://www.sandia.gov/pv/docs/PDF/batpapsteve.pdf


Have not read in detail, seems to cover your efficiency question?


Have fun,

Scott.

« Last Edit: August 23, 2007, 11:11:25 PM by scottsAI »

elt

  • Sr. Member
  • ****
  • Posts: 328
Re: Designing the $5 _charge_ controller
« Reply #5 on: August 24, 2007, 09:13:03 AM »
Thanks Scott, that was a great read. In addition to the efficiency question, it was very interesting to see the "what if you only have enough energy to do a partial charge" question addressed. I hope that someones studies that further and produces a chart or formula for that effect at other states of partial charge. At any rate, it does indicate to me that the charge controller can know when an equalization is needed due to undercharging. I have added another signal output on the charge controller (called "ALERT") to reflect that.


Here's a first pass at a schematic; I'm thinking that with all the discretes in the circuit that the cost might be up to six or seven dollars now.





Notes:

There's no single "GND" on the schematic, as indicated in the previous notes, the charge controller works on the "source ground" which is SOURCE- in the drawing.


Also, I've been no fan of adjustable voltage regulators but have been using lm217's in my mill circuits because of the large input voltage that they can take, much more than most fixed regulators.


I have put the full programming header for the AVR microprocessor in the schematic because it exposes the SPI interface. It might be possible to use the SPI interface for data logging. In that case I would put a resistor in the ground on that connector to keep the communications ground from messing up the readings of the other grounds.


 - Ed.

« Last Edit: August 24, 2007, 09:13:03 AM by elt »

scottsAI

  • Hero Member
  • *****
  • Posts: 884
Re: Designing the $5 _charge_ controller
« Reply #6 on: August 24, 2007, 05:36:04 PM »
Hello elt,


This one is better, maybe to complex:

http://www.bretagne.ens-cachan.fr/pdf/mecatronique/EnergiesRenouv/LeadAcidBattery_Gergaud_EPE2003.pd
f


I will look over the schematic this weekend, just got done at work.


Have fun,

Scott.

« Last Edit: August 24, 2007, 05:36:04 PM by scottsAI »

scottsAI

  • Hero Member
  • *****
  • Posts: 884
Re: Designing the $5 _charge_ controller
« Reply #7 on: August 25, 2007, 12:03:38 PM »
Hello elt,


The gain of 20x may be nice...

From the other post I remember 19mv, if that is full scale then the 20x isn't enough.

ADC will see 0.4v in = 20mv * 20 you need more gain like 250x.

Ideally; GAIN = 5 / full scale shunt voltage.

Dual/quad opamps are cheap. AD8607 or 9; offset is very low, Iq current is very low.

250 gain, can measure current full scale. Two resisters to set the gain. 4 resistors if including ground offset shifts (the voltage across the shunt) as difference amplifier.

The opamps can correct for signal direction.


Using two opamps can measure current in and out on the battery input, do not need two shunts.

One opamp with offset half scale allows pos and neg currents to be measured, resolution is halved, and more difficult to make accurate.

You do have two (shunt) cables, so the cost is the second wire back to the controller, both ways work.


The ground is not the battery?

Input to ADC are always referenced to gnd unless setup as differential inputs.

Ground needs to go to battery, then the other places to ADC.

As drawn along with the low gain the current into battery is derived from the current into load. Huge stack up of errors. Use the opamps for the gain and signal inversion of the neg input from the load.


Accuracy is king here. Measuring current in and out accumulating over time is an integration. Small errors accumulate become large errors over time. Some method must be determined to reset the accumulation to reduce the effect over time. Example: reset after a finishing charge.


To determine SOC Very important to measure battery temperature and measure voltage accurately.

Only measuring current / temperature I do not think you can determine when the battery is fully charged or even determine if a finishing charge is completed.


Ideally measure the fluid temperature in the battery, I like to measure one of the terminal post, metal goes directly into battery. If the current flow is high the post may get a little warmer than the fluid, I like this better then the insulated battery casing temperature which will have a long delay in the temperature reading.


SD memory works with SPI, for data logging makes it pretty easy to store lots of data.


Have fun,

Scott.

« Last Edit: August 25, 2007, 12:03:38 PM by scottsAI »

elt

  • Sr. Member
  • ****
  • Posts: 328
Re: Designing the $5 _charge_ controller
« Reply #8 on: August 25, 2007, 05:53:10 PM »
Hi Scott, thanks for the help!


You wrote:

Using two opamps can measure current in and out on the battery input, do not need two shunts.


I understand that "net" amps is enough for charge control. Being a newbie, though, I'm also interested in how much power I use vs. how much I make; one shunt won't tell me that.


I'm not op-amp savvy and limit myself to circuits examples I find. You wrote:


ground offset shifts (the voltage across the shunt) as difference amplifier.


I'm still stuck on the case that if the mill is sourcing current then that end of shunt/cable will be negative (and therefor outside of the "rail") of an op amp connected to battery ground. I also realize that this is a common condition, it's solved, and I'm "uneducated" with regard to the solution. But I don't get what you're saying... (I avoided the issue with the two cable/shunt setup but am always willing to learn!)


As drawn along with the low gain the current into battery is derived from the current into load. Huge stack up of errors.


The tiny84 not only has differential inputs but also is very flexible in allowing you to mix and match them and even reverse them under software control. For example, on one ADC reading I can set SOURCE- as the negative input and BATT- as the positive input and then on another reading I can set BATT- as the negative input and LOAD- as the positive input.


I think that the chip will do okay on resolution because it also has a selectable 1.1 volt reference internally. With a millohm wire, 50 amps is .050 volts, times 20, that's 1 volt. With 10 bit resolution, that's about 50 milliamp resolution. Above 55 amps, I can selectively switch to the 5 volt reference to get to 250 amps... it's a ridiculous thought but the turning off the gain amplifier would allow reading to 2000 amps! (If the ADC could read it before the cable melted...)


To determine SOC Very important to measure battery temperature and measure voltage accurately.


It's not my intention for the circuit to measure state of charge! I (the human being) will do that and then enter the number into the controller. The controller will then apply the charging efficiency algorithm to the net charge and compute the ongoing state of charge from there. The notions is that by slightly overcharging (or doing a "mini-equalization" each cycle as Samoa put it) that the battery will migrate towards a full charge even if my first entry of SOC is off a bit. Periodically, I'll check the SOC with a hydrometer and enter a correction into the controller... (That's the "$5" algorithm.)


Ideally measure the fluid temperature in the battery, I like to measure one of the terminal post, metal goes directly into battery.


Thank you for that suggestion. I've find what looks like an appropriate circuit in the LM34 app-notes. How do you thermally bond a sensor to a battery terminal and keep if from getting eating by fumes? Silicone or RTV?


SD memory works with SPI, for data logging


Another nice idea.


Thanks again,

 - Ed.

« Last Edit: August 25, 2007, 05:53:10 PM by elt »

scottsAI

  • Hero Member
  • *****
  • Posts: 884
Re: Designing the $5 _charge_ controller
« Reply #9 on: August 26, 2007, 09:22:23 AM »
Hello elt,


The nice thing about a micro once you have it in circuit many more things are possible.


Using two opamps can...

Since you want separate power in and out then this does not mater. Same with ground offset.


As drawn along...

Had not looked at the micro (have now), unusual for them to have gain or such a low voltage reference. Your math looks good, works for me!.


To determine SOC...

You do not measure it:-) you figure it out. Nice to be able to correct it like you said. But much easier for it to be reset by a finishing charge. I do not see voltage on the inputs. You really want that as an input. How will you input?


...fluid temperature...

You bring up an important question: fumes. To reduce maintenance looking at the flow rite watering system, still leaves the fumes. Looking into venting the cells outside directly, with a pipe or tubing (any body else done this?). The flooded battery will now be much like a SLA (sealed lead acid). I have not done this, the picture of the flow-rite for golf cart batteries had two vent holes, did not see a way to connect tubing to it. Back to temperature, clean the terminal well attach the sensor, the examples I have seen Actually attach it to an over sized spade lug on the cable, then cover it with wax. Be careful of silicon sealers any made with acetic acid (vinegar) will corrode the connection. Place the temperature sensor on the neg cable along with gnd connection using a thermistor, only adding 1 wire to get the remote temperature.


The years with the 130 cell battery, weekly measured the specific gravity of 4 cells, had a panel to measure any cell voltage along with an amp-hour meter. With this information we could predict the specific gravity within 2 points. (1.22x). The care and feeding of the battery had us intently discharging the battery at 1/800, when the discharge = 6.25% we recharged the battery. The battery was a stand-by battery, any deep discharge (25%?) required a finishing charge, or quarterly finishing charge.


Have fun,

Scott.

« Last Edit: August 26, 2007, 09:22:23 AM by scottsAI »

altosack

  • Jr. Member
  • **
  • Posts: 92
Re: Designing the $5 _charge_ controller
« Reply #10 on: August 26, 2007, 11:46:05 AM »
I think that the chip will do okay on resolution because it also has a selectable 1.1 volt reference internally. With a millohm wire, 50 amps is .050 volts, times 20, that's 1 volt. With 10 bit resolution, that's about 50 milliamp resolution. Above 55 amps, I can selectively switch to the 5 volt reference to get to 250 amps... it's a ridiculous thought but the turning off the gain amplifier would allow reading to 2000 amps! (If the ADC could read it before the cable melted...)


If you read your datasheet on the Tiny84 (I haven't read that one, but assume that the Tiny861 I have read is similar), I think you'll find that resolution goes down when you use the gain amplifier, and also when you use the 1.1v internal reference (the ADC is specified at 4V). IIRC, you will end up with 7 bits using both, not 10 bits anymore.


There is a trick you can use to increase the resolution, though. The AVRs ADC can do about 15,000 conversions per second, and you probably need somewhere in the neighborhood of a few tens per second. You can use something called "oversampling and decimation" to gain about 4 bits if you oversample 256X (8 bits). There is an application note from Atmel that explains this fairly well; look on their web site. You need a bit of noise on the signal to make this work, and leaving out the decoupling capacitor on the analog supply worked for me.


Best of luck,

Dave Voss

« Last Edit: August 26, 2007, 11:46:05 AM by altosack »

elt

  • Sr. Member
  • ****
  • Posts: 328
Re: Designing the $5 _charge_ controller
« Reply #11 on: August 26, 2007, 03:23:26 PM »
Hi Dave,


I went back to the data sheets; I missed that you shouldn't put more than 4 volts (or VCC-.5v) on the external reference... thanks for pointing that out!


I didn't read anywhere that you loose resolution with the internal 1.1 volt reference. I think that the issue there is accuracy since 1.1 volt source is not a precision reference. But it's the same reference for both the the source and the load so its value only matters when you want to convert to real world readings like "amps." But if you think of the readings as "charge units" then the accuracy of the reference doesn't matter (as long as it's voltage is constant!)


As I read it, the integral nonlinearity (INL) error might result in the SOC calculation only being good to 7 bits, but that's less than a 1% error and if this circuit does that then certainly I got my money's worth!


I've been doing 16x oversampling because I have number of channels to read and I've been thinking about the 10ms control loop I've been using in the PWM controller... you're probably right that can slow down the control loop to 100ms or so in this app and do more oversampling.


Thanks for the feedback!


- Ed.

« Last Edit: August 26, 2007, 03:23:26 PM by elt »