认为密封铅酸(SLA)电池是一个过时的东西?请再想想。它们一定会在未来的几年有好的前景。Dale为他的密封铅酸(SLA)电池设计了一种充电状态计。他的彩色发光二极管计量器简化了电池充电的检测。
An MCU-Based “Gauge” for SLA Batteries
Think sealed lead-acid (SLA) batteries are a thing of the past?
Think again. They are bound to be around for years to come. Dale
designed a state-of-charge meter for his SLA batteries. His
multicolored LED meter simplifies battery charge testing.
Rechargeable batteries are found in almost all portable, mobile,
and mission-critical electronic equipment. New technologies are
storing more energy in less space than ever before. Sealed
lead-acid (SLA) batteries are far from the leading edge of
available options: they are heavy, poisonous,and lack energy
density compared with newer options. Despite these apparent
drawbacks, they are everywhere. Like COBOL, they will be with us
for some time.
SLA batteries are especially popular in hobby robotics as well as
hobby electronics in general. Their ubiquity in surplus channels
makes them an easy choice for beginning roboticists. Low initial
cost and dependable, well-documented performance endear them to
novices and seasoned professionals alike. It also doesn ’t hurt to
find that many standardized sizes and capacities are still being
produced all over the world and will be for the foreseeable future.
Charging characteristics increase their appeal: A constant voltage
charger is often a good first project for the curious electronics
hacker. Off-the-shelf charging solutions abound and remain
competitively priced.
A FUEL GAUGEHow much charge is left in the battery? I’m glad you asked! There
are several methods available for determining the “state of charge”
(SoC) or, conversely, the “depth of discharge” (DoD). I think I’ve
seen those acronyms before, somewhere.
The most direct method is to simply measure the battery voltage and
say, “Lo, here is the remaining charge.” Fortunately for battery
users and unfortunately for us battery measurers, most batteries
have a relatively flat discharge curve. Lithium-based chemistries
are the most notorious for steady, stable voltage output. Curse
them and their dependable, high-energy densities! We will
eventually use a variation of this method to determine the state of
charge, after combining it with some other knowledge we have that
is specific to lead-acid batteries.
Once upon a time, before SLA batteries were sealed, the specific
gravity of the electrolyte could be measured and used as a good
indication of the state of charge. You dipped an industriallooking
turkey baster containing floaties into the different cells and
slurped up a sample electrolyte using the high-tech squeeze bulb on
the end. If you had a steady hand and good lighting,you probably
didn ’t spray battery acid on your clothes and skin. Unfortunately,
I often did. I don ’t test those kinds of batteries any more.
A more detailed method to determine SoC is to measure how much
energy has gone into the battery during the charge cycle and then
keep track of how much energy is then taken out during usage.
“Counting coulombs ” requires both current and voltage measurements
to be integrated over time and must take into consideration
temperature and age of the battery. In reality,temperature and age
really have to be considered in any comprehensive methodology.
Several “coulomb counter ” circuits are available from Maxim
Integrated Products, Linear Technology,Texas Instruments, and
others. Also, if you can count individual coulombs per second, you
know how many amps are flowing in a circuit,because that is the
textbook definition —but you knew that.
Table 1—This is the state of charge versus voltage for a sealed leadacid
battery at rest. These values were taken from “Battery University,”
a series of informative, on-line articles about rechargeable
batteries by Isidor Buchmann and sponsored by Cadex Electronics.
Although there is no linear relationship between voltage and state
of charge, there are well-known waypoints down the discharge curve
for lead-acid batteries. These voltage levels are only truly
representative of the state of charge after the battery has been
allowed to rest for at least 8 hours. They are summarized in Table
1.
MEASUREMENT CIRCUITRYFigure 1 shows a simple data acquisition circuit that can be used
to approximate the state of charge of an SLA battery. The input
signal powers the entire circuit. The battery voltage is brought in
via J1. From there, it is split into two paths.The first goes to an
LM317L adjustable, positivevoltage regulator that is set to
approximately 5 V using R5 and R6. I chose this for its wide input
range, excellent output stability, small size, abundant
availability, and low cost. The regulator ’s output is filtered by
C1. Overall, this is a mundane power supply circuit. Its only
special feature is that it will withstand a high input voltage and
automatically shut itself down if it overheats.
Figure 1—This is the smart SLA battery meter. I originally drew this using
Advanced Circuits’s free/gratis PCB Artist software. It enabled me
to enter the schematic, lay out the PCB, then quote and order PCBs,
all from the same program. This is a redrawn version.
The other path for the incoming power signal is to a voltage
divider composed of R7, R8, and R9. R9 is a potentiometer allowing
the calibration of the incoming signal to a known value. This is
handled in software to allow quick and reliable calibration of the
battery meter in production (see Figure 2). I will describe more
about the calibration procedure when I cover the firmware in
detail.
Figure 2—Here are the mechanical dimensions of the prototype PCBs. This will
allow you to have a custom panel machined that will fit like a
glove. The production version of the PCB will have the same
dimensions but will have rounded corners.
The wiper pin of R9 leads into pin 3 of U1, the main brain of the
circuit. I used one of my favorite Atmel AVRs, the ATtiny13, for
its small size, ease of programming, versatile peripheral set, and
low cost. The primary features that helped me select this part for
the design were an on-chip ADC with up to 10 bits of accuracy, an
internal clock, low current requirements, and reprogrammable I/O
lines.
TELL THE WORLDThe AVR is happy to measure the incoming voltage and store the
answer in a register or RAM location. That ’s not interesting at
all. I wanted to add a simple but effective display using a minimum
number of parts. I also wanted the display to produce
“meaningful ”information even with no user manual handy. A single
line of LEDs arranged as a bar graph would give a good report with
a single glance; the more LEDs lit, the more power was left in the
battery.Somewhere along the line I decided to spice it up and use
multicolor LEDs to reinforce the message: green was good, yellow
foretold doom, and red would announce failure. I suppose
“multicolor ” is a bit of a reach,as the LEDs I finally included
were technically “bipolar ” LEDs: a red and a green LED die
mounted inside the same package. Current applied in one direction
would course through one die and illuminate it while reversing the
current would light up the other side. Alternating the current
rapidly would produce the illusion of both LEDs being lit
simultaneously.This is alleged to be yellow,but it only looks
yellow if you look at it quickly and sideways at the same time. It
is yellow-esque, at best. Five or six multicolor LEDs would give
enough of a range to make a useful display. Because each LED
package is two distinct LEDs, I would have to come up with a way to
drive a dozen or so LEDs with a small microcontroller.
FANCY LED MULTIPLEXINGNormally, 12 individual LEDs would require, at a minimum, 12
dedicated output driver lines to be able to individually and
randomly address any LED. The ATtiny13 has six I/O lines available.
Using a multiplexing technique sometimes referred to as
“charlieplexing,” I was able to drive the 12 LEDs using only four
output pins. Maxim application note 1880 credits Charlie Allen with
championing this technique within the organization. Maxim
Integrated Products offers several devices that will perform that
trick for you. Don Lancaster wrote about it in his “Tech Musings ”
column in August 2001 and gave several examples (
www.tinaja.com). I ’m sure I thought of it long before, but I must have neglected
to write it down in my journal. Dang.
The number of LEDs that can be addressed depends on the number of
I/O lines that you ’re willing to throw at it.The formula is n(n –
1),where n is the number of I/O lines. So, four I/O lines would
give you 12 LEDs (i.e.,4 ×3). That translates to six bipolar LEDs.
The next step up would be five I/O lines and 20 normal LEDs or 10
bipolar LEDs. That ’s too many. The next step down would be three
I/O lines and six normal LEDs or three bipolar LEDs. That’s too
few. Six LEDs is just right.
Imagine the four I/O pins are wired to the four corners of a
square. Now each square corner is connected by a bidirectional LED
to every other corner. This makes four LEDs around the periphery of
the square as well as two across the diagonals. My schematic skills
omit the symmetrical beauty of this circuit and hint only at the
possibilities.
We have 12 LEDs: six red and six green. They look just like regular
LEDs when they are not illuminated. Some bipolar LEDs have three
legs: one for each die and a common terminal. I used the two-legged
variety of the 3-mm persuasion where each leg is attached to both
the anode of one LED and the cathode of the other.
Instead of wiring a current-limiting resistor to each LED, I wired
them to the I/O lines. This way there are only four resistors for
all 12 LEDs. This works out well as there is only one LED on at a
time, even when it looks like they are all illuminated. Because the
current through any LED must flow through two resistors, the value
of each resistor is half of what is required to limit the current
through the LED. I calculated a maximum of 20 mA through each LED.
I could probably have upped that number as the duty cycle is at
most 1/6.
To illuminate any single LED, the I/O pin that is connected to its
anode is programmed to be an output and to drive that output high.
The corresponding cathode pin is also programmed to be an output
and to drive its output low. The other two I/O lines are told to
sit down and shut up. A more technical and accurate way to describe
it would be to say that they are programmed to become inputs and
not activate their internal pull-up resistors. They effectively
become tristated at this point and do not contribute to the current
flow in the LED array. Each LED has its own pattern of ins, outs,
highs, and lows.
WRITE THE SOFTWAREI built a prototype of the circuit using a solderless breadboard
(see Photo 1). I used an Atmel STK-500 to program the ATtiny13.
Being an eight-pin DIP, it was relatively easy to pop it in and out
of the prototype for programming. Anything larger would have wanted
its own programming cable attached. The AVR devices have the nice
capability of “in-system programming,” or ISP. This allows the part
to be programmed and reprogrammed in situ, without having to remove
the part from the circuit and placed in a device programmer.
Photo 1—This is the first prototype of the battery meter built on a
solderless breadboard. The extra resistors represent doing it the
hard way when you don’t have an exact value in stock when
inspiration strikes.
I wrote the code in C. I used the WinAVR port of the GCC
compiler collection, which works well with Atmel’s AVR Studio.
These are all free programs, in various senses of the word (GCC is
libre, or free as in speech, while AVR Studio is gratis, or free as
in beer).
The first task was, as usual in embedded development, to light a
single LED. This was a little more complex than the normal embedded
“Hello, world!” monochrome monopixel. I had to constantly refer to
my scribbled notes as to pin placement and LED array wiring (see
Figure 3).
Figure 3—This is the geometric version of the LED array schematic, showing
all the possible combinations of connections between the four I/O
lines. That’s how you light up 12 LEDs with only four I/O lines!
I played with various combinations of highs and lows and ins and
outs. Once I could light up individual LEDs to my satisfaction, I
wrote a routine to scan through a memory map of LEDs and light them
or not, over and over, too quickly for the eye to detect. This
produces the illusion of multiple LEDs being illuminated at the
same time. This became the main loop of the final firmware.
Now I had a medium waiting for a message. The next step was to read
the ADC peripheral and determine what voltage was being presented
for analysis. Naturally, reading it once was not going to be
adequate, due to sampling noise and other error terms, so I set up
the on-chip Timer/Counter peripheral to interrupt periodically and
in the interrupt service routine set about to oversample the ADC
input. Eight successive samples are read and summed then divided by
eight to give a rough arithmetic average. This number is compared
to a series of preset values to determine how many LEDs of each
color to light up. This is where the values from Table 1 come into
play.
I broke down the basic thresholds from Table 1 and added a few more
of my own devising because my multicolored bar graph could easily
express more than the five original charge states.
If the input voltage is above 13.5 V, I assume that the battery is
being charged. To announce this, I have the LEDs do the happy
dance, where an upward sequence of green LEDs is marched up the bar
graph. This is similar to what you may have seen on many cellular
phones during their recharge period, except that mine is greener
and happier.
If the voltage is between 12.65 and 13.5 V, the graph shows six of
six bars, or green LEDs in this case. This represents a fully
charged battery with 100% of its capacity available. You have
to remember that in the real world, a battery has 100% of its rated
capacity only once, if you’re lucky, early in its life, and that it
slowly degrades over time.
When the voltage is between 12.45 and 12.65 V, it is estimated that
approximately 75% or more of the power is still available. Five
green dots out of six indicate this stage.
Note that 12.24 V marks the 50% line. Only four green dots are
displayed at this point. When 12.06 V is measured, it tells you
that only about 25% of the charge remains, and three yellow LEDs
are displayed, notifying you that it might be time to start
thinking about finding the charger.
When the measured voltage drops further but is still above 12 V,
two yellow LEDs describe this sad state of affairs. The battery is
effectively flat at this point.
While still above 11.89 V, a single red LED will be lit to announce
impending loss of battery power. Anything below this is considered
a battery failure and will be displayed as a blinking red light.
Below 11.5 V, the unit stops displaying anything in an effort to
save what little power might be left.
DUAL POWEROne of the original requirements for the meter was to measure both
12- and 24-V battery systems, because these were the most common
for SLA batteries. I had originally thought of using different
resistors in the inbound voltage divider, but this would have
ultimately created two meters: one for 12-V systems and another for
24-V systems. My first thought to improve this was to use a jumper
to select between the two ranges and have both sets of resistors
installed, just in case. I finally decided to have the required
duplication in software where it would weigh less and take up less
shelf space. The firmware is actually checking the various
waypoints down the discharge curve and also exactly double those
voltages. This makes the meter “autoranging ” within an admittedly
small set of ranges. It also makes it hard for the end user to
order the wrong meter or to configure it incorrectly. Note that I
didn ’t say “impossible.” Those of you with customers of your own
will understand what I mean.
I added an overvoltage condition test for inputs of over 30 V. The
LEDs light up in an alternating red wig-wag pattern that screams
out “uh oh, uh oh” to let you know you’ve hooked up the meter to
the wrong wires.
One additional “waypoint” is coded into the firmware to allow quick
and easy calibration of the meter. Then exactly 7.50 V is detected,
which is below the normal operating range but still high enough to
keep the voltage regulator happy, a special pattern of two yellow
LEDs is lit on the meter. To calibrate, attach an accurate 7.50-V
source (I happen to have one) and adjust the potentiometer R9 until
the LEDs light up with the right pattern. That’s it!
The final version of the firmware is contained in a single file of
approximately 300 lines of C code and takes up 99.4% of the
ATtiny13’s 1-KB flash memory. The file and its corresponding object
file in Intel HEX format are posted on the Circuit Cellar FTP site.
SHOW & TELLOnce I had a working prototype of my new meter, I just had to show
it off to some fellow robot builders.Last summer, I brought the
battery meter, along with some other blinky toys that I had been
working on, to an R2 Build Day hosted by Jerry Chevalier of the
R2-D2 Builders Club. Several of the robot builders expressed
interest in the meter and that got me thinking about making a real
PCB and offering it for sale.
I had been playing with Advanced Circuits’s PCB Artist software for
several months but had not really gotten the hang of it yet. I
would tell myself to start out simply and work my way though a
complete, if trivial,example. It never failed that I would
eventually start trying to get all fancy and do a lot of things at
once and would inevitably work myself into some indescribable
corner where I would get frustrated and just end up walking away.
It ’s ironic because Advanced Circuits ’s Drew Peterson lives to
help people with PCB Artist questions. The trick is to be able to
describe the problem you ’re having.If you can describe it, Drew
can help you out. If you can’t, other than “It is not doing what I
want it to do,” then you’re kinda stuck.
So I started over again, this time on a schematic-only design. I
had built a small, five-LED “Cylon” scanner and needed a schematic
to put up on my web page. It just needed to be lines, dots, and
text. I had already laid out a PCB without the benefit of a
schematic (because it was that trivial). This proved a good
exercise in learning the user interface of PCB Artist.
The next step in PCB-fu was to learn to make my own symbols. In PCB
Artist, all components are symbols, with a schematic view, a PCB
footprint, and a link associating the two. Once you can build your
own symbols effectively, the sky’s the limit. I’m still a long way
from being an expert, but I can rough out a board in 1 hour or so
and have production-quality work in a few hours more. As I
mentioned before, the software also enables you to order PCBs
online. I am constantly amazed by this wonderful world of ours.
Photo 2—This is the assembled PCB. These boards made by Advanced Circuits
are their BareBones special: double-sided, plated-though holes, no
soldermask, no silkscreen. Believe it or not, they were built in
under 24 hours! Every one perfect, every time.
The PCBs arrived the same day as the last of the components, so I
got busy soldering. I used through-hole parts exclusively on this
design and the boards were straightforward to assemble. The
finished PCB is 1.500” × 1.500” (see Photo 2). The components are
mounted on one side of the board, and the LEDs are mounted on the
other side so that the meter can be flush-mounted in an enclosure,
if desired.
The meters are available for sale on my web site (
www.dalewheat.com). They are also available on the sites of the other vendors.
If you have any questions about this little circuit, please don’t
hesitate to contact me.
Dale Wheat is a full-time freelance writer working primarily with
embedded systems and shiny things that blink or beep. Dale is
married and the father of two adult children. He lives near Dallas,
where he enjoys mowing two acres of grass in the summer and not
mowing it in the winter. To find out what he has been up to, visit
his personal web site
dalewheat.com.
PROJECT FILESTo download code, go to
ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2009/226.
RESOURCESI. Buchmann, “Charging the lead-acid battery,” Battery University,
www.batteryuniversity.com/partone-13.htm.
The Electropaedia, “State of Charge (SOC) Determination,”
www.mpoweruk.com/soc.htm.
D. Lancaster, “Tech Musings,”
www.tinaja.com/glib/muse152.pdf.
Maxim Integrated Products, Inc., “Application Note 1798: Frequency
Undersampling in Coulomb-Counting: Measuring Current Flow in
Battery Applications,” 2002,
www.maxim-ic.com/appnotes.cfm/appnote_number/1798.
———, “Application Note 1880: Charlieplexing—Reduced Pin-Count LED
Display Multiplexing,” 2003,
www.maximic.com/appnotes.cfm/appnote_number/1880.
R2-D2 Builders Club, http://astromech.net.
D. Wheat,
http://dalewheat.com.
SOURCESPCB Artist software
Advanced Circuits |
www.4pcb.comATtiny13 and STK-500
Atmel Corp. |
www.atmel.com