zoukankan      html  css  js  c++  java
  • bq27441-G1 工作机制

    /***************************************************************************
     *                        bq27441-G1 工作机制
     * 声明:
     *     本文主要是记录分析bq27441-G1芯片是如何工作的,以及其中的一些参数是
     * 如何进行配置的。
     *
     *                                         2016-2-19 深圳 南山平山村 曾剑锋
     **************************************************************************/
    
    
    一、参考文档:
        1. bq27441-G1 Technical Reference
            http://www.ti.com/lit/ug/sluuac9a/sluuac9a.pdf
        2. Quickstart Guide for bq27441-G1
            http://www.ti.com/lit/ug/sluuap7/sluuap7.pdf
    
    二、General Description
        The key to the high-accuracy, fuel gauging prediction is Texas Instruments proprietary Impedance Track™ algorithm. This algorithm uses cell measurements, characteristics, and properties to create SOC predictions that can achieve high accuracy across a wide variety of operating conditions and over the lifetime of the battery.
        精确计算并预测电池容量采用的是TI的阻抗跟踪算法。
        The fuel gauge measures the charging and discharging of the battery by monitoring the voltage across a small-value, external sense resistor. Cell impedance is computed based on current, open-circuit voltage (OCV), and cell voltage under loading conditions.
        电池计量器检测外扩的传感电阻来判断是充电,还是放电。
        The fuel gauge uses an integrated temperature sensor for estimating cell temperature. Alternatively, the system processor can provide temperature data for the fuel gauge.
        电池计量器内部的温度传感器来估算电池温度。
        To minimize power consumption, the fuel gauge has several power modes: INITIALIZATION, NORMAL, SLEEP, HIBERNATE, and SHUTDOWN. The fuel gauge passes automatically between these modes, depending upon the occurrence of specific events, though a system processor can initiate some of these modes directly.
        为了达到最小的功耗,电池计量器有以下几种状态:INITIALIZATION, NORMAL, SLEEP, HIBERNATE, and SHUTDOWN。
    
    三、Temperature Measurement
        The fuel gauge measures temperature via its internal on-chip sensor. This internal temperature data will be used by the Impedance Track™ algorithm if the OpConfig [TEMPS] bit is cleared. Alternatively, if the OpConfig [TEMPS] bit is set, the system processor can set the temperature for the fuel gauging algorithm by writing to the Temperature() register.
        电池计量器温度测量采用芯片内部的传感器。
    
    四、CONFIG UPDATE Mode
        If the application requires different configuration data for the fuel gauge, the system processor can update RAM-based Data Memory parameters using the Control() SET_CFGUPDATE subcommand to enter the CONFIG UPDATE mode. Operation in this mode is indicated by the Flags() [CFGUPMODE] status bit. In this mode, fuel gauging is suspended while the host uses the extended data commands to modify the configuration data blocks.
        如果需要自行对电池流量器进行参数配置,系统处理器可以通过Control() SET_CFGUPDATE子命令进入CONFIG UPDATE模式修改RAM-based数据内存参数。是否工作在CONFIG UPDATE模式下,可以查看Flags()[CFGUPMODE]状态位。在该模式下,当系统采用扩展数据命令修改配置数据时,电池计量器被挂起。
        To resume fuel gauging, the host sends a Control() SOFT_RESET, EXIT_CFGUPMODE, or EXIT_RESIM subcommand to exit the CONFIG UPDATE mode which clears both Flags() [ITPOR] and [CFGUPMODE] bits. After a timeout of approximately 240 seconds (4 minutes), the gauge will automatically exit the CONFIG UPDATE mode if it has not received a SOFT_RESET, EXIT_CFGUPMODE, or EXIT_RESIM subcommand from the host.
        系统可以通过Control()发送SOFT_RESET, EXIT_CFGUPMODE, 或者EXIT_RESIM子命令来退出CONFIG UPDATE模式。
    
    五、Current Measurement
        The fuel gauge measures current by sensing the voltage across a small-value, external sense resistor (10 mΩ, typical) between the SRN and SRP pins. Internally, voltage passes through a gain stage before conversion by the coulomb counter. The current measurement data is available via the AverageCurrent() command.
        电池计量器电流测量通过测量外扩的传感电阻两端的电压。
    
    六、Quickstart Guide for bq27441-G1
        2.5 Pin Descriptions
            2.5.1 GPOUT Pin
            The GPOUT pin is a multiplexed pin and the polarity of the pin output can be selected via the OpConfig [GPIOPOL] bit. The function is defined by OpConfig [BATLOWEN] bit. If the bit is set, the Battery Low Indicator (BAT_LOW) function is selected for the GPOUT pin. If cleared, the SOC interrupt (SOC_INT) function is selected for the GPOUT pin.
            GPOUT引脚是多功能复用引脚,其引脚极性输出由OpConfig[GPIOPOL]位决定,其功能引脚选择由OpConfig[BATLOWEN]位决定。如果OpConfig[BATLOWEN]被置位,GPOUT引脚用于指示用指示电量过低功能,如果该位被清零,那么GPOUT引脚用于片上中断功能。
        
            When the BAT_LOW function is activated, the signaling on the multiplexed pin follows the status of the [SOC1] bit in the Flags() register. The fuel gauge has two flags accessed by the Flags() function that warn when the battery SOC has fallen to critical levels. When StateOfCharge() falls below the first capacity threshold, specified in SOC1 Set Threshold, the [SOC1] flag is set. The flag is cleared once StateOfCharge() rises above SOC1 Set Threshold. The GPOUT pin automatically reflects the status of the [SOC1] flag when [BATLOWEN] = 1 and [GPIOPOL] = 0. The polarity can be flipped by setting [GPIOPOL] = 1.
            如果BAT_LOW功能被选择,那么GPOUT引脚电平将跟随Flags()寄存器的[SOC1]状态寄存器,电池计量计有2个标志位可以通过Flags()函数访问,这两个标识都是标识电流下降到了一个临界值,当StateOfCharge()下降到SOC1中设定的第一个电池容量阈值的时候,[SOC1]标志被置位,当StateOfCharge()大于SOC1设置的临界值的时,标志位将被清零。如果[BATLOWEN]=1并且[GPIOPOL]=0,那么GPOUT引脚将自动反应[SOC1]的状态标志。当然,如果[GPIOPOL]=1,那么极性将正好相反。
        
            When StateOfCharge() falls below the second capacity threshold, SOCF Set Threshold, the [SOCF] flag is set, serving as a final discharge warning. Similarly, when StateOfCharge() rises above SOCF Clear Threshold and the [SOCF] flag has already been set, the [SOCF] flag is cleared.
            当StateOfCharge()继续下降到SOCF设置的电池容量阈值,[SOCF]标志位将会被置位并作为最后的放电警告。类似的是,当StateOfCharge()上升到SOCF设置的阈值时,并且[SOCF]标志已经被置位,那么[SOCF]标志将被清零。
        
            When the SOC_INT function is activated, the GPOUT pin generates 1-ms pulse width under various conditions as described in Table 2-1.
            当SOC_INT功能被选择,GPOUT引脚将根据表2-1不同的情况生成1-ms脉冲。
    
        2.5.2 Battery Detection (BIN)
            The function of the OpConfig [BIE] bit is described in Table 2-2. When battery insertion is detected and the INITIALIZATION mode is completed, the fuel gauge transitions to NORMAL mode to start Impedance Track™ fuel gauging. When battery insertion is not detected, the fuel gauge remains in INITIALIZATION mode.
            OpConfig[BiE]位功能描述如2-2所述。当电池插入被检测,且INITIALIZATION模式设置完成,电池流量计转到NORMAL模式下开始阻抗跟踪。如果电池没有被检查到,电池流量计将保持在INITIALIZATION模式。
        
        3.1 Data Memory Parameter Update Example
            This following example shows the command sequence needed to modify a Data Memory parameter. For this example, the default Design Capacity is updated from 1000 mAh to 1200 mAh. All device writes (wr) and reads (rd) are implied to the I2C 8-bit addresses 0xAA and 0xAB, respectively.
            下面是一些参数设置命令。下面例子中默认的设计容量大约是1000mAh到1200mAh,所有的设备读写操作都是通过I2C 8-bit地址0xAA和0xAB。
    
    七、Standard Commands
        The fuel gauge uses a series of 2-byte standard commands to enable system reading and writing of battery information. Each standard command has an associated command-code pair as indicated in Table 4-1. Because each command consists of two bytes of data, two consecutive I2C transmissions must be executed both to initiate the command function and to read or write the corresponding two bytes of data.
        电池计量器采用一系列的2字节标准命令来读取其电池信息,每一个标准命令都如表4-1中的命令码对对应。由于每一个命令都由2字节组成。
    
    八、Extended Data Commands
        Extended data commands offer additional functionality beyond the standard set of commands. They are used in the same manner; however, unlike standard commands, extended commands are not limited to 2- byte words. The number of command bytes for a given extended command ranges in size from single to multiple bytes, as specified in Table 5-1
        扩展数据命令相对于标准命令,提供了更多的功能,他们有同样的操作,但不像标准的命令,扩展命令并不是限制在2-byte,扩展命令的字节数从一个到多个字节。
    
    九、读写函数:
        static int bq27xxx_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single)
        {
            struct i2c_client *client = to_i2c_client(di->dev);
            struct i2c_msg msg[2];
            unsigned char data[2];
            int ret;
    
            if (!client->adapter)
                return -ENODEV;
    
            msg[0].addr = client->addr;
            msg[0].flags = 0;
            msg[0].buf = ®                          # 单字节标准命令
            msg[0].len = sizeof(reg);
            msg[1].addr = client->addr;
            msg[1].flags = I2C_M_RD;
            msg[1].buf = data;                          # 读取字节buffer
            if (single)                                 # 读取字节长度
                msg[1].len = 1;                         
            else
                msg[1].len = 2;
    
            ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
            if (ret < 0)
                return ret;
    
            if (!single)                                # 转换读取的数据,并将数据返回
                ret = get_unaligned_le16(data);
            else
                ret = data[0];
    
            return ret;
        }
        static int bq27xxx_write_i2c(struct bq27x00_device_info *di, u8 reg, int value, bool single)
        {
            struct i2c_client *client = to_i2c_client(di->dev);
            struct i2c_msg msg;
            unsigned char data[4];                      # 写入数据buffer
            int ret;
    
            if (!client->adapter)
                return -ENODEV;
    
            data[0] = reg;                              # 标准命令
            if (single) {
                data[1] = (unsigned char)value;         # 写入的值
                msg.len = 2;
            } else {
                put_unaligned_le16(value, &data[1]);    # 写入的值
                msg.len = 3;
            }
    
            msg.buf = data;                             # 指定buffer
            msg.addr = client->addr;
            msg.flags = 0;                              # 标志的写
    
            ret = i2c_transfer(client->adapter, &msg, 1);
            if (ret < 0)
                return ret;
    
            return 0;
        }
        static int bq27xxx_read_i2c_blk(struct bq27x00_device_info *di, u8 reg,
            u8 *data, u8 len)
        {
            struct i2c_client *client = to_i2c_client(di->dev);
            struct i2c_msg msg[2];
            int ret;
    
            if (!client->adapter)
                return -ENODEV;
    
            msg[0].addr = client->addr;
            msg[0].flags = 0;
            msg[0].buf = &reg;
            msg[0].len = 1;
    
            msg[1].addr = client->addr;
            msg[1].flags = I2C_M_RD;
            msg[1].buf = data;
            msg[1].len = len;
    
            ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
            if (ret < 0)
                return ret;
    
            return ret;
        }
        static int bq27xxx_write_i2c_blk(struct bq27x00_device_info *di, u8 reg,
            u8 *data, u8 sz)
        {
            struct i2c_client *client = to_i2c_client(di->dev);
            struct i2c_msg msg;
            int ret;
            u8 buf[33];
    
            if (!client->adapter)
                return -ENODEV;
    
            buf[0] = reg;
            memcpy(&buf[1], data, sz);
    
            msg.buf = buf;
            msg.addr = client->addr;
            msg.flags = 0;
            msg.len = sz + 1;
    
            ret = i2c_transfer(client->adapter, &msg, 1);
            if (ret < 0)
                return ret;
    
            return 0;
        }
        
    九、命令执行总结:
        1. 执行控制命令的时候,需要发送标准控制命令(00),以及子序列(00xx),再读数数据或者再进行其他操作,读数据又分为读单字节数据和读双字节数据。
        2. 非控制命令则只需要直接发送命令(标准命令一个字节),再讲数据读出,读数据又分为读单字节数据和读双字节数据。
        3. 自行配置电池计量器:
            1. 解锁;
            2. 控制命令进入配置模式;
            3. 扩展命令选择需要配置的分类;
            4. 将数据写入对应的分类;
            5. 控制命令退出配置模式;
            6. 加锁。
  • 相关阅读:
    Linux之文档与目录结构
    Linux介绍
    CentOS7下zip解压和unzip压缩文件
    yum 命令讲解
    Linux安装redis
    pip更新问题
    第一章-KS8初体验 安装部署
    MVC Razor视图引擎
    MVC 组件之间的关系
    Web应用程序和网站的区别
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/5201243.html
Copyright © 2011-2022 走看看