
\documentclass[11pt]{article}
%Gummi|065|=)
\usepackage{graphicx}
\usepackage{caption}
\title{\textbf{BatteryMonitorBoard}}
\author{Steak Electronics}
\date{}
\begin{document}

\maketitle

\tableofcontents

\section{Overview}

\section{Chip Hunting}
Need to find a chip for battery charging. Some sheets have been saved. I looked at TI primarily. Though considered one AD/LTC. BQ2954 is out of the question as its too complex in its application circuit. THe BQ2000 is a 8 pin DIP and seems like a good start. That will cover nicad/nimh, and lithium batteries.

Though the BQ2000 is a bit of a mess as well. Data sheet has a complex circuit. There is a simpler one here:
http://www.ti.com/lit/pdf/sluu007
and
https://electronics.stackexchange.com/questions/95970/how-to-use-battery-charge-controller-bq2002n
Regardless of the contents of that post, the fact is, the chip requires a lot of stuff.

https://www.st.com/content/ccc/resource/technical/document/datasheet/df/b9/e6/5b/ec/92/45/ed/CD00132951.pdf/files/CD00132951.pdf/jcr:content/translations/en.CD00132951.pdf
This chip: stc4054, is extremely simple. Limited to 1 lithium cell (so only 4.2 volts max) but application circuit is lean, and it has a shutdown pin, so you can turn off the charger. Price is the cheapest as well, at 1.50 for 1.

That looks hopeful. Why not multiple?
Need to remember to be careful of 4.1 lithium batteries. Most chargers are 4.2, and its easy to forget that there is a difference.

MCP73826 is another reasonable option. Slightly more complex, but not by much.
RT9526A is also simple. Let's start with the st chip.

Looks like the voltage on that pin should be between 1.2 and 2.4 in order to turn it off. Below 1.2 it is on, and monitoring current. Above 1.2 but below 2.4 it is off. above 2.4 it's putting 35ua into the battery. I think.

Also like the LTC1734, which is lithium / nicad. But expensive at 3-4 dollars. Don't see any lead acid battery chargers on digi that aren't being obsoleted. There's not one. I did see some on manufacturer's pages though. Just not here.

There is one microchip one (lead acid) based on a pic. App circuit is complex.
AN1015 is the app note.

So need a lead, and nicd charger still.

Tomorrow I'd like to look at maxim. I see this:

https://www.maximintegrated.com/en/products/power/battery-management/MAX1772.html
But the application circuit is too much for what I want to deal with.
Seems lead acid battery chargers are not as common as they must've been before.

Onsemi is only lithium batteries.

Mouser has only universal chargers, no lead. But universal includes lead.
let's check linear. LT1510 is an 8 pin simple device. Though it's nicad and lithium only. It says it can do lead in table, but not in datasheet.
lt1510 would work for nicad. data sheet figure 6 has a circuit for nicad.

What about lead?
lt1513 does the three main types: nicd,li-ion,lead
At a cost of \$10.
At digi, the bq2031 is the only lead battery chip (not multi type) that is in production. Not much choice. EDIT: actually that is not
recommended for new designs either.

http://www.eevblog.com/forum/beginners/mc34063-battery-charger/msg1378671/\#msg1378671
Here he uses a boost regulator to power a battery. Essentially just setting the voltage.
http://www.eevblog.com/forum/projects/switching-lead-acid-battery-charger-ic/msg806972/\#msg806972
Here is some better advice.
quote:
\begin{verbatim}
I'd recommend just float charging. It takes only a little longer
 and is easier on the batteries. You will need to limit the initial
 charge current to about 0.1 C (so 2 A for a 20 AH battery). The
 easiest way to do this is a constant current/ constant voltage
 power supply. Set the current limit to the desired charge current,
 and the voltage to the float voltage (13.8 V adjusted for
 temperature if needed). The voltage on the battery will slowly
 increase over time until it reaches ~13.8 V, then the current will
 slowly drop over time until it reaches nearly zero. At that point, 
the battery is fully charged and you can either remove the charger
 or just leave it on.
\end{verbatim}
Which is what I did with my solar battery charger, and it worked well. So I suppose there is no need for anything more than a vreg for lead batteries. This time I will go to the recommended 13.8 instead of what I had before (around 12) and I will do the same trickle charge method. Simple. Done.

May use 1512 instead. \$5 in 150 quantity. Hm...
\$10 in single.
That would cover lead, nicad.
Will need jumpers on R1 and R2 depending on what battery type. According to data sheet, li-ion the divider is a float voltage. In nicd, it is a top limit.

