Battery Monitor Utility for bq2084 under Linux

From LEXWiKi

Jump to: navigation, search

Contents

The Sample code source and Spec File you can download from

Source file(Old): PW016 Source Code

Source file: Battery_Monitor_Utility_src_2.6.2.tar.gz
compile source code to binary
advance prepare:

   Install develope library:
   #apt-get install libgtk2.0-0 libgtk2.0-dev libglib2.0-dev
   #apt-get install automake

IDE(Codeblocks) solution:

   In Codeblocks:
   Setting->Compile and debugger setting:
           Compiler setting->Other Options:`pkg-config gthread-2.0 --cflags`
           Linker settings-other linker options:`pkg-config gthread-2.0 --libs`
   Using for "make":
   In terminal:
   #cd Pw016_Utility
   #./configure LIBS=-lgthread-2.0
   #make

Binary file(Old): PW016 DEMO AP

Binary file(32 bits): Battery_Monitor_Utility_bin_2.6.2_x86

Binary file(64 bits): Battery_Monitor_Utility_bin_2.6.2_x64

Control IC spec file:bq2084-v143.pdf

How to use the Demo Application

  • This utility has to be used with bq2084 gas gauge.

Check Battery Info

Image:BMU2.6Main.JPG

In order to retrieve the current battery information, please click the “Check Battery Info” and battery information will be refreshed as current status.

  • a.Battery Temperature.
  • b.Battery Current.
  • c.Battery Voltage.
  • d.Battery Status for Charge or Discharge.
  • e.Battery Status for Remaining capacity percent.
  • f.Battery remaining life time.
  • g.Battery Alarm Flag.
  • h.Battery Cycle Count:After battery fully charge and fully discharge one time, the cycle count will add 1.(As the picture you can see, cycle count is 12, that means the battery has fully charged 12 times and fully discharged 12 times)
  • I.Power off shutdown Message:After you Remove the power and you set the shutdown time,The time will be countdown


Note 1:
The battery control IC will protect the battery base on the preset threshold value.
Please download file from above “Battery Data Flash Info” for further preset threshold information.

  • Over Charged:

Threshold = Full Charge Capacity + Maximum Over Chg.
The Over Charged and Terminate Charge warnings from Battery Alarm status will appear “Yes” when the value of full charge capacity + maximum over chg is greater than the set value of threshold and the charge action will be terminated.

  • Over Temperature:

The Over Temperature and Terminate Charge / Terminate Discharge warnings from Battery Alarm status will appear “Yes” when the value of full charge capacity + maximum over chg is greater than the set value of threshold and the charge / discharge action will be terminated.
For Charge Mode: Threshold = Chg Suspend Temp Hi (Ref, Battery Data Flash Info)
For Discharge Mode: Threshold = Over Temp Dsg (Ref, Battery Data Flash Info)

Note 2:
The value of the “Current” from the Battery Info may appear in positive or negative value depending on the Charge / Discharge mode.

Setup Long Time Monitor

Image:BMU2.6BatteryCheck.JPG

After click the “Battery Long Time Monitor” button, user will enter the Long Time Monitor setup dialog box to configure the parameters for the battery event log.

  • A.User temperature Threshold: User can designate the preferred threshold value. The overheating event will be recorded in batterylog.txt once the battery temperature has exceeded the set threshold value.
  • B.“New temperature threshold value” will appear in RED C after clicked the “Apply”.
  • D.The Over temperature warning will appear as shown below when the action of “Run with user temperature threshold …” has been activated and exceeded the temperature threshold.


Image:PW016_warning.png

  • E.User Capacity(%) Threshold: User can designate the preferred threshold value. The low capacity event will be recorded in batterylog.txt once the battery capacity has been below the set threshold value.
  • F.“New capacity threshold value” will appear in RED G after clicked the “Apply”.
  • H.The low capacity warning will appear as shown below when the action of “Run with user capacity threshold …” has been activated and below the capacity threshold.


Image:PW016_warning_2.png

  • I.The Battery Long Time Monitor will set to refresh & record the monitor values after the set interval value.
  • J.The coThe Battery Long Time Monitor will set to refresh & record the monitor values after the set interval value.
    mputer will shut down when the action of “Shutdown automatically,…” has been active and below the capacity setting value(RED K).
  • L.The Battery Long Time Monitor will set after you remove the power shutdown second
  • M.will shut down when the action of “Shutdown automatically,…”
  • N.Activate the Battery Long Time Monitor (RED L) after complete the parameters and the event log will be saved as batterylog.txt under BMU4bq2048_bin_w folder.


conBattery log file shown as below picture,
Image:Battery_logfile.jpg
Image:BMU2.6MainCountDown.png
(Battery Long Time Monitor and countdown has been activated )


Application Configuration

