Digital meter of capacity and internal resistance of batteries. A device for measuring battery capacity. Basic methods Circuit for measuring the capacity of a li ion battery

This device is designed to measure the capacity of Li-ion and Ni-Mh batteries, as well as to charge Li-ion batteries with a choice of initial charge current.

Control

We connect the device to a stabilized power supply of 5V and a current of 1A (for example, from a cell phone). The indicator displays the result of the previous capacitance measurement “xxxxmA/c” for 2 seconds and on the second line the value of the OCR1A register “S.xxx”. We insert the battery. If you need to charge the battery, then briefly press the CHARGE button; if you need to measure the capacity, then briefly press the TEST button. If you need to change the charge current (the value of the OCR1A register), then press the CHARGE button for a long time (2 seconds). Go to the register adjustment window. Let's release the button. By briefly pressing the CHARGE button, we change the register values ​​(50-75-100-125-150-175-200-225) in a circle, the first line shows the charging current of an empty battery at the selected value (provided that you have a 0 resistor in the circuit ,22 Ohm). Briefly press the TEST button; the values ​​of the OCR1A register are stored in non-volatile memory.
If you have performed various manipulations with the device and you need to reset the clock or measured capacity, then press the TEST button for a long time (the values ​​of the OCR1A register are not reset). As soon as the charge is complete, the display backlight turns off, to turn on the backlight, briefly press the TEST or CHARGE button.

The operating logic of the device is as follows:

When power is applied, the indicator displays the result of the previous measurement of the battery capacity and the value of the OCR1A register, stored in non-volatile memory. After 2 seconds, the device goes into the mode of determining the type of battery by the voltage at the terminals.

If the voltage is more than 2V, then it is a Li-ion battery and the full discharge voltage will be 2.9V, otherwise it is a Ni-MH battery and the full discharge voltage will be 1V. Control buttons are available only after connecting the battery. Next, the device waits for the Test or Charge buttons to be pressed. The display shows "_STOP". When you briefly press the Test button, the load is connected via a MOSFET.

The magnitude of the discharge current is determined by the voltage across the 5.1 Ohm resistor and is summed up with the previous value every minute. The device uses 32768Hz quartz to operate the clock.

The display shows the current value of the battery capacity "xxxxmA/s" and the discharge torus "A.xxx", as well as the time "xx:xx:xx" from the moment the button was pressed. An animated low battery icon is also shown. At the end of the test for the Ni-MH battery, the message “_STOP” appears, the measurement result is displayed on the display “xxxxmA/c” and is remembered.

If the battery is Li-ion, then the measurement result is also displayed on the display “xxxxmA/c” and is remembered, but the charging mode is immediately activated. The display shows the contents of the OCR1A register "S.xxx". An animated battery charge icon is also shown.

The charge current is adjusted using PWM and is limited by a 0.22 Ohm resistor. In hardware, the charge current can be reduced by increasing the resistance from 0.22 Ohm to 0.5-1 Ohm. At the beginning of charging, the current gradually increases to the value of the OCR1A register or until the voltage at the battery terminals reaches 4.22V (if the battery has been charged).

The amount of charge current depends on the value of the OCR1A register - the larger the value, the larger the charge current. When the voltage at the battery terminals exceeds 4.22V, the value of the OCR1A register decreases. The recharging process continues until the OCR1A register value is 33, which corresponds to a current of about 40 mA. This ends the charge. The display backlight turns off.

Settings

1. Connect the power.
2. Connect the battery.
3. Connect the voltmeter to the battery.
4. Using the temporary + and - buttons (PB4 and PB5), we ensure that the voltmeter readings on the display and the reference voltmeter match.
5. Long press the TEST button (2 seconds), memorization occurs.
6. Remove the battery.
7. Connect the voltmeter to the 5.1 Ohm resistor (according to the diagram near the 09N03LA transistor).
8. Connect the adjustable power supply to the battery terminals, set the power supply to 4V.
9. Briefly press the TEST button.
10. We measure the voltage across the 5.1 Ohm resistor - U.
11. Calculate the discharge current I=U/5.1
12. Using the temporary buttons + and - (PB4 and PB5) we set the calculated discharge current I on the indicator “A.xxx”.
13. Long press the TEST button (2 seconds), memorization occurs.

