This is only a preview of the March 2022 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
|
Battery
Monitor Logger
Part 2 –
By TIM BLYTHMAN
• Monitor up to 3 batteries from 6 to 100V • Currents to 10A (or 100A+ with shunt)
In Part 1 of our new Battery Multi-Logger last month, we described how
it combines the functions of a Micromite LCD BackPack with voltage and
current-sensing hardware, plus power-saving techniques, all on a single
PCB. Now we’ll go over the construction, testing, setup and calibration
procedures so you can build and use it.
B
efore starting the assembly,
let’s quickly review the Battery
Logger’s capabilities.
n I
t can handle batteries from 6-100V
and monitor up to three bidirectional
currents of up to 10A using its onboard shunts, or much more (to 100A
or beyond) using external shunts.
n
Its own power consumption is less
than 1mA while actively logging
with the screen off.
n
It can display current and historical data on a 2.8-inch backlit LCD
touchscreen, and the data can also
be downloaded to a computer over
USB for further analysis.
n I
t tracks the current battery stateof-charge in both amp-hours (Ah)
and watt-hours (Wh), and it has a
current measurement resolution of
around 0.1% of full-scale, which
equates to 10mA steps when using
the internal shunts.
All these functions are built onto a
small PCB. All the user interface features are accessed via the touchscreen,
so it can easily be integrated into other
devices with a rectangular case cutout.
22
Construction
The Battery Logger is built on an 86mm
x 50mm double-sided PCB coded
11106201, available from the PE PCB
Service. Fig.5 shows where the components go, on both sides of the board.
As usual, when assembling a board
with many SMDs, it is useful to have
the following on hand: flux paste, solder braid (wick), a magnifier, tweezers
and an adjustable temperature iron.
The smallest parts have pad spacing
under 1mm, so solder bridges are almost inevitable, hence the need for
flux paste and solder wick.
Since flux tends to generate smoke,
use a fume extraction hood or work in
an outdoor area, where the smoke can
more easily dissipate.
One of the most fiddly parts is the
USB socket (CON5) so start by fitting
that. Dispense flux onto the pads and
then sit the USB socket in place; it
should lock into the holes in the PCB.
Add more flux to the tops of the pins.
With a clean tip, add solder to your
iron, then press it against the small pins
and pads together. The socket’s metal
shroud tends to get in the way a bit.
Once you are sure that you have soldered all the pins, check for bridges
and remove them if necessary, then
solder the larger tabs on the shroud
in place.
ICs
Solder the ICs (IC1-IC6 and REF1, on
the back of the PCB) next. We suggest fitting IC5 first, as it has the finest pin pitch.
For each of the ICs, check the orientation of pin 1 against the PCB silkscreen by matching the dot before soldering any pins.
IC6 is asymmetric, so although this
part is small, it is easy to orientate
correctly. Note that some of the ICs
might not have a dot to indicate pin 1.
Instead, they will have a bevel along
one edge or a line at one end; in each
case, this feature is nearest to pin 1. For
REF1, the pin 1 indicator might even
be a tiny laser-etched cross.
When soldering the ICs, apply flux
to the pads, then rest the IC in place
and tack one lead. Check the positioning, ensuring that the part is flat and
aligned within its pads. If not, remelt
Practical Electronics | March | 2022
The Multi-Logger can be
mounted in a UB5 Jiffy
Box like many Micromitebased projects, as shown
here. But you might like to
use the bezel to mount the
Multi-Logger in the front
panel of your equipment
enclosure; you could then
use the Jiffy Box to protect
the rear of the unit.
the solder and adjust the part with
the tweezers.
After the part is located correctly,
solder the remaining pins. Don’t worry
about solder bridges as they happen, as
it is easier to remove multiple bridges
later, all at the same time. Apply extra flux if necessary during soldering.
To remove any bridges, apply fresh
flux and press the solder braid against
the excess solder with the iron. When
it melts, allow it to draw up the solder and then gently pull it away from
the component.
The surface tension between the
component and the pad should hold
enough solder to maintain a good connection, even if the solder braid removes most of it.
Now is a good time to inspect your
work closely with a magnifier, as making changes will be harder as more
parts are added.
It’s a good idea to clean away excess
flux first; isopropyl alcohol is a good
all-round choice, but specialised flux
cleaning products often do a better job.
Transistor and regulators
The next trickiest parts are the transistors and regulators in SOT-23 packages.
There are six such parts in three types:
Q1 and Q3 (P-channel MOSFETs), Q2
and Q4 (N-channel MOSFETs), and
REG1 and REG2 (LDO regulators).
Fortunately, they will only fit one
way, so use a similar technique to the
ICs. Solder one lead and check the
position before soldering the remaining leads. The rest of the SMDs all
have much larger pads, so are easier
to deal with.
Resistors and capacitors
Many of the remaining parts are
3216-sized (3.2 x 1.6mm; or 1206
imperial) resistors and capacitors.
The resistors should be marked with
their values, while the capacitors are
Practical Electronics | March | 2022
typically not, so take extra care with
the capacitors and don’t mix them up.
(We recommend working with one
value at a time.)
Where possible, we’ve marked the
resistors and capacitor values below
the part itself; the exception is the
parts around IC4.
Remember that if you are using external shunts for current sensing, you
omit the three 15mΩ shunt resistors.
Leave the larger shunt resistors aside
for now, even if you intend to fit them.
For the remaining parts, check the value printed on the silkscreen against
the value on the part, which will be
a numerical code that you can match
in our parts list.
For each part, apply flux to the pad,
solder one lead, check and adjust if
necessary and then solder the other
lead. Refresh the first lead if necessary.
Most of the capacitors are 100µF,
10µF or 100nF types, so we recommend placing these first. The 100µF
and 10µF capacitors will most likely
be larger, so they won’t be too hard to
differentiate. All four 100µF devices
are fitted to the back of the PCB.
Use the same method as for the resistors. Follow up with the remaining
capacitors, taking note of their value
before removing from the packaging
and working one at a time.
There are two small inductors (L2
and L3) which also have 3216 dimensions; they are soldered in much the
same way.
The larger 120µH inductor (L1) might
require a hotter iron to solder. Use the
same technique of working on one lead
at a time. Sometimes you get better heat
transferral by pressing the long edge of
your soldering iron tip onto the pad.
Then solder the other lead.
Next, solder the button cell holder.
Again, you might need to turn up your
iron to supply more heat. Add flux to
the pads and locate the holder such
that a cell can be inserted from the
edge of the PCB.
Tack one pad down and when you
are happy with it, solder the other
pad. Refresh the first pad to relieve
any stress on the PCB pads. Check
our photos to see how it should look.
And the rest
There are two surface-mounted diodes; they are both fitted with their
cathodes facing towards REG2 (as that
is what they supply).
You may well be using surfacemounting or through-hole parts for
LED1 and S1. Fit these two next. LED1’s
cathode faces to the right, towards
CON1. Most surface-mount LEDs have
their cathode marked with a green dot,
but double-check this, as some do not.
At this stage, practically all the
SMDs have been fitted, so it is a good
opportunity to clean off any excess
flux left on the PCB.
JP1 is not usually needed, so can be
left off (we used it in our testing), but
JP2 is required. Fit the jumper shunt to
make it easier to manipulate and solder
one lead. Check it is square and flat,
then solder the other leads.
If you have pre-programmed microcontrollers (IC1 and IC2), then fit the
shunt to JP2 on the bottom two pads (as
seen in our photo). This is the ‘RUN’
position. If you need to program IC1,
then fit the shunt to the top two pads
(near the PCB mounting hole).
For programming, you will only
need to fit CON1, as IC2 can program
IC1. But if you have a programmer,
you might find it quicker and easier
to fit both for programming anyway.
We used right-angled headers for
CON1 and CON2 to make it easier to
debug, but straight headers will also
work, and fit under the LCD.
23
Fig.5: the PCB photos shown above are of an early prototype, so they differ slightly from the overlays which are our
final design, including up-to-date component values. There are components on both sides, although the back of the
board is much more sparsely populated. Take extra care with the orientation of all ICs, the two diodes and the LED.
Most of the other components are unpolarised.
The connections for the 2.8-inch
LCD are made up of a 4-way and a 14way female header. Only the 14-way
header is needed for the current version of the software, although having
both headers will make the assembly
more robust.
Use the 2.8-inch LCD as a jig to fit
the headers. You might need to solder pin headers to the LCD if they are
not pre-installed; most do not come
with the 4-way header fitted. In that
case, plug the headers into the sockets and insert them into their respective PCBs. The headers sockets go on
our PCB, with the pin headers on the
LCD side.
Solder the headers in place, keeping
the PCBs parallel. Then gently separate the LCD from the PCB, wiggling
it if necessary.
The final step in assembling the
PCB is to fit CON3 and CON3A, the
battery and load connections. Mount
them on the back of the PCB to allow
access even after the stack is assembled. Verify that you have fitted the
three larger 15mΩ shunts if you will
not be using external shunts.
Programming
If you have pre-programmed ICs, you
don’t need to worry about this step
and should proceed to the setup section. Both IC1 and IC2 need firmware
24
to work. The only way to program IC2
in-circuit is to use ICSP header CON1
and a programmer such as a PICkit 3
or PICkit 4.
You can use the MPLAB X IPE (integrated programming environment),
which is available as a free download as part of the MPLAB X package
from: www.microchip.com/mplab/
mplab-x-ide
Choose PIC16F1455 as the device
and your programmer from the Tool
drop-down. Connect the programmer
to CON1 according to its instructions
and browse for the Microbridge HEX
file (2410417A.HEX). Then press the
Program button to upload it.
With the IPE open, you can also use
this to upload the firmware for IC1.
Connect the programmer to CON2, select PIC32MX170F256B as the Device
and browse for 1110620A.HEX. Upload this file with the program button.
After programming is completed,
don’t forget to move JP2 to the RUN
(lower) position.
Microbridge and MMBasic
If you’re inclined to tinker with the
BASIC code, you can program IC1 with
the MMBasic files too, although that
is a bit more involved.
We’ll outline the steps, but with
the assumption that you do have a
bit of experience with the Micromite
environment, know your way around
MMBasic quite well and are comfortable uploading files to the Micromite.
If you don’t want to do this, then skip
to the next section.
You will need the Microbridge firmware on IC2 and start with JP2 in the
PROGRAM position, as it needs (at
the very least) the HEX file for the
BASIC environment to be uploaded
to IC1 first.
This can be done with a PICkit and
the IPE (as outlined above), but instead
of the Battery Logger firmware, you
should choose the latest Micromite
MMBasic firmware file.
Alternatively, the MMBasic firmware can be uploaded by the Microbridge by pressing S1 (to enter programming mode). Then use a program
like pic32prog or P32P GUI to upload
the Micromite MMBasic HEX file. We
used version 5.5.2.
JP2 can now be moved to the RUN
position. From the BASIC environment (a serial port running at 38,400
baud), you should run the commands
to set up the 2.8-inch LCD and touch
panel as per usual for the V2 Micromite BackPack.
OPTION LCDPANEL ILI9341,
LANDSCAPE, 2, 23, 6
OPTION TOUCH 7, 15
GUI CALIBRATE
Practical Electronics | March | 2022
The BASIC files are arranged as a
library file supplementing the main
source code. This allows the Micromite to compress some of the data it
uses. Load the Library.bas file, then
run the command:
LIBRARY SAVE
This saves and compresses the library
file. Next, load the main Battery Logger.
bas file and run it. These instructions
are in the Library.bas file.
Setup and operation
If you haven’t already done so, fit a
CR2032 cell to the BAT1 holder, fit
the LCD panel and connect the Logger
up to a computer or USB power supply via CON5. If you programmed IC1
with the hex file specific to this project,
then the Logger software should start
straight away. If you loaded the BASIC
files yourself, you might need to run
the program manually for the first time.
You should see Screen1 appear at
startup. An error message might appear for the first few seconds while the
program waits for a valid battery reading to occur; if it does not disappear
after about ten seconds, there could be
a problem with IC5. The voltage shown
after ‘V=’ should be zero, as you don’t
have a battery connected yet.
You might see some readings for
the current values, though, as we have
not completed the calibration yet. I1
corresponds to the Logger’s own current use, while I2-I4 are the currents
measured through the terminals of
CON3A, as shown in Fig.5. These values might jump around a bit, but the
long-term averages are the most important figures.
At right are the capacity and state
of charge measurements. CHGv% is
a simple linear calculation between
nominal full and empty voltages, while
CHGm% is based on measured current
since the last full and empty states.
The CHGm% reading won’t be entirely accurate until the battery has
experienced a complete charge and
discharge cycle. Similarly, the capacity readings will not be meaningful
right away.
At upper right is a countdown timer; when this reaches zero, the display
will blank. This is the normal mode,
where the Battery Logger is logging,
but does not need to display anything,
thus saving power. The counter can
be reset by touching anywhere on the
Main screen.
This timeout only happens from
the Main screen shown in Screen1,
so make sure to return to it each time
you finish accessing the Battery Logger’s graphical interface.
Practical Electronics | March | 2022
Fig.6: we ran this diagram last month to show what the Logger can do. We’re
repeating it now as you might want to use it as a guide when wiring it up.
When using the internal shunts, the battery connects across CON3, and the
positive ends of your loads or chargers go to the terminals of CON3a. All
load and charger negatives go straight to the battery. When using the external
shunts, follow diagram (C) and make sure the wiring from the battery to the
shunts is short and thick for maximum precision.
To reactivate the screen, press and
hold the touch panel until the backlight illuminates. For maximum
power efficiency, the Micromite only
checks the panel at one-second intervals, so it might take a second or so of
touch to wake it up. The Battery Logger waits for the touch to be released
before displaying the main screen, so
you can’t accidentally press a button
when waking it up.
The interface is fairly intuitive,
but we’ll walk through the various
screens anyway. Screen2 is reached
by pressing the Data button and displays a graph of the voltage and currents. The current scale (left-hand
side) can be manually set, while the
voltage scale uses the nominal full and
empty values. By default these are set
to 14.4V and 11.0V, to suit a 12V leadacid battery.
The buttons along the bottom set this
page to display the various scales, with
the time frames shown at the bottom
of the screen. In each scale, the Export
button does a dump of data to the serial port. This data is produced so that
it can be saved as a CSV (comma separated value) file and then can be opened
with most spreadsheet programs. Pressing Exit returns to the Main display.
Screen3 is accessed using the Settings button. Each value shown can
be changed by pressing the respective button.
25
Screen1: the main screen provides all the critical statistics
for your battery, as well as three simple menu options
for accessing other features. The greyed values seen are
capacity calculations which are not yet valid, as the Logger
has not detected a complete charge and discharge cycle;
they will light up brighter when that happens.
Screen4 shows a number being entered, in this example to update the
current year. If the number entered is
invalid, a message is displayed. Pressing OK prompts for the new value to
be confirmed (see Screen5).
The time and date settings are immediately saved to the real-time clock
and are displayed on this and the main
screen. The two B/L values are for the
backlight brightness as a percentage,
from 1-100. The first value (B/L) is
used most of the time.
The second value (B/L dim) is used
for the last five seconds before the
screen shuts down, to indicate that
this is about to happen. A minimum
value of 1% is allowed for either setting to ensure that the display is always visible.
The V(full) and V(empty) values
should be set to suit your particular
battery. You can’t set the V(empty) value to be higher than the V(full) value.
The Timeout value sets how long
the display stays on before blanking
at the Main screen. This has a minimum of five seconds, as this is the
period of dimming that occurs before
blanking. A large value can be used
to stop the display blanking; eg, a period of 99999999 seconds is around
three years.
The ‘I scale’ value sets the limits of
the graph on the Data page only. Setting a value of 20 will cause the graph
to span from –20A to 20A.
The ‘V(sdown)’ value sets a critical battery limit. Below this level, the
Battery Logger sleeps for much longer
Screen3: the Settings screen provides the most common
options for configuring the Logger, including battery
voltages, time and date and backlight controls. Each entry
is validated to ensure it does not conflict with other values
(such as the ‘Empty’ voltage being higher than the ‘Full’
voltage) and then immediately saved to Flash memory.
26
Screen2: the Data screen provides a graphical view of
the logged data. Different timespans can be shown, and
the display will automatically scroll once a minute to
show current data. The Weeks option provides around a
fortnight of data. Data can also be dumped as CSV rows
over the console serial port with the Export button.
periods between activity. The MMBasic code sets this to 15 seconds. Since
the ADC (IC5) goes to sleep after each
conversion, the result is that current
consumption drops even lower than
the normal ‘screen off’ mode.
This setting is intended to preserve
a battery that already is heavily discharged. You can still use the Battery Logger, although you will have to
touch the screen for up to 15 seconds to
wake it up, and the data will be much
more sparse, as it won’t be logging as
frequently. Still, you should be able to
quickly identify that there is a problem
with the battery and rectify it.
To disable this feature (eg, for testing without a battery connected),
set this value to 0V. In this case, the
buck regulator will shut down below
Screen4: the Entry screen is displayed whenever a number
needs to be entered. The symbol at lower left allows the
last typed character to be deleted. Since negative numbers
are not used, there is no minus symbol.
Practical Electronics | March | 2022
Screen5: each Entry value is validated before being
processed and saved, which provides a way of safely
making changes.
around 5.5V, causing the Battery Logger to power off completely unless it
is powered from USB.
Calibration
The remaining button on the Main page
goes to the Calibrate page (Screen6). You
should always calibrate the V factor first,
as the measured current depends on the
voltages measured being accurate.
Internally, there is a V factor (the
ratio between the actual voltage and
the raw 24-bit ADC reading) for each of
the four dividers, but only one is displayed, as they should all be similar
to within component tolerance. The
nominal value is 100V/16,777,216; ie,
a full-scale reading at 100V.
The four V factors allow compensation for variations in the dividers,
mostly due to component tolerances.
They allow the three current sense dividers to be zeroed against the primary
voltage divider. Thus, this step should
be done first before attempting to calibrate the individual currents; otherwise, there will be an offset from zero.
You’ll need to hook up your battery, or, at the very least, a stable voltage source above 6V. Higher voltages
will mean that the quantisation error
(due to steps between consecutive
ADC values) will be proportionally
less, potentially giving slightly better calibration.
Don’t hook up anything to CON3A
though, as we don’t want any current
flow to skew the results. If possible,
leave the USB supply connected too,
as this will minimise the load on the
Screen7: any conditions that need to be satisfied for
accurate calibration are prompted before the calibration
begins. While this adds an extra step, it means there is little
chance for the calibration to fail.
Practical Electronics | March | 2022
Screen6: the Calibration screen provides a mostly
automated way of adjusting the Logger to account for
component tolerances. The operator simply needs to enter
a meter reading (volts or amps), and the Logger calculates
the calibration factors to produce the desired value.
battery, with the display running from
USB power. In this case, the only battery drain will be the no-load quiescent current of IC4, at around 10µA.
Hook up a voltmeter to the battery
terminals and allow the unit to settle for a minute. This reading must be
stable for optimum results. Press the
‘Volts’ button and acknowledge that
there is no load on the terminals.
Enter the battery voltage as displayed on the voltmeter. A page will
show the various V factors and an
estimate of how much they vary. If
there is a variation of more than a
few percent (due to component tolerances), you might have a problem
with the dividers, such as a wrong
component value or a spurious load
on the battery.
Screen8: as noted, all values are checked for validity
before being saved and used by the Logger. In this case, a
brief but helpful message is provided to allow the user to
work out what went wrong.
27
You can confirm the new values by
pressing OK, or use Cancel to investigate further. The calibration is stored to
Flash and used immediately. Go back
to check that the displayed currents
(I2-I4) have settled near zero. This
means that the calibration is correct.
The remaining calibrations are not
so critical as they won’t produce an
offset in the results, but will simply
give incorrect current scaling. The
default values are calculated from
nominal component values; you will
have to change these if you are using
external shunts.
Current calibration
The current calibration method is
straightforward. A known load is applied to each terminal, the current is
measured and entered into the Battery
Logger, and it then calculates the conversion ratio.
For I2-I4, these are the external loads
at CON3A, while I1 is the Battery Logger’s own current. Thus for I2-I4, the
load should be applied between CON3A and the battery negative.
In this case, the actual current being
displayed on the main screen will be
negative (the battery is discharging).
Still, you can only enter a positive value, so you should just enter the magnitude of the current.
The initial values are set in the
MMBasic program but can also be altered here, which you need to do if you
are using shunts with values other than
15mΩ. The current calibration values
are simply the inverse (reciprocal) of
the shunt resistance in ohms, so the
default 15mΩ shunts have a calibration factor of 66.67.
For I1, you will probably need to
disconnect the battery to allow an
ammeter to be connected in the Battery Logger’s supply. When doing
this, disconnect the USB cable and
ensure that there is no load on any
of the CON3A terminals.
The nominal value of the factor used for I1 is the inverse of the
shunt resistor resistance (in ohms)
divided by the op-amp circuit’s gain.
Consider that the measured shunt
voltage would be the same as if the
shunt resistance was multiplied by
the gain. Therefore, the default value is the inverse of 0.1Ω, (ie, 1/0.1)
which is 10, divided by 100 – in other words, 0.1
Mounting and completion
With everything calibrated and set
up, you can mount and connect up
the Battery Logger. Being a similar
size and shape to the V2 Micromite
BackPack, the Battery Logger can be
fitted with the laser-cut acrylic front
28
When fitted to the inside of an equipment enclosure, the important features are
available for maintenance access, including cable terminations and the RTC
backup battery.
panel designed for UB3 Jiffy boxes.
In this form, it can be mounted in
a box. Or, you could opt to use the
acrylic panel as a bezel to mount the
Battery Logger in an equipment enclosure, with wires connecting internally
and the touch panel being accessible
from outside.
To do this, separate the LCD and
Battery Logger PCB by wiggling gently. Decide which side of the bezel
you would like visible; we prefer the
matte face, but it is reversible, so you
can put the gloss side to the outside
if you want.
Thread four of the M3 screws
through the front of the bezel, place
the washers over the threads, then follow with the LCD. The spacers provide
clearance for the leads that protrude
from the back of the headers.
Secure the M3 screws with the
tapped spacers. Reconnect the Battery
Logger PCB and secure it to the stack
with the remaining M3 screws.
This complete assembly can now
be attached, for example, to the front
door of an equipment cupboard, using an M3 screw and nut in each corner to secure it. When the cabinet is
opened, the battery connections can
be accessed from the rear.
Protecting the back of the Battery
Logger is easily done with the UB3 Jiffy
box. The included screws might be too
short if they need to screw through a
panel, but the pillars will line up with
the holes in the bezel.
In this case, all you need is a few
holes in the side or back of the box to
run the wires.
To complete the wiring, you can
follow the three examples shown in
Fig.6 (reproduced from last month).
This shows options for use with internal and external shunts, including
one possibility of sharing terminals on
CON3A if you have more than three
total loads plus charging sources.
Note that ideally, there should be a
fuse on each wire out of CON3A (or
in the high-current wiring leading to
the shunts).
There should also be a fuse in the
wire leading from the battery positive
to CON3’s positive terminal. This way,
a fault in the Battery Logger or any of
the connected loads cannot short out
the battery.
The wiring will be specific to individual arrangements, so we can only
offer general advice.
Conclusion
Like many of our projects, especially
those written in MMBasic, we expect
people will want to customise, tinker
and perhaps improve the software.
We look forward to hearing what
features readers would like to add, as
we are already planning to supplement
the Battery Logger with extra hardware
in the future.
You will see that we haven’t left
many microcontroller pins unused,
but we have broken out two pins to
a header at the top right of the PCB.
These are connected to the Micromite’s
I2C pins, as we figured that would be
a good way of expanding the device
(they are already used for the real-time
clock, but I2C is a shared bus).
3.3V power and ground connections
are also available at nearby CON2,
while CON6 connects to the Micromite’s second COM port (COM1), at
pins 21 and 22.
That provides a dedicated communications channel that could be used
to add more features.
Reproduced by arrangement with
SILICON CHIP magazine 2022.
www.siliconchip.com.au
Practical Electronics | March | 2022
|