Image:PW016_application_config.png

  • A. Auto startup while booting: Operating battery monitor utility automatically when the device booting.
  • B. Hide while application startuping: The utility will be minimized when it startuped.
  • C. Start battery long time monitor automatically : The utility will operate long time monitoring automatically when it starupped.


SDK Reference Code Introduction

int GotBatteryCurrent(void)

   signed short temp = 0;
   temp = ReadI2CWORDSTATE(0x16, 0x0a);//Check "bq2084-v143.pdf" Page 14 and 39
   return temp;


float GotBatteryTemperature(void)

   float kdegree =0.00; //For tenth-degree Kelvin convert 
   int temp = ReadI2CWORDSTATE(0x16, 0x08);//Check "bq2084-v143.pdf" Page 14 and 38
   kdegree = (temp*0.1) - 273.15; //273.15 is K-Degree constant 
   return kdegree;


int GotBatteryVoltage(void)

   int temp = 0;
   temp = ReadI2CWORDSTATE(0x16, 0x09);//Check "bq2084-v143.pdf" Page 14 and 39
   return temp;


int GotBatteryLifePercent(void)

   int  temp = 0;
   temp = ReadI2CWORDSTATE(0x16, 0x0d);//Check "bq2084-v143.pdf" Page 14 and 40
   return temp;


WORD GotBatteryLifeTime(void)

   WORD temp = 0;
   temp = ReadI2CWORDSTATE(0x16, 0x11);//Check "bq2084-v143.pdf" Page 14 and 41
   return temp;


bool Gotalarm(void)

      
    bool bResult = ReadI2CWORD(0x16,0x16,&lsb,&msb); //Read flag state of pw016 from smbus mapping ram area
	if(bResult)
	{
		tmp = msb;
		if(tmp&0x80)
		{
                   gtk_entry_set_text(GTK_ENTRY(Over_Charge),"YES");
                   pw016_var.f_Over_Charge=TRUE;
                }
		else
		{
			gtk_entry_set_text(GTK_ENTRY(Over_Charge),"NO");
			pw016_var.f_Over_Charge=FALSE;
		}
		tmp = msb ;
		if(tmp&0x40)
		{
			gtk_entry_set_text(GTK_ENTRY(Terminate_Charge),"YES");
			pw016_var.f_Terminate_Charge=TRUE;
		}
		else>
		{
			gtk_entry_set_text(GTK_ENTRY(Terminate_Charge),"NO");
			pw016_var.f_Terminate_Charge=FALSE;
		}
		tmp = msb ;
		if(tmp&0x10)
		{
			gtk_entry_set_text(GTK_ENTRY(Over_Temprature),"YES");
			pw016_var.f_Over_Temprature=TRUE;
		}	
		else
		{
			gtk_entry_set_text(GTK_ENTRY(Over_Temprature),"NO");
			pw016_var.f_Over_Temprature=FALSE;
		}
		tmp = msb ;
		if(tmp&0x08)
		{
			gtk_entry_set_text(GTK_ENTRY(Temprature_Discharged),"YES");
			pw016_var.f_Temprature_Discharged=TRUE;
		}
		else
		{
			gtk_entry_set_text(GTK_ENTRY(Temprature_Discharged),"NO");
			pw016_var.f_Temprature_Discharged=FALSE;
		}
		tmp = msb ;
		if(tmp&0x02)
		{
			gtk_entry_set_text(GTK_ENTRY(Remain_Capacity),"YES");
			pw016_var.f_Remain_Capacity=TRUE;
		}
		else
		{
			gtk_entry_set_text(GTK_ENTRY(Remain_Capacity),"NO");
			pw016_var.f_Remain_Capacity=FALSE;
		}
		tmp = msb ;
		if(tmp&0x01)
		{
			gtk_entry_set_text(GTK_ENTRY(Remaining_Time),"YES");
			pw016_var.f_Remaining_Time=TRUE;
                }
		else
		{
			gtk_entry_set_text(GTK_ENTRY(Remaining_Time),"NO");
			pw016_var.f_Remaining_Time=FALSE;
		}
		tmp = lsb ;
		if(tmp&0x20)
		{
			gtk_entry_set_text(GTK_ENTRY(Fully_Charged),"YES");
			pw016_var.f_Fully_Charged=TRUE;
		}
		else
		{
			gtk_entry_set_text(GTK_ENTRY(Fully_Charged),"NO");
			pw016_var.f_Fully_Charged=FALSE;
		}
		tmp = lsb ;
		if(tmp&0x10)
		{
			gtk_entry_set_text(GTK_ENTRY(Fully_Discharged),"YES");
			pw016_var.f_Fully_Discharged=TRUE;
		}
		else
		{
			gtk_entry_set_text(GTK_ENTRY(Fully_Discharged),"NO");
			pw016_var.f_Fully_Discharged=FALSE;
		}
Personal tools