The device is powered from a stabilized source with a voltage of 5 Volts and a current of 1A. Quartz at 32768Hz is designed for accurate time keeping. The ATmega8 controller is clocked from an internal oscillator with a frequency of 8 MHz, and it is also necessary to set EEPROM erase protection with the appropriate configuration bits. When writing the control program, educational articles from this site were used.

The current values ​​of the voltage and current coefficients (Ukof. Ikof) can be seen if you connect a 16x4 display (16x4 is preferable for debugging) on ​​the third line. Or in Ponyprog if you open the EEPROM firmware file (read from the EEPROM controller).
1 byte - OCR1A, 2 bytes - I_kof, 3 bytes - U_kof, 4 and 5 bytes are the result of the previous capacity measurement.

Video of the device:


The proposed device is designed to measure the capacity and internal resistance of Ni-Cd and Ni-MH batteries. There is a sound indication of excessively low battery voltage, as well as the moment of the end of its discharge.

Measuring the capacity of a battery is based on discharging it with a steady current, measuring the discharge time and multiplying these values. When measuring internal resistance, the device measures the battery voltage without load, then under load with a current of 1 A and, based on these data, calculates the internal resistance of the battery.

The device diagram is shown in Fig. 1. Its basis is the ATmedav microcontroller (DD1). The keyboard with a single-wire interface consists of six buttons SB1-SB6. Information about the measured battery parameters is displayed on the nine-digit LED indicator HG1. To discharge the connected battery, a voltage-controlled current source (VTUN) is used on op-amp DA2, transistor VT1, resistors R9, R10, R19-R21, R23 and capacitors C7, C9.

If the voltage of the connected battery is below 1 V, the device's keyboard is locked and the BF1 capsule emits three intermittent sound pulses at a frequency of 600 Hz. If the battery voltage is above 1 V, the BF1 capsule emits two intermittent sound pulses at a frequency of 3000 Hz when the battery is connected, and also when it has finished discharging to the set voltage

After connecting the battery, set the voltage to which it must be discharged by pressing buttons SB3 and SB4. The setting step when pressed briefly is 0.1 V. When you hold the button, the first ten step values ​​are 0.1 V, then 1 V. Then, by pressing the SB1 and SB2 buttons, the discharge current is set. If these buttons are held for less than five seconds, the current value does not change and its current value is displayed, as shown in the photo in Fig. 2 (symbol і in the lower position). If the SB1 and SB2 buttons are held for more than five seconds, the current value will change in variable steps: first 50 mA, then 150 mA. In this case, the symbol і will be displayed in the top position, as shown in the photo in Fig. 3.

The maximum value of the discharge current is 2.55 A As soon as the discharge current reaches a value greater than zero (when the battery voltage is greater than the set threshold or equal to it), the sound signal will disappear and the HL1 LED will begin to blink at a frequency of 0.25 Hz. When you press the SB5 button, the voltage without load is measured and stored, then under load, the internal resistance in ohms is calculated, which is displayed in the low-order digits of the indicator with the symbol g, as shown in the photo in Fig. 4.

When you press the SB6 button, the highest digits of the HG1 indicator display the current battery voltage. When no button is pressed, the high digits of the HG1 indicator show the voltage to which the battery needs to be discharged, and the low digits show the capacity in the format XX.XX ampere-hours. Insignificant zeros of tens of volts and ampere-hours are canceled by software.

Most of the parts are mounted on a printed circuit board made of one-sided foil-coated fiberglass, a drawing of which is shown in Fig. 5 Thin rectangles show surface mount components R7, R8 and C5 installed on the side of the printed circuit conductors.

