# RK818/RK816 Fuel Gauge Development Guide Release version: 2.0 Author's email: chenjh@rock-chips.com Date: 2018.05 Document classification: Public information Preface Overview This document mainly introduces Rockchip's RK818/RK816 submodule: fuel gauge. It introduces related concepts and functions, DTS configuration, and analysis and positioning of some common # Product Version | Chip Name | Kernel version | | -- | -- | | RK818 | 3.10ÿ4.4 | | RK816 | 3.10 | # Target Audience This document (this guide) is mainly applicable to the following engineers: Technical support engineers Software development engineers Revision History | date | Version au | thor modification in | structions | | -- | -- | -- | -- | | 2016.07.25 | V1.0 Chen | Jianhong's first dra | ft, the use of rk818 in kernel 4.4 | | 2017.05.25 | V2.0 Chen | Jianhong added th | e use of rk816 and rk818 in kernel 3.10; corrected the description error of charging voltage/current | | 2018.05.31 | V2.1 Chen | Jianhong adjusted | the document format and layout errors, no major content updates | RK818/RK816 Fuel Gauge Development Guide 1 Overview RK818/RK816 Fuel Gauge 2 Fuel Gauge Principle 3 Important Concepts 4 Drivers and menuconfig 4.1 Fuel Gauge Driver Functions 4.2 Kernel 4.4 4.3 Kernel 3.10 5 DTS configuration5.1 Kernel 4.4 5.2 Kernel 3.10 6 Start fuel gauge development6.1 Preparation6.2 Problem solving7 Battery calibration7.1 Principles of battery calibration7.2 Methods of battery calibration7.3 When calibration is required8 Common problem analysis and location ## 1 Overview RK818/RK816 Fuel Meter RK818/RK816 is a high-performance PMIC that integrates multiple high-current DCDCs, multiple LDOs, 1 linear switch, 1 USB 5V and boost output, as well as switch charging, intelligent power path management, coulomb meter, RTC and adjustable power-on timing. Among them, "switch charging, intelligent power path management, and fuel meter (coulomb meter)" are the functions involved in this document. 1. Charging management: including input current limiting, trickle charging, constant current/constant voltage charging, charging termination, charging timeout safety protection and other functions. 2. Intelligent power path management: the output voltage can be adjusted to provide the required power to the system load, and the battery can be charged at the same time. When entering the input current limiting state, the input power will be provided to the system load first, and the remaining power will be provided to the battery for charging. In addition, when the power required by the system load exceeds the limited input power, or the power input is disconnected, the intelligent power path management function will automatically turn on the switch between the battery and the system load, so that the battery can provide additional power to the system load at the same time. 3. Coulomb meter: By using the patented algorithm, the coulomb meter can accurately measure the charge and discharge characteristics of different batteries. Measure the battery power and provide the battery power information to the system main chip through the I2C interface. It also has functions such as low-current charging for over-discharged batteries, battery temperature detection, charging safety timer, and chip thermal protection. ## 2 Fuel meter principle 1. Three basic principles: a) The open circuit voltage of a battery and the percentage of battery capacity (OCV-SOC) curve mainly depends on the materials and process of the battery.The battery is produced by a process that is not affected by temperature, aging, etc., and has little effect. That is, the SOC-OCV curve remains basically unchanged after the battery is produced.b) The battery is affected by battery polarization during operation, and it is difficult to deduce the battery's OCV voltage from the battery port voltage. Therefore, the available OCV voltage can only be obtained when the battery is not polarized (such as after being shut down for a long time or working at a low current for a long time), and the SOC can be derived from the OCV.c) The coulomb meter can measure the actual amount of electricity flowing into or out of the battery. If the total capacity of the battery is known, the SOC value can be easily obtained. However, the cumulative error of the coulomb meter is large, and the total capacity of the battery will be affected by factors such as temperature and aging. Therefore, the coulomb meter method can only guarantee good accuracy in a short period of time, and the total capacity of the battery needs to be updated regularly. d) Currently, all the fuel gauges with good performance are based on the above OCV estimation and coulomb counter calculation to obtain the real-time remaining capacity status of the fuel gauge. ## 2. Coulomb counting method A current detection resistor is connected in series between the positive and negative electrodes of the battery. When current flows through the resistor, V_delta is generated. By detecting V_delta, the current flowing through the battery can be calculated. Therefore, the battery power change can be accurately tracked with an accuracy of 1%. In addition, by coordinating the battery voltage and temperature, the influence of factors such as battery aging on the measurement results can be greatly reduced. ## 3. Current signal conditioning 4. Voltage acquisition The battery voltage is divided down (voltage division ratio 0.5) to within the Vref range through a voltage divider circuit and then converted into a digital output through an ADC module. ## 5. Average current acquisition The digital part adds the corrected current value to the multi-digit accumulator 256 times per second. After one second, the accumulator value is divided by 256 to get the average current value. ## 6. Coulomb counter update The coulomb counter automatically accumulates once when the average current is updated. ## 3 Important Concepts OCV voltage is open circuit voltage. PMIC collects data during the power-on sequence. Because the load is very small at this time, it is close to the open circuit state, so the voltage at this time is accurate. Purpose: When the battery is shut down for at least 30 minutes, we believe that the polarization of the battery is basically eliminated. The OCV voltage obtained at this time is real and valid, so the voltage will be used to query the ocv_table to get a new power to update the coulomb meter value and perform a coulomb meter calibration. OCV table Each battery has its own battery characteristic curve. According to the principle that a specific voltage corresponds to a specific amount of electricity, we divide the electricity from 0% to 100% into 21 points, with a step of 5%, thus obtaining a table of "voltage <--> electricity". The purpose of this table is to calibrate the coulomb meter when the battery is connected for the first time, when the device is turned off for a long time, and when it is dormant for a long time. For example: 1 ocv_table = <3400 3599 3671 3701 3728 3746 3762 ...... 4088 4132 4183>; Corresponding relationship: 3400mv: 0%, 3599mv: 5%, 3671mv: 10%, .... 4183mv: 100%; The maximum input current and maximum charging current are configured in the software to be the maximum current that can be obtained from the adapter, which is called the "maximum input current". For example, for a 5V/2A adapter, we generally configure the maximum input current in the software to be 2A (it can also be set to 1.8A...). RK818/816 has an intelligent power path management function, that is, the power from the adapter is first supplied to the system, and the remaining power is used to charge the battery. The maximum remaining current value allowed to charge the battery configured in the software is called the "maximum charging current". Input current limiting can be simply understood as when the power supply current demand for the battery and the system exceeds the maximum input current, this "not enough" situation is called "input current limiting occurs". Or it can also be understood as: when the battery cannot be charged at the maximum charging current state under the conditions required by the battery, input current limiting occurs. This function is mainly used as one of the three conditions for charging cutoff (the other two are charging cutoff voltage and cutoff current). Relaxation mode In extremely low load conditions (currently only for secondary standby), if the system load current is less than a certain threshold for more than a certain period of time (configurable by software), the fuel gauge module enters relaxation mode. Relaxation voltage In relaxation mode, the fuel gauge collects a set of voltage every 8 minutes, which we call relaxation voltage. Purpose: The load of the secondary standby is very small. We approximately think that the relaxation voltage is similar to the open circuit voltage. Therefore, in the driver processing, when the system wakes up from the secondary standby and meets certain conditions, it will be used to query the ocv_table table to calibrate the coulomb meter. Finish charging cut-off signal When the battery charging is cut off, the register will generate a status signal, called the finish signal. Purpose: The software will only consider it as the real hardware charging cut-off when it obtains this signal, and then enter the corresponding algorithm process to adjust the displayed power. Chip thermal protection The self-protection mechanism of PMIC is actually a feedback mechanism: when the chip temperature is greater than the set threshold, the input current will be gradually reduced to reduce the PMIC workload and reduce chip heat. This feedback process is automatically completed by hardware, and software cannot participate. There is no strict corresponding ratio between temperature and current. In extremely harsh conditions, charging may even stop. Charge cut-off condition: When the charging current reaches the cut-off current, the voltage reaches the cut-off voltage, and there is no input current limiting, a charge cut-off signal is generated.If the battery is fully charged, the current limit condition needs to be input to judge, otherwise it is impossible to distinguish whether the charging current has really decreased or the charging current to the battery is small because the system load is relatively large at this time. ## 4 Driver and menuconfig ### 4.1 Fuel gauge driver functions 1. Battery power statistics and display; 2. Charging current and voltage settings (according to battery and charger type), support single-port/dual-port charging; 3. 5V power supply for OTG devices; 4. Battery temperature detection. ### 4.2 Kernel 4.4 rk818 driver and macro configuration (too large to be used, so it is split into 2 drivers): drivers/power/rk818_battery.c drivers/power/rk818_charger.c // Responsible for processing power 2 display // Responsible for processing charger detection, charging voltage, current setting | 1 2 | CONFIG_BATTERY_RK818 | | -- | -- | | 1 2 | CONFIG_CHARGER_RK818 | rk816 driver and macro configuration: | drivers/power/rk816_battery.c 1 | // Responsible for processing power display + charger detection, charging voltage, current setting | | -- | -- | | CONFIG_BATTERY_RK816 1 | | -- | 4.3 Kernel 3.10 rk818 driver and macro configuration: | drivers/power/rk818_battery.c 1 | // Responsible for processing power display + charger detection, charging voltage, current setting | | -- | -- | CONFIG_BATTERY_RK818 rk816 driver and macro configuration: | 1 drivers/power/rk816_battery.c | // Responsible for processing power display + charger detection, charging voltage, current setting | | -- | -- | CONFIG_BATTERY_RK816 5 DTS Configuration 5.1 Kernel 4.4 The configuration of DTS consists of two parts: 1. Battery part: required. A complete battery node information is as follows. This node is placed in the RK818 node. The battery and charger sub-device drivers of RK818 will use the information in the battery node. Among them, ntc_table, ntc_degree_from, and dc_det_gpio are optional parts, and the rest are mandatory parts. 1 battery 2 { compatible = “rk818ÿbattery” ocv_table = <3400 3599 3 3671 3701 3728 3746 3762 4 3772 3781 3792 38163836 3866 3910 5 3942 39714002 4050 4088 4132 4183>; 6 ntc_table = <43662 41676 39793 38005 36308 34696 33164 7 31709 30326 29011 27760 26570 25438 24361 8 23335 22358 21427 20540 19695 18890 18121 9 17389 16690 16022 14778 14197 13642 13113 10 12606 12122 11659 11216 10793 10388 10000 11 9629 9273 8933 8607 8295>; 12 ntc_degree_from = <1 10>; design_capacity = 13 <4000>; design_qmax = <4100>; bat_res = 14 <120>; max_input_current = <2000>; 15 max_chrg_current = <1800>; 16 max_chrg_voltage = <4200>; sleep_enter_current = 17 <300>; sleep_exit_current = <300>; power_off_thresd 18 = <3400>; zero_algorithm_vol = <3850>; 19 energy_mode = <0>; fb_temperature = <105>; 20 sample_res = <10>; max_soc_offset = <60>; 21 monitor_sec = <5>; virtual_power = <0>; 22 power_dc2otg = <1>; dc_det_gpio = <&gpio0 GPIO_C1 23 GPIO_ACTIVE_LOW>; 24 25 26 27 28 29 30 31 }; 2. charger part: optional. If the TypeC port is not supported for charging, this part of the configuration is not required. For machines that support the TypeC charging port, please add a reference to the "extcon= <&fusbn>" node under the root node of rk818 (where n=0,1.., for specific references, please refer to the actual hardware situation), as shown below. Because rk818_charger.c needs to register the TypeC notification chain based on this reference to obtain the TypeC charger type detection information. 1 rk818: pmic@1c { compatible= 2 "rockchip,rk818"; status= "okay"; 3 4 reg= <0x1c>; 5 clockÿoutputÿnames= "xin32k", "wifibt_32kin"; interruptÿparent= <&gpio1>; interrupts = 6 <21IRQ_TYPE_LEVEL_LOW>; pinctrlÿnames= 7 "default"; pinctrlÿ0= <&pmic_int_l>; 8 9 10 rockchip,systemÿpowerÿcontroller; rk818,support_dc_chg= <1>;/ *1: dc chg; 0:usb chg*/ 11 rk818,support_dc_chg= <1>;/*1: dc chg; 0:usb chg*/ wakeupÿsource; extcon = <&fusb0>; 12 // important!!!13 #clockÿcells= <1>; 14 15 16 battery { 17 ........... 18 ........... }; 19 }; 20 ### 5.2 Kernel 3.10 The node information of RK816 and RK818 is basically the same, with only a few attributes being different. The following takes RK818 as an example for explanation. A complete battery node information is shown below. This node is placed in the RK818 node. Among them, ntc_table, ntc_degree_from, dc_det_gpio, dc_det_adc are optional parts, and the rest are mandatory parts. 1 battery 2 { compatible = "rk818-battery" // If it is rk816, change to "rk816-battery" ocv_table = <3400 3599 3671 3701 3728 3 3746 3762 4 3772 3781 3792 38163836 3866 3910 5 3942 39714002 4050 4088 4132 4183>; 6 ntc_table = <43662 41676 39793 38005 36308 34696 33164 7 31709 30326 29011 27760 26570 25438 24361 8 23335 22358 21427 20540 19695 18890 18121 9 17389 16690 16022 14778 14197 13642 13113 10 12606 12122 11659 11216 10793 10388 10000 11 9629 9273 8933 8607 8295>; 12 ntc_degree_from = <1 10>; design_capacity 13 = <4000>; design_qmax = <4100>; 14 15 bat_res = <120>; 16 max_input_current = <2000>; 17 max_chrg_current = <1800>; 18 max_chrg_voltage = <4200>; 19 sleep_enter_current = <300>; 20 sleep_exit_current = <300>; sleep_filter_current 21 = <100>; // rk818 does not need this attribute power_off_thresd = <3400>; zero_algorithm_vol 22 = <3850>; energy_mode = <0>; 23 24 25 fb_temperature = <105>; 26 max_soc_offset = <60>; monitor_sec 27 = <5>; virtual_power = <0>; 28 power_dc2otg = <1>; dc_det_gpio 29 = <&gpio0 GPIO_C1 30 GPIO_ACTIVE_LOW>; dc_det_adc = <1>; // rk818 does not need this attribute, 31 but rk816 may need it 32 }; ocv_table Open circuit voltage-capacity table. That is, "voltage corresponding to capacity", a total of 21 voltage values, corresponding to 0% --> 100%, the capacity step between voltage values is 5%. This data sheet can be provided by the battery manufacturer, or measured by RK Shenzhen Branch, or obtained by the measurement tools provided by RK. Please consult the relevant engineers of Shenzhen Branch for details. ntc_tableBattery NTC table, unit: ohm. If you need to detect the battery temperature, please fill in the corresponding NTC value. One value represents a temperature, and the temperature step between adjacent values is 1 degree Celsius, increasing from left to right. If you do not need to detect the battery temperature, please remove this attribute field. The above example shows the NTC value corresponding to -10\~30 degrees Celsius. ntc_degree_from The temperature corresponding to ntc_table[0] is the starting temperature value. Therefore, please add this attribute after configuring ntc_table. Because DTS cannot pass negative numbers, ntc_degree_from consists of two fields. The first field indicates the positive and negative signs: 1: negative, 0: positive; the second field indicates the temperature. For example, ntc_degree_from = <1, 10> means -10 degrees Celsius. design_capacity Actual battery capacity. The actual available capacity determined after actual measurement. For example, if the nominal capacity is 4000mah, but the actual measured capacity is only 3850mah, please fill in 3850 for this value. design_qmax The maximum capacity value is mainly used as one of the error correction conditions for software processing. Currently, please fill in 1.1 times the nominal capacity: that is, nominal capacity*1.1. bat_res is the internal resistance of the battery. It is mainly used in the discharge algorithm and is very important! This value is obtained when measuring ocv_table, so please pay attention to the measurement of this parameter and do not miss it. max_input_current Maximum input current. Currently there are the following gears (unit: mA): | 1 | RK818: <450, 80, 850, 1000, 1250, 1500, 1750, 2000, 2250, 2500, 2750, 3000> | | -- | -- | | 2 | RK816: <450, 80, 850, 1000, 1250, 1500, 1750, 2000> | Note that the second gear is 80, not 800! In general, the 80ma gear is not set. max_chrg_current Maximum charging current. Currently there are the following gears (unit: mA): 1 RK818: <1000, 1200, 1400, 1600, 1800, 2000, 2250, 2400, 2600, 2800, 3000>2 RK816: <1000, 1200, 1400, 1600, 1800, 2000, 2250, 2400> max_chrg_voltage The maximum charging voltage is the cut-off voltage for fully charging the battery. Currently, there are the following gears (unit: mV): 1 RK818: <4050, 4100, 4150, 4200, 4250, 4300, 4350>2 RK816: <4050, 4100, 4150, 4200, 4250, 4300, 4350> sleep_enter_current One of the conditions for entering relaxation mode. Currently set to 300 and do not change. sleep_exit_current sleep_filter_current Filter invalid relaxation current. Currently fill in 100 and do not change. power_off_thresd Please read and understand carefully Expected system shutdown voltage, unit: mV. Special note: This value refers to the instantaneous voltage of VSYS, not the voltage of the vbat terminal (but the power meter collects the voltage of the vbat terminal)! Principle explanation: The voltage at the Vbat terminal needs to pass through a MOS tube with a resistance of about 50 milliohms (in addition, there is actually impedance caused by PCB routing) before it is converted to VSYS to supply the system, so it is correct to use VSYS as the shutdown point. From this we can know that: for the same vbat terminal voltage, the greater the current load current, the lower the vsys terminal voltage; conversely, under the same vsys, the greater the current load current, the higher the corresponding vbat voltage. The RK platform does not recommend that the voltage at the vsys end be lower than 3.4v, as this may easily lead to unstable power supply of DCDC/LDO such as VCC_IO (3.3v). ### zero_algorithm_vol The voltage value to enter the voltage + coulomb meter discharge mode, unit: mV. Below this value, the voltage + coulomb meter combined software discharge algorithm is entered. Recommendation: 4.2v battery is set to 3850mv, 4.3v and above batteries are set to 3950mv. ### energy_mode Some customers are very concerned about the smoothness of the curve, while others are more concerned about whether the battery can be fully discharged. It is difficult to balance the two. Therefore, this attribute is reserved for selection. When the value is 1, it means that the battery should be fully discharged as much as possible. When it is 0, it means that the rationality of the curve smoothness should be considered as much as possible (for example, if it is set to shut down at 3.4v, it may sometimes shut down at 3.5v). The driver has tried to balance the curve smoothness and the shutdown voltage point, so it is recommended to set it to 0. If it is found after testing that the shutdown voltage point cannot meet the needs, you can set it to 1 for an attempt or directly contact the driver maintainer for optimization. ## fb_temperature Chip thermal protection temperature threshold, currently there are four temperature levels (unit: Celsius): | 1 < 85, 95, 105, 115> | | -- | Currently, select 115 on VR and 105 on others. If set to 0, the temperature control feedback function is turned off. This value is generally only used to troubleshoot problems (see "1.5 Common Problems Analysis and Location"). Never turn off the temperature control feedback function during normal use. ## sample_res The size of the sampling resistor near the battery terminal, in milliohms. The coulomb meter uses this resistor to obtain the current size of the system. Please fill in the value according to the actual resistance size of the hardware sticker. Currently, the resistance size only supports 10mR or 20mR. Note: Only the rk818 fuel gauge driver on the 4.4 kernel supports it. The 3.10 kernel does not support it and the default value is 20mR. ### max_soc_offset The maximum power error allowed during power-on calibration. If the power has been off for at least 30 minutes, the power of the ocv table will be queried when the power is turned on, and compared with the power before shutdown. If the deviation exceeds max_soc_offset, a forced calibration will be performed, and the power will be set to the actual value corresponding to the ocv table. For example: the current displayed power is 20%, but the actual power calculated based on the ocv voltage is 80%, then the displayed power is directly displayed as 80%. Generally, this kind of extremely large power deviation will occur after a crash. The size of this value depends on the customer's acceptance and is set by the customer. It is not recommended that this value be less than 60. ### monitor_sec Polling time (seconds). The fuel gauge driver needs to be polled continuously to work properly, during which a lot of I2C read and write operations are required. However, considering the different robustness of I2C on different platforms, this configuration option is reserved. Currently, 5\~10s is recommended, and 5s is the best choice.I2C on different platforms, this configuration option is reserved. Currently, 5\~10s is recommended, and 5s is the best choice. ## virtual_power Test mode. Sometimes during the copying process, you do not want the system to shut down due to insufficient power supply due to battery level, charging current, etc. Set this value to 1, that is, release the charging current limit, and the system input current is always max_input_current to meet the power supply. At this time, the driver always reports to Android that it is currently in charging state and the battery level is 66%. power_dc2otg Whether to support OTG devices to obtain 5V power from DC. For machines that support dual-port charging, when the hardware circuit supports inserting DC, the 5V power supply of the OTG device is directly supplied by DC, and no additional 5V output is required from RK818. If supported, set to 1. If not supported or there is no DC port, please set to 0. dc_det_gpio Specify the gpio corresponding to the dc pin. If there is no such function, please remove this attribute. ## dc_det_adc Whether to support using saradc to detect dc pins, 1: support, 0: not support. Generally speaking, this attribute and "dc_det_gpio" must be a choice between the two. ## 6 Started development of fuel gauge ### 6.1 Preparation 1. Measure the battery's ocv curve and internal resistance: Each battery has a voltage-capacity characteristic curve (ocv_table) and internal resistance. RK Shenzhen can Carry out measurements in this regard.Carry out measurements in this regard. 2. Fill in the DTS parameters and refer to Section 1.5 for correct configuration. 3. Calibrate the battery and refer to Section 1.7. 4. Start normal use. ### 6.2 Problem Solving 1. If there is an abnormality during use, please immediately open the debugging information to capture the on-site log and then analyze it; 2. If you think there is a problem with the charge/discharge curve, such as jump, too fast/too slow. Then please capture the complete (0100% or 100%0%, principle: try to Covering a large range of charge) charge/discharge log; 3. If you cannot analyze the cause yourself, please capture the on-site or reproducible log and mention it in redmine. Note: The captured log must have the debug information of the fuel gauge turned on! ! For some common problems, please refer to Chapter 8. ## 7 Battery Calibration ### 7.1 Principle of Battery Calibration 1. When the machine is turned off, the PMIC actually just turns off each DCDC/LDO, but it is not completely powered off. Instead, it maintains the power-on state with a very low load. The PMIC itself provides some blank data registers that can be used to store the data of the fuel gauge. The currently stored information is related to the previous state: power, coulomb meter capacity, and battery full charge capacity (i.e. design_capacity). Each time the fuel gauge driver is initialized when the machine is turned on, these values are not affected by DTS, but read the data before shutdown and continue to be used. 2. When the above three information needs to be corrected, the PMIC needs to be completely powered off to clear these data. When the power is completely turned off and then powered on again, the power The battery's GGSTS_REG[4] ("First Power On") status bit will be set. So it is necessary to remove the battery to achieve this.The battery's GGSTS_REG[4] ("First Power On") status bit will be set. So it is necessary to remove the battery to achieve this. 3. When the battery is reconnected, the driver determines that it is the first time to power on, and all relevant data will be obtained from DTS again and the relevant The battery capacity, power, etc. In this way, we get the accurate state after a calibration. 4. For point 3, please note that after removing the battery, you should confirm that the polarization is basically eliminated before reconnecting it (you can leave the battery alone to wait for it to be polarized). Otherwise, the OCV voltage at startup will also be inaccurate. For example, when a large load is discharged, the battery is removed. At this time, the battery is actually still in a polarized state, and the battery voltage will slowly rise. If it is immediately connected back at this time, the OCV voltage collected at this time will be inaccurate! We need to ensure that the battery is in a state where polarization is basically eliminated during calibration, so that the OCV voltage is accurate when the power is turned on for the first time and the accurate power can be obtained. ### 7.2 Battery Calibration Methods There are currently two ways to calibrate the battery, choose 1 from 2: Method 1: Hardware method: Remove the battery for about 10 seconds, then reconnect it; Method 2: Software method: Use the serial port to perform the following operations: 1. Find the bat node path: busybox find /sys/ -name bat, for example, the path is "/sys/rk818/bat"; (if it is rk816, the path is "/sys/rk816/bat", the same below) 2. Execute: echo m > /sys/rk818/bat; 3. Read back to confirm: echo r > /sys/rk818/bat, the return value BIT(4) should be 1; 4. Then shut down normally, and wait for at least 30 minutes before restarting (only then can the accurate ocv voltage be obtained). Supplement: If you need to clear the operation in step 2, execute: echo c > /sys/rk818/bat; ### 7.3 When is calibration required? 1. When the battery capacity configured by DTS is changed; 2. It is obvious that the battery capacity is inaccurate (the reason may be machine crash, some special non-electricity meter stress test, etc.); 3. The electric meter should be calibrated once before copying the machine to ensure that the battery is tested accurately. This is meaningful (only all test items need to be calibrated). It is sufficient to calibrate once at the beginning, and there is no need to calibrate before each case test). ## 8 Analysis and location of common problems ### 1. How to open debugging information and capture logs? Method 1: Before compiling, change the first line of the driver static int dbg_enable = 0 to 1. Method 2: If the firmware does not turn on dbg_enable, you can also enter the following command to turn it on and off during operation: Turn on: echo 1 > /sys/module/rk818_battery/parameters/dbg_level Turn off: echo 0 > /sys/module/rk818_battery/parameters/dbg_level If it is rk816, the node is changed to: /sys/module/rk816_battery/parameters/dbg_level 2. Why can't I shut down the computer after it is immediately restarted when the adapter or USB is plugged in? The PMIC chip was originally designed to be able to shut down the computer as long as it is plugged in.The device cannot be shut down. 3. Why is the status indicated by register GGSTS[4] (battery presence) different from the actual status when hot-swapping the battery after powering on? The PMIC does not support hot-swap detection of batteries and only performs a test once when the device is powered on. 4. Why is the voltage after shutdown different from the shutdown point configured by DTS? Why does it shut down at such a high voltage? The shutdown voltage is based on the real-time voltage printed by the last log,and this shutdown voltage is the vsys voltage (refer to section 1.5.2 for details). We must ensure that the real-time voltage is not lower than the preset shutdown point. And after shutdown, the system is powered off, the polarization of the lithium battery gradually disappears, and there will be a process of voltage recovery. This is the characteristic of lithium batteries. 5. Why does the battery level remain almost the same while the voltage is slowly decreasing when the machine is turned on and off, rebooted, or in secondary standby mode? At this time, the driver cannot poll normally to enter the working state, so this type of stress test is not supported. The quality department and customers do not need to test these three items when doing the power meter test. 6. Why is the charging current always very small when using a battery charger? a) Check if the voltage applied to vbus is far less than 5V because of the poor quality and high impedance of the charging cable. You can connect an external voltage regulator to increase the voltage appropriately to see if the current can be increased. b) Enter the screen-off state (level 1 standby) and observe whether the charging current increases to determine whether it is related to operating power consumption; c) A battery that is about to be fully charged will have a very low charging current, so please pay attention to the battery voltage; d) Under high temperature and heavy load conditions, it is possible that the PMIC temperature rises and triggers the input current limit. So first increase the feedback temperature (fb_temperature) to see if it works. If it still doesn’t work, try turning off the temperature control (set fb_temperature to 0). 7. Why does the battery level change after the battery is unplugged and then turned on? Our requirement is that the battery level will not jump after the battery is removed. Can this be met? a) After the battery is unplugged, the PMIC is completely powered off. At this time, the ocv voltage can only be queried by ocv_table to infer the battery level, so it is normal and it is a battery recalibration; b) Do you want the battery level to not jump after removal? It is almost impossible, unless the software is circumvented: write the power before shutdown to a file and read it after powering on. If the customer has a need, please add this part of the circumvention code by yourself. 8. PMIC has a temperature feedback function to adjust the input current, so how do we know the internal temperature of the PMIC at this time? There is no way to know, as it was not included in the design.This function. 9. Why is the current printed on the log so off-center, with the positive and negative signs reversed or the current magnitude so different from the actual value? Please make sure that the selected sampling resistor is 20/10 milliohm and the resistance accuracy is high enough; secondly, please make sure that the solder joints are clean and the sampling resistor should be located between BAT- and GND. 10. Why does the battery report "finished" when it is not fully charged, for example, only 3.9V? This is usually because the battery quality is poor and the maximum charging current is set too high. The voltage is too large, causing the panel to protect itself, thus causing the PMIC to falsely report the finish status. 11. Why does the current value fluctuate between positive and negative in the finish state (the value is smaller)? This is the current zero point error after full charge, which is not a big deal. 12. Why is the battery level displayed only 90% instead of 100% even though the battery has been reported as finished? Since the coulomb counter has cumulative errors and the charging is completed by hardware, there will be a certain error between the two, and it is impossible to accurately grasp the timing of reporting the finish, so this situation is normal. In this case, the software will do a processing, that is, slowly let the battery level approach 100%, which is not noticeable to the end user and there is no problem in use. 13. Why is the power meter so inaccurate during operation and so different from the value in ocv_table? Concepts are confused. ocv_table is open circuit without negative The ratio of voltage to power under load conditions , and we only use this table for power-on calibration and sleep calibration. So such a comparison is meaningless and does not make sense in principle. 14. Does it support replacing batteries of different specifications? No. After replacing the battery, the OCV curve, internal resistance, capacity and other parameters need to be retested. Write. 15. What are the conditions for PMIC to determine that the battery is fully charged? Three conditions must be met at the same time: the voltage reaches the cut-off voltage, the current reaches the finish current, and the battery is not fully charged.Input current limiting occurs. 16. Why does the battery icon always show 50% charging? Please disable the test_power driver 17. Why does the battery icon always show 66% charging? There is no battery connected; or the virtual_power of DTS is configured to 1. Please configure into 0. 18. Why is the charger not recognized when it is plugged in or out? a) Kernel 4.4: rk818_charger.c is responsible for charger detection. The USB charger and OTG device plugging and unplugging are dependent on the USB notification chain. Please pay attention to whether the serial port log prints "rk818-charger: recieve xxx notifier event: xxx" and other serial port information. If not, the USB notification chain is not successfully registered (small possibility), or there is a problem with the USB driver. rk818_charger.c is responsible for charger detection. The USB charger and OTG device plugging and unplugging are dependent on the USB notification chain. Please pay attention to whether the serial port log prints "rk818-charger: recieve xxx notifier event: xxx" and other serial port information. If not, the USB notification chain is not successfully registered (small possibility), or there is a problem with the USB driver. ### Machine Translated by Google rk818_battery.c is responsible for charger detection (including battery power). The USB charger and OTG device plugging and unplugging all rely on the USB notification chain. Please pay attention to whether the serial port log prints "rk818-bat: recieve xxx notifier event: xxx" and other serial port information. If not, the USB notification chain is not registered successfully (small possibility), or there is a problem with the USB driver.