Driver for Texas Instruments' battery state-of-charge estimator.

Dependents:   BQ34Z100G1-Utils BQ34Z100G1-ChemIDMeasurer

You are viewing an older revision! See the latest version

Setup and Calibration Guide

AKA: The missing manual for TI's battery gauges.

This page will walk you through the whole process of configuring and calibrating the BQ34Z100G1 fuel gauge IC.

What You Need

In order to create the initial calibration (golden image in TI-speak), you will need to perform tests on your first board of your design. To do this, you need:

  • Your PCB with a BQ34Z100G1 on it and the battery attached to it. It will also need to have a header to access the I2C bus, a way to charge it (such that current flows through the BQ34Z100G1 when charging), and some place for you to attach a dummy load.
    • Your life will be even easier if you can set it up so that the dummy load and the battery charger can be automatically controlled by the CPU. Otherwise, expect to do a lot of babysitting during the calibration process.
  • A dummy load which can discharge your battery. I recommend a power resistor attached to a metal block. The load should discharge the battery at between 1/5 C and 1/10 C.
  • A TI EV2300 or EV2400 programmer box. These are kinda expensive but you can try to find them on Ebay (especially the older EV2300) for cheaper.
  • An accurate voltmeter
  • Ideally, an accurate current meter (though this is not strictly required).

Note about C rates: 1C refers to current that would exhaust the battery's capacity in 1 hour. So, if you have a 1500mAh battery, a 1C discharge rate is 1.5A, and a 1/10 C discharge rate would be 0.15A.

Code Settings

The first step in getting the BQ34Z100G1 (BQ34 for short) running is to configure all of the constants in code to match your board. You'll notice this block at the top of the BQ34Z100.h file:

Library configuration

//Battery configuration settings
//Stored in flash: run flashSettings() then reset sensor to save
#define DESIGNCAP 1400 //mAh, per cell (Page 48, offset 11)
#define DESIGNENERGY 5180 //mWh, per cell (Page 48, offset 14)
#define CELLCOUNT 0x04 //number of series cells (Page 65, offset 7)
#define LEDCONFIG 0x4b //5-LED Expander with I2C host comm (Page 64, offset 4)
#define VOLTSEL true //Switches to an external battery voltage divider
#define ZEROCHARGEVOLT 3375 //mV, charge cut-off voltage/Cell terminate voltages
#define FLASH_UPDATE_OK_VOLT 2800 // mV, below this voltage per cell flash writes will not go through

#define QMAX0 10000 //mAh, datasheet says to use c-rate current (max discharge current)

//The voltage divider works by this formula: Gain = (TOP LEG R/BOTTOM LEG R)*1000
//Top leg: 294Kohm and bottom leg: 16.5Kohm
//This only works if you enable the external voltage divider (VOLTSEL) option for the sensor
//Note: requires calibration after setting in flash
#define VOLTAGEGAIN 17818
#define LOADSELECT 0x01 // "Load Select defines the type of power or current model to be used to compute load-compensated capacity in the Impedance Track algorithm"
#define LOADMODE 0x00 // "Load Mode is used to select either the constant current or constant power model for the Impedance Track algorithm"
#define RESETVOLTAGE 22200 //mV, voltage to reset to after unsuccessful voltage calibration

//Sense resistor value
#define SENSE_RES 5.0f //mOhms, value of guage sense resistor

#define USE_EXTERNAL_THERMISTOR 0 // If 1, use an external thermistor connected to the IT pin.  If 0, use the internal temp sensor.

The comments should be fairly self-explanatory, but make sure that all values are configured appropriately for your application circuit.

For the LEDCONFIG value, see the "LED Display" section (7.3.13) in the BQ34 datasheet.

Care should be taken regarding the ZEROCHARGEVOLT value, especially if you are using an undervoltage protection IC that disconnects the battery if it goes below a certain voltage. When discharging, the battery needs to actually go below (ZEROCHARGEVOLT * CELLCOUNT / 1000) volts or the BQ34 won't see it as being completely discharged, so you won't be able to calibrate. So, make sure the ZEROCHARGEVOLT puts you above the undervoltage lockout threshold.

Note: We have only ever used this driver with lithium batteries. For non-lithium batteries a couple other settings will need to be programmed which are currently not implemented by the driver, see datasheet section 8.2.3.1.

Initial Configuration and Calibration

To perform initial configuration of the chip, you will need to flash the BQ34Z100G1-Utils program we created. Make sure that the changes you made to BQ34Z100.h get copied into that program's copy of that file.

  1. Run the "Test Connection to Sensor" test. This will verify that the BQ34 is correctly connected and communicating. If it fails, check that the I2C pins and address in the header are right.
  2. Run "Write Settings to Flash". This will take all the settings you wrote into the h file and download them to the BQ34's flash memory.
  3. Run the "Calibrate Voltage" test. This will require you to enter the voltage across the battery, and then it will set the BQ34's voltage measurement scaling to match this reading.
  4. Connect the dummy load, then run the "Calibrate Current" test. This will guess the BQ34 current scaling factor based on your sense resistor, and then refine the guess based on a real current reading. If you aren't set up to read the current from a real measurement, you can also calculate it fairly accurately if you know the battery voltage and the resistance of the load.