To ensure the linearity of the ITUN current throughout the entire interval, it is necessary to use op-amp DA2 with the lowest possible zero offset voltage and transistor VT1 with a low threshold voltage. In the author’s copy, the zero bias voltage of op-amp DA2 is about 4 mV and transistor VT1 with a threshold voltage of 1.85 V at a drain current of 1 A, the nonlinearity of the ITUN current did not exceed 10%. The minimum current value of ITUN is no more than 2 mA. Transistor VT1 is installed without a heat sink. A fan from a computer processor is used to cool it. The fan and device receive power from an unstabilized network adapter with an output voltage of 9.. 12 V and a load current of at least 0.5 A.

The setup consists of selecting resistors R6 and R9. By selecting resistor R6, the readings of the most significant digits of the HG1 indicator are determined using a standard voltmeter. Next, by pressing the buttons SB1 and SB2, the required value of the discharge current is displayed on the HG1 indicator, measure the ITUN current with a standard ammeter and select the resistor R9 and set the measured current equal to the readings of the HG1 indicator.

P.S. If there is no self-excitation of the microcontroller clock generator, its pins 9 and 10 should be connected to the common wire through capacitors of the same capacity 12...22 pF.

Microcontroller programs can be downloaded.


Publication date: 07.06.2012


Readers' opinions
  • [email protected] / 18.07.2019 - 21:40
    Dear Ozolin M.A. I built a layout of your circuit Radio No. 7, 2015 on ATtiny26 As I understand it, there is an error with quartz in the circuit. The diagram shows a 32768Hz clock resonator. And the fuses (H-17, L-EE) started working with 4 MHz quartz. Maybe the fuses are indicated incorrectly? Please tell me.. Where is the typo? So that the LED blinks at a frequency of 0.5Hz as in the description. Maybe you need less quartz? Type 3.2MHz/3.579575/3.68640/ Piezoceramic resonator ZTA 3.58 MHz? The diagram is simple and cool. There is nothing superfluous. It works at 4MHz for now. Thanks to you. If you tell me about quartz, it will be absolutely great. With respect, Roman.
  • Ozolin M. A / 05/11/2015 - 10:26
    Resistance R8 should be 1, not 10 kOhm! A MISTAKE OF THE EDITORS OF THE RADIO MAGAZINE AND THE ONE WHO WITHOUT LOOKING POSTED THE ARTICLE HERE. I pointed out this error to them immediately after the article was published and the correction was published in the “our consultation” section. Link to working diagram http://maxoz.ru/newAk/newAk.gif
  • Ozolin M. A / 05/11/2015 - 10:13
    Gentlemen Boris and Alexander K.G, check the serviceability of the parts, or look for errors in installation! The firmware is working and has been tested many times!
  • Alexander G.K.
    / 04/23/2015 - 10:02
  • I agree with Boris - the scheme does NOT work! After "dancing with a tambourine", it never started. The only thing that can be detected is the voltage above or below 1 V. (three or two “beeps”). Mr. M. Ozolin, don’t respond (!) - *.HEX I won’t ask. Bad business....
    Sergey / 09/18/2013 - 07:36
  • How to set fuses for controller firmware?
    Boris / 05/28/2013 - 06:59
  • The circuit does not work; when pressed, all buttons display the same numbers in the two least significant digits. Mr. M. Ozolin, will you respond?
    Vitaly / 11/16/2012 - 03:55
  • B (ITUN) - to obtain good linearity, it is better to replace the LM357N op-amp with an MCP601.
    Alexander / 10.22.2012 - 17:10

Greetings, citizens of Datagoria! Let me introduce you to my next creation - a battery capacity tester. The device, of course, is not for every day, but sometimes you can’t do without it!

I needed to measure the remaining capacity of the acid battery, in winter, after all, every Ampere counts, maybe it’s time to replace the battery? Simple tests with a load fork and density measurements did not suit me; they did not give me information about whether I would have enough energy to warm up the car for 40 minutes on the RV (about 8 A/h) and then start the car with the starter.

