The circuit described here provides monitoring of the charge status of a battery by the continuous measurement of charge and discharge currents. The battery current is integrated over time (respecting its sign), and net consumption is shown on a display. The charge stored in the battery can be calculated as a result of this process, and this calculation does not involve the battery’s terminal voltage. The current flowing out of or into the battery is passed through a 0.4 mΩ series resistor in the circuit. Power for the circuit is drawn from the battery under test. The TLC271 operational amplifier, wired as a differential amplifier, requires a symmetrical supply in this application, and for this reason a diode pump circuit driven by a 7555 CMOS timer IC acting as an astable multivibrator is included to generate a negative voltage. The ±5 V supplies for the opamp are then derived using positive and negative fixed voltage regulators. The +5 V supply also powers the rest of the circuit, including the LCD panel.
The current sense amplifier is designed to produce a signal suitable for subsequent digital processing as follows. A current of between +150 A and –150 A produces a voltage drop across the shunt of between +60 mV and –60 mV. The gain of the amplifier is chosen that a current of ±150 A corresponds to a range of ±300 LSBs in the output of the ten-bit ADC inside the microcontroller. With a reference voltage of 5.00 V this, in turn, corresponds to a voltage range of ±1.466 V. The required gain is thus 1466/60= 24.43. Metal film resistors are used to set the gain with sufficient accuracy. The LM336 voltage reference at the output of the opamp offsets the output voltage by 2.5 V, half the reference voltage of the ADC. Small errors in this voltage can be compensated for by adjusting the offset voltage of the opamp.
To measure the battery voltage, whose nominal value is 12 V, it is connected to the second ADC input via a voltage divider. If there is 15 V across the battery the divider is designed to produce an output voltage of 4.888 V, which corresponds to 1000 LSBs at the ADC output. Again, the voltage divider can be constructed with sufficient accuracy using metal film resistors.
The measurement results are shown on a one-line LCD panel. The firmware running in the PIC16F873A microcontroller provides the following functions.
1. Measurement of voltage and current at regular intervals.
2. Integration of current values (respecting sign) over time to measure total net consumption.
3. Storage of calculated net consumption values in internal EEPROM.
4. Selectable display of current, voltage and net consumption.
The program is written in assembler and the main part consists of four loops with execution times of 45 ms, 225 ms, 1125 ms and 72 s. The processor is idle within the 45 ms loop, whose timing is controlled by TMR0: the purpose of the loop is solely to make overall timing precise. Every 225 ms the button is polled, to see if the user wishes to cycle the display through current, voltage and consumption readings. In the third loop, every 1125 ms, voltage and current readings are taken. After each ADC conversion result is fetched it is converted into a format suitable for display. Each current reading is added into an accumulator, taking account of its sign. The 1125 ms loop is executed 64 times, so that over a period of 72 s a total of 64 current readings are summed. After 72 s have elapsed a mean current is calculated by dividing this sum by 64. The reason behind using a 72 s averaging period is that the main purpose of the circuit is to integrate current over time. In a digital system, this cannot be done continuously: the readings have to be sampled. In the conversion results for the current readings, 1 LSB corresponds to 0.5 A, and averaging these values over 72 s = 0.02 h means that one LSB in the final result neatly corresponds to a consumption of 0.01 Ah.
The program takes account of the fact that when charging not all the current flowing into the battery ends up as a stored charge: a multiplicative correction factor of 0.7 is applied.
The prototype of the circuit was constructed on a piece of perforated stripboard. First P1 is used to adjust the contrast of the LCD. Then offset potentiometer P2 is set by putting the unit into current display mode with no battery connected (and hence with 0 V across the current sense resistor), and adjusting for a zero reading. This compensates for any offset error in IC2 as well as for the tolerance in the 2.5 V reference IC3. The software for the microcontroller (hex file and source code) is available for download free of charge from the Elektor website . One further note: the first six entries in the PIC’s EEPROM are set to zero when it is programmed. This is necessary because the program reads these entries to initialize its consumption counter at power-up.