OK, i've decided:

\subsection{Part Selection Summary}

LT1512, and STC4054.
For starters, I will use stc as lithium and lt as nicad / lead.

this will avoid the worry of jumpers, and what not. Later I can be flexible.

Now onto other parts. I need some way to monitor the current, and of course a voltage tap.

Where to put current sense? I think before the battery.

I should put some jumpers in, so I can isolate everything though. I dont' want to mix circuits at the start. So isolate the charger from the op amp and sense, at first.

Let's go with the basic differential op amp in microchip an1332. I need a vreg supply (linear) at 15.5 volts, for the op amp, so it's above the lead battery voltage. Simplest two switchers I see are lm2577 or the mk3608. The mk is easier to use.

With that we have:
\begin{itemize}
\item Battery charger x 2
\item voltage monitor x 2
\item current monitor x 2
\item ethernet (using off the shelf enc modules for now, but maybe
  on board later).
\item microcontroller (nano)
\item temperature monitor (something like max6675 looks nice. can put on board, without difficulty).
  \item additional taps into adc, and some op amps and current shunts not populated to be used as extra current - voltage converters. At least two. Put on modular schematic.
  
  \end{itemize}
I also want a general current and voltage monitor. I want
to be able to watch the load on a battery, and record that as well...
Perhaps that will be separate. I might want to grab some off the shelf
current / voltage monitoring stuff, or just throw a few op amps with breakouts on the board.

Let's build.

Keep all schematics modular!

\textbf{A note on lt1512 tuning}
\begin{verbatim}
How this is tuned:
The V divider on Feedback pin
determines float voltage.
The R downstream of I_feedback 
(after 24 ohm resistor)
determines current (100mV / R)
See data sheet for more details.

Put Simply: Set float voltage on r divider
and make sure current resistor is high enough
to be low current.
\end{verbatim}

\textbf{Calculating LT1512 vdivider}
\begin{verbatim}
Example calculation for R1:
R1 = (R2(Vbat - 1.245) )\ (1.245+R2(0.3uA))
with default R2 at 12,400
Desired Vbat float of 13.8 (lead)
(13.8 - 1.245) * 12400 == 155682
1.245 + (12400 * .000003) == .03720 + 1.245 == 1.2822
155682/1.2822 == 121417

It would be evil for them to put 0.3uA and
expect you to convert that to 0.000003A
But that's what they did. At least they
give an example to check.

Five zeros on that.
\end{verbatim}
Based on the vdivider, what you are seeing is for high voltages, with R2 being the recommended 12.4K, is R1 150K at ~13, R1 220K at ~9V.

Some more notes
\begin{verbatim}
checking the given example:
41200 * (8.2 - 1.245)  286546

41200 * 0.000003 + 1.245 == 1.3605 


lowest possible value (1.3V charge)
(1.3 - 1.245 ) * 12400 == 682 
(12400 * .000003 ) + 1.245 == 1.28
682 / 1.28 == 532

so lowest resistor value must be 500 about...
\end{verbatim}
Lowest resistor would be 536. (e48 resistor)


\subsection{Current monitor}
I considered doing an (high side) op amp with external resistors per AN1322 microchip app note, but decided to go instead with a current monitor, ala ina169. There are a number of INA chips being advertised. Adafruit, for example sells the INA219 and there are many articles
about other current sense in the same family. There is the shunt
resistor value, and the gain resistor to set. I will use based off of the adafruit example, as well as the ti example a 1ohm shunt (for up to 1A readings, seems as you decrease the shunt you get more capacity in amperage to read), with a 1K gain resistor, which TI gives as an example in a table. That means voltage will equal current.

For the inductor
see lt data sheet for details.
must not be series resistance greater than 0.1 ohms.


\subsection{PCB Revision - Modular Parts}
I decided to route out some of the pcb, so I can possibly reuse the temperature sensor and perhaps the lithium battery charger. This was on revision 2. I got the first revision already made after a marathon one Sunday morning from 8-2pm. Here's how it is routed out.

\includegraphics{../pics/modular_reusable.jpg}
\captionof{figure}{Cut out with pliers and reuse parts.}

\subsubsection{Ripped off by temperature sensors}
The community around Arduino advertises the LM35, advertises the MAX6675. The latter is \$10 in one off quantity (\$5 from ebay), the former isn't cheap either, at \$2.00 about. Though the LM35 has a much more limited range. The LM35 is great as it's extremely simple to use (power and read voltage which converts directly to temperature).