Battery capacity tester circuit

Like any child, it was born in pain. Mainly due to the mistakes of the “obstetrician”.

Fragment excluded. Our magazine exists on donations from readers. The full version of this article is available only



Controlled discharge controller



Fuse placement when programming the ATmega8A MK


5. All part ratings are indicated on the software.

--
Thank you for your attention!
Igor Kotov, editor-in-chief of Datagor magazine


Printed circuit board in LayOut: ▼ 🕗 10/24/14 ⚖️ 144.03 Kb ⇣ 124 Hello, reader! My name is Igor, I'm 45, I'm a Siberian and an avid amateur electronics engineer. I came up with, created and have been maintaining this wonderful site since 2006.
For more than 10 years, our magazine has existed only at my expense.

Good! The freebie is over. If you want files and useful articles, help me!

Recently, I began to notice that my smartphone began to discharge faster. The search for a software “energy eater” did not bear fruit, so I began to wonder if it was time to replace the battery. But there was no absolute certainty that the battery was the cause. Therefore, before ordering a new battery, I decided to try to measure the real capacity of the old one. To do this, it was decided to assemble a simple battery capacity meter, especially since this idea had been incubated for a long time - there are a lot of batteries and accumulators that surround us in everyday life, and it would be nice to be able to test them from time to time.

The very idea underlying the operation of the device is extremely simple: there is a charged battery and a load in the form of a resistor, you just need to measure the current, voltage and time during the battery discharge, and use the data obtained to calculate its capacity. In principle, you can get by with a voltmeter and an ammeter, but sitting at instruments for several hours is a dubious pleasure, so you can do this much easier and more accurately using a data logger. I used the Arduino Uno platform as such a recorder.

1. Scheme

There are no problems with measuring voltage and time in Arduino - there is an ADC, but to measure current you need a shunt. I had the idea to use the load resistor itself as a shunt. That is, knowing the voltage on it and having previously measured the resistance, we can always calculate the current. Therefore, the simplest version of the circuit will consist only of a load and a battery, connected to the analog input of the Arduino. But it would be nice to provide for turning off the load when the threshold voltage on the battery is reached (for Li-Ion this is usually 2.5-3V). Therefore, I included a relay in the circuit, controlled by digital pin 7 through a transistor. The final version of the circuit is shown in the figure below.

I placed all the elements of the circuit on a piece of breadboard, which is installed directly on the Uno. As a load I used a spiral of nichrome wire 0.5 mm thick, having a resistance of about 3 Ohms. This gives a calculated discharge current of 0.9-1.2A.

2. Current measurement

As mentioned above, the current is calculated based on the voltage on the spiral and its resistance. But it is worth considering that the spiral heats up, and the resistance of nichrome depends quite strongly on temperature. To compensate for the error, I simply took the current-voltage characteristic of the coil using a laboratory power supply and letting it warm up before each measurement. Next, I generated the trend line equation in Excel (graph below), which gives a fairly accurate dependence i(u) taking into account heating. It can be seen that the line is not straight.

3. Voltage measurement

Since the accuracy of this tester directly depends on the accuracy of the voltage measurement, I decided to pay special attention to this. Other articles have already repeatedly mentioned a method that allows you to most accurately measure voltage with Atmega controllers. I will repeat only briefly - the essence is to determine the internal reference voltage using the controller itself. I used the materials in this article.

4. Program

The code is not anything complicated:

Program text

