Application Report
SLUA355B – August 2005 – Revised January 2010
Data Flash Programming and Calibrating the bq20z80
Family of Gas Gauges
Jackie Hui ......................................................................................................... High Precision Analog
ABSTRACT
This application report presents a strategy for high-speed, economical calibration and data flash
programming of the bq20z80 advanced gas gauge chipset family. VB6 code examples are provided, along
with step-by-step instructions for preparing a golden battery pack.
Contents
1 Introduction .................................................................................................................. 1
2 Preparing the Golden Pack ................................................................................................ 2
3 Reading and Saving the Data Flash Image From the Golden Pack ................................................. 3
4 Writing the Data Flash Image to Each Target Device .................................................................. 4
5 Calibration .................................................................................................................... 4
6 Writing Pack-Specific Data Flash Locations ............................................................................. 6
Appendix A How to Convert Between DFI and ROM File Types Using bqEASY™ Software .......................... 7
List of Figures
1 bqEASY™ 1B Load/Read .DFI or .ROM File Page ................................................................... 7
2 Select DFI file manually .................................................................................................... 8
3 Click Program Dataflash Image ........................................................................................... 8
4 Select ROM file manually .................................................................................................. 9
List of Tables
1 Introduction
The bq20z80 family of advanced gas gauges is built with new technology and a new architecture for both
data flash access and calibration. With this new architecture, unit production cost and capital equipment
investment can be minimized, as there is no longer a need to perform a learning cycle on each pack. A
single “golden pack” can become the source of data for all other packs. A method is shown to quickly read
and write the golden image. Also, the calibration method is now quick and simple because the calibration
routines are built into the firmware of the target device.
The methods in this document are presented as VB6 (Visual Basic 6) functions. These functions were
copied directly from working code. In order to read from and write to the data flash, they use five types of
SMBus read and write functions. These can be duplicated in any software environment that has SMBus
communication capabilities. As used herein, each Read/Write function is designed for communication with
a gas gauge, so the device address (0x16) is omitted for clarity.
1. WriteSMBusInteger() has two arguments – the SMBus command and a signed integer. Internally, this
function separates the integer into two bytes for transmission by the SMBus write-word protocol.
2. WriteSMBusByteArray() has three arguments – the SMBus command, the array of bytes and an
integer specifying the length of the byte array. Internally, this function separates the byte array into
separate bytes for transmission by the SMBus write-block protocol.
3. WriteSMBusCommand() has only one argument – the SMBus command.
4. ReadSMBusWord() has three arguments – the SMBus command, the returned upper byte and
Impedance Track is a trademark of Texas Instruments.
SLUA355B – August 2005 – Revised January 2010 Data Flash Programming and Calibrating the bq20z80 Family of Gas Gauges 1
Submit Documentation Feedback
Copyright © 2005–2010, Texas Instruments Incorporated
Preparing the Golden Pack www.ti.com
returned lower byte. This one is especially useful for reading specific bit patterns.
5. ReadSMBusByteArray() has three arguments – the SMBus command, the returned array of bytes, and
the returned length of the byte array. It is internally implemented with the SMBus read-block protocol.
Also used in these functions is a simple delay routine called DoDelay. VB6 code for this procedure is
provided at the end of the document.
Error handling is not implemented in this sample code, because requirements are unique and varied. Also,
constants are hard-coded into the functions to improve clarity rather than documenting them in code
elsewhere as would normally be good coding practice.
A good strategy for production is a seven-step process flow:
1. Write the data flash image to each device. This image was read from a golden pack.
2. Calibrate the device.
3. Update any individual flash locations, such as serial number, lot code, and date.
4. Perform any desired protection tests.
5. Connect the cells.
6. Initiate the Impedance Track™ algorithm
7. Seal the pack.
In this document, the first three steps are examined in detail.
2 Preparing the Golden Pack
Impedance Track™ technology allows the bq20z80 gas gauge to automatically acquire and maintain
parameters for battery modeling needed for continuous accuracy, regardless of battery model or
manufacturer. The ICs are shipped preprogrammed with default values for these parameters. In the
course of daily use (charge, discharge, unused), the algorithm collects new parameters. Parameter
acquisition is complete after one full discharge cycle and subsequent relaxation takes place.
The default parameters that are used for fuel gauging prior to discharge activity are less accurate than
parameters acquired during such activity. Therefore, the error of the gas gauge is more than the 1% that
is achieved after parameter acquisition. It is desirable to have optimal accuracy in the battery packs
coming from the production line even before any discharge activity occurs. This can be accomplished by
performing a discharge cycle on one battery pack (let it acquire optimized parameters), save its data flash
in a file, and then program the golden data into all battery packs coming from the production line.
2.1 Creating Pre-Learned Defaults
1. Assemble a battery pack with the bq20z80 solution, which includes setting basic flash constants for a
given pack configuration, calibrating the pack, connecting System Present to ground, and enabling IT.
This is described in detail in the application report Pack Assembly and the bq20z80 (SLUA335).
2. In particular, it is important to set parameters specific to the number of serial cells used. This is
described in application report bq20z80 EVM Data Flash Settings for Number of Serial Cells and Pack
Capacity (SLVA208 ).
3. To achieve maximum accuracy of first cycle parameter acquisition, set an initial guess for Qmax Cell 0,
Qmax Cell 1, Qmax Cell 2, Qmax Cell 3 and Qmax Pack. These values are in mAh as specified in the
battery manufacturer data sheet. For example, if single-cell data-sheet capacity is 2400 mAh and 3
parallel cells are used, set each value to 2400 × 3 = 7200 mAh.
4. Charge the pack to full.
5. Let it relax for 2 hours.
6. Discharge the pack to the minimum system-acceptable voltage (should be the same as DF.Gas
Gauging.IT Cfg.Term Voltage) at the typical application rate. The exact rate is not critical.
7. Let it relax for 5 hours.
8. Repeat steps 4 through 7 to achieve maximum impedance table accuracy. Verify that DF.Gas
Gauging.State.Update Status reads 06. If not, repeat the cycle. Its normal value should be 06.
9. Use the EVSW to export the .gg File. Open the .gg file with Notepad to change DF.Gas
Gauging.State.UpdateStatus to 02. Change DF.SBS Configuration.Data.Cycle Count to 0.
10. Reprogram the pack with a fresh .srec or .senc to clear all hidden constants.
2 Data Flash Programming and Calibrating the bq20z80 Family of Gas Gauges SLUA355B – August 2005 – Revised January 2010
Submit Documentation Feedback
Copyright © 2005–2010, Texas Instruments Incorporated
www.ti.com Reading and Saving the Data Flash Image From the Golden Pack
11. Use the EVSW to import the modified .gg file as saved in step 9. Write All.
12. Send reset command (0x0041).
The golden pack is now ready to have its data flash read into a binary file as described in the function
listed in Section 3.
3 Reading and Saving the Data Flash Image From the Golden Pack
Two types of files are associated with a golden image file: a ROM file and a DFI file. Both are binary files
with data flash information, but a ROM file contains additional headers. The sample code that follows is an
example of how to save the golden image in a DFI file. If saving the golden image in a ROM file is desired,
see Appendix A. Note that this step only needs to be done once for a given project.
Function SaveDataFlashImageToFile(sFileName As String) As Long
Dim iNumberOfRows As Integer
Dim lError As Long
Dim yRowData(32) As Byte
Dim yDataFlashImage(&H700) As Byte
Dim iRow As Integer Dim iIndex As Integer
Dim iLen As Integer Dim iFileNumber As Integer
'// FOR CLARITY, WITHOUT USING CONSTANTS
'// 0x700 is the data flash size for bq8024-based devices (eg: bq20z80). 0x700 \ 32 = 56 rows
iNumberOfRows = &H700 \ 32
'// PUT DEVICE INTO ROM MODE
lError = WriteSMBusInteger(&H0, &HF00)
DoDelay 0.01
'// READ THE DATA FLASH, ROW BY ROW
For iRow = 0 To iNumberOfRows - 1
'// Set the address for the row. &H9 (0x09) is the ROM mode command.
'// 0x200 is the row number where data flash starts.
'// Multiplication by 32 gives us the actual physical address where each row starts
lError = WriteSMBusInteger(&H9, (&H200 + iRow) * 32)
'// Read the row. &HC (0x0c) is the ROM mode command.
lError = ReadSMBusByteArray(&HC, yRowData, iLen)
'//Copy this row into its place in a big byte array
For iIndex = 0 To 32 - 1
yDataFlashImage((iRow * 32) + iIndex) = yRowData(iIndex)
Next iIndex
Next iRow
'// WRITE DATA FLASH IMAGE TO FILE
iFileNumber = FreeFile
Open sFileName For Binary Access Write As #iFileNumber
Put #iFileNumber, , yDataFlashImage
Close #iFileNumber
'// EXECUTE GAS GAUGE PROGRAM
lError = WriteSMBusCommand(&H8)
End Function
SLUA355B – August 2005 – Revised January 2010 Data Flash Programming and Calibrating the bq20z80 Family of Gas Gauges 3
Submit Documentation Feedback
Copyright © 2005–2010, Texas Instruments Incorporated
Writing the Data Flash Image to Each Target Device www.ti.com
4 Writing the Data Flash Image to Each Target Device
Two types of files are associated with a golden image file: the ROM file and the DFI file. The sample code
that follows is an example of how to write a DFI file to the target device. To write with a ROM file, see
Appendix A. The following method is fast. It only takes about 2 seconds to write the entire data flash in
this manner.
CAUTION
If power is interrupted during this process, the device may become unusable.
Function WriteDataFlashImageFromFile(sFileName As String) As Long
Dim lError As Long
Dim iFileNumber As Integer
Dim iNumberOfRows As Integer
Dim iRow As Integer
Dim iIndex As Integer
Dim yRowData(32) As Byte
Dim yDataFlashImage(&H700) As Byte
'// READ THE FLASH IMAGE FROM THE FILE INTO A BYTE ARRAY
iFileNumber = FreeFile
Open sFileName For Binary Access Read As #iFileNumber
Get #iFileNumber, , yDataFlashImage
Close #iFileNumber
'// FOR CLARITY, WITHOUT USING CONSTANTS
'// 0x700 is the data flash size for bq8024-based devices (eg: bq20z80). 0x700 \ 32 = 56 rows
iNumberOfRows = &H700 \ 32
'// PUT DEVICE INTO ROM MODE
lError = WriteSMBusInteger(&H0, &HF00)
DoDelay 0.01
'// ERASE AND WRITE EACH ROW
For iRow = 0 To iNumberOfRows - 1
'// Set the row to program
yRowData(0) = iRow
'// Copy data from the full array to the row array
For iIndex = 0 To 31
yRowData(iIndex + 1) = yDataFlashImage((iRow * 32) + iIndex)
Next iIndex
// Erase the row
' lError = WriteSMBusInteger(&H11, iRow)
DoDelay 0.01
'// Write the row. Length is 33 because the first byte is the row number
lError = WriteSMBusByteArray(&H10, yRowData, 32 + 1)
DoDelay 0.01
Next iRow
'// EXECUTE GAS GAUGE PROGRAM
lError = WriteSMBusCommand(&H8)
End Function
5 Calibration
Devices in the bq20z80 family of advanced gas gauges are quick and easy to calibrate. It only takes about
3 seconds to accurately calibrate offsets, voltage, temperature, and current. With the Impedance Track™
devices, the calibration routines have been incorporated into firmware algorithms, which can be initiated
4 Data Flash Programming and Calibrating the bq20z80 Family of Gas Gauges SLUA355B – August 2005 – Revised January 2010
Submit Documentation Feedback
Copyright © 2005–2010, Texas Instruments Incorporated
www.ti.com Calibration
with SMBus commands. The hardware for calibration is also simple. One current source, one voltage
source, and one temperature sensor are all that is required. The accuracy of the sources is not important,
only their stability. However, accurately calibrated reference measurement equipment should be used for
determining the actual arguments to the function. For periodic voltage measurement, a DVM with better
than 1-mV accuracy is required.
The elapsed time for calibration can be changed by modifying values in the data flash, but this is not
recommended. Use the default values for the times in DF.Calibration.Config
In the CalibrateAll( ) function, command 0x51 is used to setup a complete calibration of the device. Pack
voltage calibration is generally not performed because its accuracy is not required for standard
applications. In this case, Pack Voltage refers to a separate measurement of the voltage at the pack
terminal and is unrelated to the SBS.Voltage( ) measurement.
The definition of the bits in command 0x51 are:
Bit 0 Coulomb Counter Offset Bit 8 Pack Gain
Bit 1 Board Offset Bit 9 Pack Voltage
Bit 2 ADC Offset Bit 10 AFE Error
Bit 3 Temperature, Internal Bit 11 Reserved
Bit 4 Temperature, External 1 Bit 12 Reserved
Bit 5 Temperature, External 2 Bit 13 Reserved
Bit 6 Current Bit 14 Run ADC Task Continuously
Bit 7 Voltage Bit 15 Run CC Task Continuously
Bits 14 and 15 should always be set. These cause the Coulomb Counter and ADC tasks to run
continuously, just as they do in normal operation. This has been found to increase the accuracy of the
calibration.
After command 0x51 is issued, the calibration sequence is started in the firmware of the gas gauge. The
calibrations are run in sequence starting from the least significant bit. Then, command 0x52 is used to poll
these bits, which change from high to low as the tasks are completed. However, bits 14 and 15 do not
change; hence, the masking of them in the polling loop.
It can be seen from this code that a simple modification to command 0x51 would allow it to work as a
single function calibration. For example, to only calibrate voltage, only bit 7 could be set.
Function CalibrateAll(iVoltage As Integer, iCurrent As Integer, iTemperature As Integer, iCells
As Integer) As Long
'// iVoltage is in millivolts
'// iCurrent is in milliamps (normally negative, such as -2000)
'// iTemperature is in Kelvin/10 units, so the argument is: 10 * (Celsius + 273.15)
Dim lError As Long
Dim bDoingCal As Boolean
Dim yLS As Byte
Dim yMS As Byte
'// GO TO CALIB MODE
lError = WriteSMBusInteger(&H0, &H40)
'// WRITE THE NUMBER OF CELLS
lError = WriteSMBusInteger(&H63, iCells)
'// WRITE THE ACTUAL VOLTAGE, CURRENT & TEMPERATURE
lError = WriteSMBusInteger(&H60, iCurrent)
lError = WriteSMBusInteger(&H61, iVoltage)
lError = WriteSMBusInteger(&H62, iTemperature)
'// START CALIBRATION
'// Useful cal lo byte &HD5 - External temperature sensor 1
'// &HF5 - External temperature sensor 1 and 2
'// &HCD - Internal temperature sensor
SLUA355B – August 2005 – Revised January 2010 Data Flash Programming and Calibrating the bq20z80 Family of Gas Gauges 5
Submit Documentation Feedback
Copyright © 2005–2010, Texas Instruments Incorporated
Writing Pack-Specific Data Flash Locations www.ti.com
lError = WriteSMBusInteger(&H51, &HC0D5)
'// POLL STATUS
bDoingCal = True
While bDoingCal
lError = ReadSMBusWord(&H52, yMS, yLS)
bDoingCal = (yMS And &H3F) Or yLS
DoDelay 0.2 '// check every 200 millisecond
Wend
'// TRANSFER RESULTS TO DATAFLASH
lError = WriteSMBusCommand(&H72)
DoDelay 0.1 '// Insure write process is finished
'// EXIT CALIB MODE
lError = WriteSMBusCommand(&H73)
End Function
6 Writing Pack-Specific Data Flash Locations
The third step is to fine tune the data flash a little for each pack, to give it a unique identity. In the following
example, the pack Serial Number is written using subclass and offset information found in the gas gauge
product data sheet. Modifications to single data flash locations normally require a block read of the
32-byte data flash page, then updating the desired element of the block, and writing it back to the device.
This procedure is documented in the product data sheet.
Function WritePackSerialNumber(iSerialNumber As Integer) As Long
Dim lError As Long
Dim yData(32) As Byte
Dim iLen As Integer
'// SET THE SUBCLASS TO 48 (FOUND IN PRODUCT DATASHEET)
lError = WriteSMBusInteger(&H77, 48)
'// READ THE PAGE
lError = ReadSMBusByteArray(&H78, yData(), iLen)
'// REPLACE THE TWO BYTES AT OFFSET 12 (FOUND IN DATASHEET) WITH NEW S/N
yData(12) = (iSerialNumber And &HFF00) \ 256 '// modify MS
byte yData(13) = iSerialNumber And &HFF '// modify LS byte
'// WRITE THE PAGE BACK TO FLASH
lError = WriteSMBusByteArray(&H78, yData(), iLen)
'// FLASH WRITES ARE SLOW
DoDelay 0.1
End Function
Sub DoDelay(fWaitTime As Single)
Dim vTime As Variant
vTime = Timer
While Timer < (vTime + fWaitTime)
'// fix midnight problem
If Timer < vTime Then Exit Sub
'// Yield to various Windows events while the delay is in progress
DoEvents
Wend
End Sub
6 Data Flash Programming and Calibrating the bq20z80 Family of Gas Gauges SLUA355B – August 2005 – Revised January 2010
Submit Documentation Feedback
Copyright © 2005–2010, Texas Instruments Incorporated
www.ti.com
Appendix A How to Convert Between DFI and ROM File Types Using bqEASY™ Software
A.1 Introduction
Two file types are associated with data flash image, a .ROM file and a .DFI file. A .ROM file contains data
flash information in binary format, plus some headers related to the target device. This file is used by the
bqMTester, a TI production tool. A .DFI file is also a binary file, but with only the data flash information.
This file is produced by TI evaluation tool – bqEASY™. The data flash read/write sample codes in this
application report are used to handle DFI file types. Although both files are similar, ROM and DFI files are
not interchangeable.
From bqEASY™ v1.85 (or later) software, the ability to read a ROM file into a target device, or to write the
data flash image from a target device to a ROM file, was added. By having the related EVM in hand, a
user can apply this new feature to convert between DFI and ROM file types to fit into their
production/evaluation setting.
A.2 Create a ROM File From a DFI File
The read and write data flash image features are available in bqEASY™ 1B. Load/Read .DFI or .ROM File
page (under 1. Setup), shown in Figure 1.
Figure 1. bqEASY™ 1B Load/Read .DFI or .ROM File Page
SLUA355B – August 2005 – Revised January 2010 Data Flash Programming and Calibrating the bq20z80 Family of Gas Gauges 7
Submit Documentation Feedback
Copyright © 2005–2010, Texas Instruments Incorporated
Create a .DFI File From a ROM File www.ti.com
1. To Create a .ROM file From a .DFI File
(a) Connect to the target device before starting the bqEASY™ software. (For example, to convert a
bq20z90-v150 ROM file to DFI file, connect the bq20z90 EVM to the PC before starting the
software.)
(b) Start the EVSW, and go to bqEASY™. Click on 1. Setup” tab and go to the 1B. Load/Read .DFI or
.ROM File page (see Figure 1).
(c) Choose the “Select DFI file manually” radio button; a “Browse…” button appears. Click on
“Browse…” to select the .DFI file from the local computer.
Figure 2. Select DFI file manually
(d) Click the Program Dataflash Image button to program the selected .DFI file to the target device.
Figure 3. Click Program Dataflash Image
(e) The target device contains the dataflash image of the .DFI file on completion of the programming.
Click Read Dataflash (.ROM) button to read the image out in ROM format. A save-dialog box
appears; select the desired directory and filename. A ROM format of the dataflash image will be
saved to the computer.
A.3 Create a .DFI File From a ROM File
Creating a DFI file from a ROM file is basically the same manner as described in Section 2.
1. To Create a .DFI File From a .ROM file
(a) Connect the target device to PC before starting EVSW.
(b) Go to bqEASY™ 1B. Load/Read .DFI or .ROM File page (see Figure 1).
(c) Choose the “Select ROM file manually” radio button, and click on “Browse…” to select the .ROM
file from the local computer.
8 Data Flash Programming and Calibrating the bq20z80 Family of Gas Gauges SLUA355B – August 2005 – Revised January 2010
Submit Documentation Feedback
Copyright © 2005–2010, Texas Instruments Incorporated
www.ti.com Create a .DFI File From a ROM File
Figure 4. Select ROM file manually
(d) Click Program Dataflash Image button to program the selected .ROM file to the target device.
(e) On completion of data flash programming, click Read Dataflash (.DFI) button to read the data flash
out in .DFI format.
SLUA355B – August 2005 – Revised January 2010 Data Flash Programming and Calibrating the bq20z80 Family of Gas Gauges 9
Submit Documentation Feedback
Copyright © 2005–2010, Texas Instruments Incorporated
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements,
and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should
obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are
sold subject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI’s standard
warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where
mandated by government requirements, testing of all parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and
applications using TI components. To minimize the risks associated with customer products and applications, customers should provide
adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right,
or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information
published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a
warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual
property of the third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied
by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive
business practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional
restrictions.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all
express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not
responsible or liable for any such statements.
TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product would reasonably
be expected to cause severe personal injury or death, unless officers of the parties have executed an agreement specifically governing
such use. Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, and
acknowledge and agree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their products
and any use of TI products in such safety-critical applications, notwithstanding any applications-related information or support that may be
provided by TI. Further, Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products in
such safety-critical applications.
TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products are
specifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as military-grade meet military
specifications. Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely at
the Buyer's risk, and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use.
TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products are
designated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they use any non-designated
products in automotive applications, TI will not be responsible for any failure to meet such requirements.
Following are URLs where you can obtain information on other Texas Instruments products and application solutions:
Products Applications
Amplifiers amplifier.ti.com Audio www.ti.com/audio
Data Converters dataconverter.ti.com Automotive www.ti.com/automotive
DLP® Products www.dlp.com Communications and www.ti.com/communications
Telecom
DSP dsp.ti.com Computers and www.ti.com/computers
Peripherals
Clocks and Timers www.ti.com/clocks Consumer Electronics www.ti.com/consumer-apps
Interface interface.ti.com Energy www.ti.com/energy
Logic logic.ti.com Industrial www.ti.com/industrial
Power Mgmt power.ti.com Medical www.ti.com/medical
Microcontrollers microcontroller.ti.com Security www.ti.com/security
RFID www.ti-rfid.com Space, Avionics & www.ti.com/space-avionics-defense
Defense
RF/IF and ZigBee® Solutions www.ti.com/lprf Video and Imaging www.ti.com/video
Wireless www.ti.com/wireless-apps
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2010, Texas Instruments Incorporated