I'll have to find an alternative for the MAX6675. At \$10 it's just stupid. A micro can do temperature as well. Maybe \$5 would be acceptable, but \$10 is not. How big are your pockets?

\vspace{0.4in}

\includegraphics[scale=0.3]{../pics/tinythermocouple.jpg}
\captionof{figure}{technoblogy has an article on using a micro with an external thermocouple}

Cheapest thermocouple on Digikey, is a digilent (they just import) thermocouple at \$10. Next is a DFRobot (chinese adafruit) at \$30 with a module included. Thermocouples are not cheap! Onto ebay.\footnote{Thermocouples: I forgot how they work today. I've read of them before but haven't used them much (have seen them in toasters. Now that I know they are worth \$5-10 I'm going to start retrieving them from broken toasters). When two dissimilar metals are put together, and then the metals are heated, you can get a voltage across them. This voltage can be read with an ADC. This phenomenon has a name, but the name is not important. Names just add another thing you need to remember. Bad idea. (OK, I remembered it, now I can fool myself into feeling intelligent - seebeck effect. Now let me go count my hertz, and volts, and teslas...) Wikipedia calls it the thermoelectric effect.}

After some research I decided to go with the Digilent probe. The cheapest used probe on ebay is \$10. I don't want the new ones from US, which is only \$5 cheaper.

\section{Bom Notes}
I should try to get rid of some expensive items where possible.

\vspace{0.2in}

tantalum is \$1. Try a ceramic.

MAX6675 is \$10.

Slide pot is just for fun. That can be removed.



\vspace{0.2in}


On the subject of boms, I have made two. The LT portion is complex, and requires its own bom. The rest of the items are on a different bom. I keep some things in stock so a few items have been omitted.

\subsection{SOD323 (diode) is equal to 0805}
Looks like the SOD323, diode / SC-73 package is near the 0805 package in size. SOD323 is slightly smaller, but not by much. They are probably interchangeable in practice.


\section{PCB Build and Test Notes}
I built the PCB. There were a few errors which I've put in the TODO file, but nothing show stopping. There will be a rev2 pcb. A few notes:

On the LT1512, if you float the voltage divider, and Feedback pin, the device will short out. My power supply continually is saving me on this.

For the voltage divider, you don't actually see the float voltage, between R1, and R2 of the divider, I don't think. The voltage, however does rise, above the divider, where the Vsw pin is. What you do see is the 1.24 reference, or some voltage near it. 

What I'm seeing now, is if you connect a scope probe to the lt charge pin, (pin which charges the battery) you can adjust the divider and see the voltage rise. That must be the float voltage. Meanwhile, the feedback pin, which is downstream of the charge pin, has always about 1.24 or so.

So seems to work well. For a while, I misunderstood how the voltage divider was supposed to work, and spent a few hours double checking the divider values. I had wired the switches wrong in rev 1, but that was not the issue. The issue was my expectation to see the voltage between the divider actually be the float voltage, when that float voltage was above the divider. Must be some transistor math doing a calculation on the voltage divider.

With the 0.2 ohm resistor (in typical application first page of LT1512 data sheet), I had changed it to a 1ohm. That was still not enough, and I instead substituted in a 10ohm. This limits charging to 10mA. The 1 ohm resistor seemed to have some issue of high float voltages causing thermal runway... Maybe a 5 ohm resistor can be used for 20mA charging. This was only on high float voltages. With the 1 Nicd, I was able to do 80-100mA of charging, without issue. But once float is around 5-6 volts you start to get issues with the current growing exponentially from the main PSU, and the LT1512 chip overheating. (At \$8 each, a melted chip is to be avoided).


\subsection{Current usage, and Solar Project}
This project is a descendant of the solar battery charger project. I'm going to restart that project with some of these components, but might use the LT1372, or some other more efficient regulator. No current limiting should be necessary, given that I will use small solar panels (though current limit, might need to be in consideration).

The INA169 draws about 90uA when measuring the 10mA of current going through for a 6V lead battery.


\subsection{Current Limiting resistor on LT1512}
The Resistor after I Feedback, R10 (in my schematic. it's the 0.2 ohm resistor in the official data sheet)... In the circuit here, it is 1 ohm. It 
will allow about 80mA into a NiCd at 1.2
volts. At this level, there is an issue with
charging voltages above single cell lithium values. What happens
is that the circuit starts using over an amp of current and
the LT chip overheats.
If you increase the resistance, you 
can lower the current output and thus also charge 6-12v
batteries.
Test with a current limiting power supply!

\subsection{Separate Grounds 1512}
I did not separate the grounds on the first run, and while there might be more noise (I didn't measure) everything seems to work, regardless.
\subsection{Switches Max Current}
These switches have a max current of 300mA.

\subsection{Usage}
Here's how to use this device. Plug in a 9-12V PSU. Connect USB to computer (bbb, rpi preferred for long term usage).
Measure the voltage divider. This value is found after the large diode, but before the voltage divider. Adjust the switches, and pot as needed. Check with a DMM, for the voltage - that will be the final charge voltage.
Connect battery + into INA169 (high side current sense) . Connect INA169 v out into LT CONN (which is same as where float voltage is measured). 
Connect battery - into ground. Check ina169 ADC reading with Serial out or DMM, it should reflect the charging. You can also put a DMM in series with battery to confirm its charging.

\subsection{Forgot V Dividers for batteries gt 5v}
I guess I forgot a voltage divider on this board. I'll need at least 2 or 3 pins on the ADC to be 10\%, so that I can measure 6 and 12v lead batteries. Hmph. For rev 2 I guess.
\\

\includegraphics[scale=0.5]{../pics/DSCN2552.JPG}
\captionof{figure}{Rev 2}

\section{Rev 2 Build}
The board tends to slowly ramp up, pulling 150 at start, then moving eventually to 500mA (testing at fuse) before cutting back to about 400mA, and the 5V output has a bit of switching on it (thermal shutdown, possibly). It also heats up both the LT and the LM317 at this point.
\\

I recall having this problem with the first board though I was able to get it working, after breaking some traces. On this board, occasionally, I was able to see it pull 60mA, and the output voltage became high. Otherwise the LT FB (I call it the LT Float voltage) became what was expected. But when it was 500mA (shorting?), the float V is low. More research needed. It's possible the LT chip has been damaged too much. The scope is quite clear on what is going on, though. And I was getting output voltages earlier with/without overheating. This is without a battery connected, though a battery added does not make a difference.
\\

I hear a snap when its turning on sometimes. EDIT: maybe I do not...

\subsection{Solution: Grounding Soldering Issue}
This is revision two. On this board, I was getting intermittent issues where the board would suddenly ramp up in current draw from about 10mA to 200 to 300 to 400mA before overheating, and then it would restart the process. I found the LTC IC getting hot.
\\

Before, I had already checked over the schematic once or twice before, so I was fairly confident that was not the issue. I started by reviewing the block diagram of the data sheet. The two inputs, Ifeedback and feedback pins seemed of interest. I tried disconnecting them. At this point, the same behaviour was occuring. I also tried disconnecting the output from the vdivider.
\\

None of these changes made any difference. I checked the continuity of GND pins, and low and behold, pin 3 (GND-S) was intermittent. Normal GND was OK (Pin 2).
\\

It turned out to be an assembly issue. The soldering was not 100\%. This led to intermittent issues. Push on the board enough, and it makes contact.

\textbf{Behaviour of Board with Pins N/C}:
\\
Once I resoldered Pin 3 (GND-S) I still had three other pins disconnected. I found that the board immediately tried to pull more than 1A from my PSU (which shut off). After connecting the three pins (it looks like the FB pin was the cause of this), the board returned to normal operation.

So there are two error scenarios here:
\\

1, GND-S is not connected, and the board slowly ramps up current draw before overheating, and triggering self shutoff.
\\

2. FB (or perhaps another pin) is not connected, and the board instantly tries to pull \textgreater 1A current. 

\subsection{Vin Input Cap}
I had a 2.2uf but it looks like a 22uF is recommended. I threw on a 100uf Electrolytic I had for now. Next revision will have a 22uF tantalum similar to the output cap.

\subsection{Terminal Blocks}
The ones I have are flimsy. Next time I will use Barrier Strip that are pcb mount. These should be more sturdy and usable. See the AIPhone teardown for what they use. (Picture below).
\\

\includegraphics[scale=0.4]{../../../Teardowns_2019/AIPhone_JK-1MEDv2/pics/DSCN2572.JPG}
\captionof{figure}{Barrier Strips that are PCB mount are stronger than terminal blocks.}

\subsection{Using DMM probes, vs. direct wires}
I had better results with direct wires into the current sense, as opposed to trying to use the DMM with its probes, and assumed high R cables.

\subsection{Float Voltage for 6V SLA}

https://www.powerstream.com/SLA.htm
Gives 13.5 - 13.8, so 13.65 / 2 == 6.825

















\end{document}