#define A_PIN 1 #define NUM_READS 100 #define pinRelay 7 const float typVbg = 1.095; // 1.0 -- 1.2 float Voff = 2.5; // shutdown voltage float I; float cap = 0; float V; float Vcc; floatWh = 0; unsigned long prevMillis; unsigned long testStart; void setup() ( Serial.begin(9600); pinMode(pinRelay, OUTPUT); Serial.println("Press any key to start the test..."); while (Serial.available() == 0) ( ) Serial.println("Test is launched..."); Serial.print(" "); print("mA"); Serial.print("mAh"); Serial.print(" "); .println("Vcc"); digitalWrite(pinRelay, HIGH); testStart = millis(); prevMillis = millis(); void loop() ( Vcc = readVcc(); //read reference voltage V = (readAnalog(A_PIN) ) * Vcc) / 1023.000; //reading the battery voltage if (V > 0.01) I = -13.1 * V * V + 344.3 * V + 23.2; //calculating the current according to the I-V characteristic of the spiral else I=0; * (millis() - prevMillis) / 3600000); //calculation of battery capacity in mAh Wh += I * V * (millis() - prevMillis) / 3600000000; //calculation of battery capacity in Wh prevMillis = millis(); (); // send data to the serial port if (V< Voff) { //выключение нагрузки при достижении порогового напряжения digitalWrite(pinRelay, LOW); Serial.println("Test is done"); while (2 >1) ( ) ) ) void sendData() ( Serial.print((millis() - testStart) / 1000); Serial.print(" "); Serial.print(V, 3); Serial.print(" ") ; Serial.print(I, 1); Serial.print(cap, 0); Serial.print(" "); ); Serial.println(Vcc, 3); ) float readAnalog(int pin) ( // read multiple values ​​and sort them to take the mode int sortedValues; for (int i = 0; i< NUM_READS; i++) { delay(25); int value = analogRead(pin); int j; if (value < sortedValues || i == 0) { j = 0; //insert at first position } else { for (j = 1; j < i; j++) { if (sortedValues <= value && sortedValues[j] >= value) ( ​​// j is insert position break; ) ) ) for (int k = i; k >< (NUM_READS / 2 + 5); i++) { returnval += sortedValues[i]; } return returnval / 10; } float readVcc() { // read multiple values and sort them to take the mode float sortedValues; for (int i = 0; i < NUM_READS; i++) { float tmp = 0.0; ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); ADCSRA |= _BV(ADSC); // Start conversion delay(25); while (bit_is_set(ADCSRA, ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both tmp = (high << 8) | low; float value = (typVbg * 1023.0) / tmp; int j; if (value < sortedValues || i == 0) { j = 0; //insert at first position } else { for (j = 1; j < i; j++) { if (sortedValues <= value && sortedValues[j] >= value) ( ​​// j is insert position break; ) ) ) for (int k = i; k > j; k--) ( // move all values ​​higher than current reading up one position sortedValues[k] = sortedValues; ) sortedValues[j] = value; //insert current reading ) //return scaled mode of 10 values ​​float returnval = 0;< (NUM_READS / 2 + 5); i++) { returnval += sortedValues[i]; } return returnval / 10; }

for (int i = NUM_READS / 2 - 5; i
In my opinion, the only interesting point in the code would be the use of a digital filter. The fact is that when reading voltage, the values ​​inevitably “dance” up and down. At first I tried to reduce this effect by simply taking 100 measurements in 5 seconds and taking the average. But the result still did not satisfy me. During my searches, I came across such a software filter. It works in a similar way, but instead of averaging, it sorts all 100 measurement values ​​in ascending order, selects the central 10, and calculates the average of them. The result impressed me - measurement fluctuations stopped completely. I decided to use it to measure the internal reference voltage (readVcc function in the code).

5. Results

The data from the serial port monitor is imported into Excel in a few clicks and looks like this:

In the case of my Nexus 5, the declared capacity of the BL-T9 battery is 2300 mAh. The one I measured is 2040 mAh with a discharge of up to 2.5 V. In reality, the controller is unlikely to allow the battery to drain to such a low voltage, most likely the threshold value is 3V. The capacity in this case is 1960 mAh. A year and a half of phone service led to a loss of capacity by about 15%. It was decided to hold off on purchasing a new battery.
Using this tester, several other Li-Ion batteries have already been discharged. The results look very realistic. The measured capacity of new batteries coincides with the declared capacity with a deviation of less than 2%.
This tester is also suitable for metal hydride AA batteries. The discharge current in this case will be about 400 mA.