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.
- 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.
- Run "Write Settings to Flash". This will take all the settings you wrote into the cpp file and download them to the BQ34's flash memory.
- 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.
- 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
- 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.
- Discharge your battery somewhat. It does not need to below the zero charge voltage, but it should be below half its maximum voltage.
- Set up logging in your terminal program so that data will be saved to a file as it is printed.
- Run ChemIDMeasurer on your board. If you don't have automatic charging, turn on the charger now.
- 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.
- 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.
- Wait for the discharge process to complete. Once the voltage gets below the termination voltage, the program will prompt you to disconnect the load.
- Give the battery 5 hours to relax. After this amount of time has passed, the program will end.
Getting the Chem ID
- Save all the data that ChemIDMeasurer printed into a CSV file. TI requires you to name the file
roomtemp_rel_dis_rel.csv
. - 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. - 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.
- If everything went well, you will soon get an email containing the best Chem ID for your battery pack.
Programming the Chem ID
- Connect the EV2300 or EV2400 programmer to your board's I2C bus.
- Open the bqStudio app and connect to the IC.
- 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.
- Click the update chemistry button at the bottom.
- It should flash the chemistry data onto the IC. Your BQ34 should now be set up for your battery pack!