After these steps, if you run "Display Data", you should now see accurate voltage and current values.

Finding the Chem ID

Next, you need to run an initial calibration process that analyzes your battery's charging and discharging behavior. How this works is, you make a CSV file logging voltage and current through one complete charge-discharge cycle of your battery. Then, you upload it to a Texas Instruments website, which runs it through a MathCAD script on their server and returns you the result. Finally, you feed the result number into TI's bqStudio software and their programmer will download the appropriate data into the chip's memory. Does this sound Rube Goldbergian enough? Ok good, let's get started.

Running the Measurement

  1. Download and build our ChemIDMeasurer Mbed application. As before, make sure to edit BQ34Z100.h and add your configuration settings. Also, if you have a charger and/or load that can be automatically controlled, edit the charger and load activation/deactivation functions in ChemIDMeasurer.cpp.
  2. Discharge your battery somewhat. It does not need to below the zero charge voltage, but it should be below half its maximum voltage.
  3. Set up logging in your terminal program so that data will be saved to a file as it is printed.
  4. Run ChemIDMeasurer on your board. If you don't have automatic charging, turn on the charger now.
  5. Wait for the battery to charge fully. The program will detect when the current gets below a certain value (C/10). If you don't have automatic charging, turn off the charger when indicated.
  6. Give the battery two hours to relax. After this time, the program will prompt you to enable the load. The battery should ideally be discharged at a C/10 rate.
  7. Wait for the discharge process to complete. Once the voltage gets below the termination voltage, the program will prompt you to disconnect the load.
  8. Give the battery 5 hours to relax. After this amount of time has passed, the program will end.

Getting the Chem ID

  1. Save all the data that ChemIDMeasurer printed into a CSV file. TI requires you to name the file roomtemp_rel_dis_rel.csv.
  2. Create the config file (config.txt) that describes the CSV file. The config.txt included in the ChemIDMeasurer repository should be already right for the data it outputs, all you need to do is edit the line that says NumCellSeries to have the number of cells in your battery pack.
  3. Zip up roomtemp_rel_dis_rel.csv and config.txt into a .zip file, and upload them into the GPC (Gauging Parameter Calculator) tool here.
  4. If everything went well, you will soon get an email containing the best Chem ID for your battery pack.

Programming the Chem ID

  1. Connect the EV2300 or EV2400 programmer to your board's I2C bus.
  2. Open the bqStudio app and connect to the IC.
  3. Go to the Chemistry tab and search through the list of chemistries until you find one with the number that was sent to you by GPC.
  4. Click the update chemistry button at the bottom.
  5. It should flash the chemistry data onto the IC. Your BQ34 should now be set up for your battery pack!

Calibrating the Gauge

Finally, your BQ34 has been set up with all the information about your battery! Now it's time to calibrate it. The calibration procedure for the BQ34 seems to be a bit of a black incantation, and there are a bunch of different, often conflicting procedures out on the net. The one that worked best for me was on the 4th post of |this thread. I'll reproduce it below with some edits for clarity.

The basic idea of the procedure is to complete two full charge and discharge cycles using the battery pack, with a few extra commands thrown in. The charge cycles should be such that the battery charges all the way up and the Full Charge flag on the BQ34 sets, and the discharge cycles should be such that the pack goes below the zero charge voltage but does not trigger its undervoltage protection.

One thing that will be useful in your calibration process is the Output Status test in BQ34Z100-Utils. This test prints every status flag that the BQ34 supports. https://cdn.discordapp.com/attachments/586386027518754847/787041720160223272/unknown.png Also take notice of the Update Status flag, which is an indicator of "how calibrated" the chip is (see datasheet section 7.3.6.10 for values).

All of these steps can be done manually using the Utils code, or you can write your own program to run them automatically.

Calibration Procedure:

  1. Activate impedance tracking.
  2. Charge the pack to charge termination.
  3. Allow the pack to rest until the OCVTAKEN flag becomes 1.
  4. Discharge the pack at a C/10 to C/5 rate to the Termination Voltage.
  5. Allow the pack to rest until the OCVTAKEN flag becomes 1. Qmax should update and Update Status should increment to 05.
  6. Fully charge the pack to charge termination.
  7. Allow the pack to rest until the OCVTAKEN flag becomes 1.
  8. Discharge the pack at a C/10 to C/5 rate to the Termination Voltage.
  9. Allow the pack to rest until the OCVTAKEN flag becomes 1. The Ra table should update and Update Status should increment to 06.

After this procedure, your BQ34 should be calibrated! If the Update Status does not display the right value, you may need to run one or two additional cycles to give it some extra time to calibrate. If it still is not fully calibrated, then you may have a configuration problem that's keeping the chip from calibrating. We saw this behavior when settings like the thermistor selection or the Chem ID were configured wrong.

Once you do get Update Status 0x6, you can use the EV2400 to extract your golden image and flash it onto other chips!


All wikipages