当前位置:网站首页>2022 - 06 - 09 rk817 PMU Battery Temperature Detection

2022 - 06 - 09 rk817 PMU Battery Temperature Detection

2022-06-10 21:52:00 Xichen, lune de mer

Un.、Connexions matérielles,TS/GPIO,Thermistor connecté à la batterie thermistor

2.、Thermistor(the resistance of the thermistor)Il existe deux catégories générales::
      1、La résistance augmente avec la température,Appelé facteur de température positif(PTC,Positive Temperature Coefficient)Thermistor.
      2、La résistance diminue avec la température,Appelé coefficient de température négatif(NTC,Negative Temperature Coefficient)Thermistor.

Trois、Schéma interne de la batterie

 

Quatre、 Type thermométriqueNTC Tableau des caractéristiques de température de résistance des Thermistors

 

 Cinq、 Registre impliqué dans l'obtention de la valeur du Thermistor

1、gas_gauge_ADC_CONFIG0
Address: Operational Base + offset (0x0050),TS_ADC_EN BIT à configurer comme 1

 

2、gas_gauge_ADC_CONFIG1  Address: Operational Base + offset (0x0055) VOL_ADC_TSCUR_SEL ..Assurez - vous que celui - ci décrit le passage de TS La taille du courant de sortie du pied .

 3、CODEC_AREF_RTCFG1
Address: Operational Base + offset (0x0017) REF_ADC_SEL ParamètresADC Tension de référence.

 

 4、gas_gauge_BAT_TS_H Etgas_gauge_BAT_TS_L AccèsADC Valeur

Six、Code modifié,Et tester

1、Code modifié

commit b353b70850442863c4b051beb258681c6cd71cdf
Author: xxx.wei <[email protected]>
Date:   Thu Jun 9 14:09:22 2022 +0800

    get battery temperature
    
diff --git a/drivers/power/supply/rk817_battery.c b/drivers/power/supply/rk817_battery.c
index 32e2d65..4c49a27 100755
--- a/drivers/power/supply/rk817_battery.c
+++ b/drivers/power/supply/rk817_battery.c
@@ -632,6 +632,11 @@ struct rk817_battery_device {
 	bool				change; /* Battery status change, report information */
 };
 
+struct battery_res_temp_data {
+	unsigned long res;
+	int temp;
+};
+
 static void rk817_bat_resume_work(struct work_struct *work);
 
 static u64 get_boot_sec(void)
@@ -2095,6 +2100,40 @@ static int rk817_battery_time_to_full(struct rk817_battery_device *battery)
 	return time_sec;
 }
 
+static const struct battery_res_temp_data bat_temp_table[] = {
+	{324  ,125},{  371,120},{  427,115},{  491,110},{  567,105},
+	{657  ,100},{  763, 95},{  890, 90},{ 1044, 85},{ 1228, 80},
+	{1452 , 75},{ 1725, 70},{ 2058, 65},{ 2466, 60},{ 2968, 55},
+	{3588 , 50},{ 4357, 45},{ 5318, 40},{ 6523, 35},{ 8047, 30},
+	{10000, 25},{12461, 20},{15652, 15},{19783, 10},{25152,  5},
+	{32116,  0},{41306, -5},{53280,-10},{68982,-15},{89682,-20}
+};
+
+#define BAT_TEMP_TEBLE_NUM (sizeof(bat_temp_table) / sizeof(bat_temp_table[0]))
+
+static int  rk817_battery_get_temperature(struct rk817_battery_device *battery)
+{
+    int i ,ret = 25 ;
+	unsigned long val = 0 ,res = 0;
+	val = rk817_bat_field_read(battery, BAT_TS_H) << 8;
+	val |= rk817_bat_field_read(battery, BAT_TS_L);
+    res=(val * 12 *10000)/(0XFFFF+1);//res=(val * 12 *1000000)/((0XFFFF+1)*10*10);
+	for( i = 0; i < BAT_TEMP_TEBLE_NUM ;i++)
+	{
+		if ( res <= bat_temp_table[i].res)
+		{
+			if( i > 0)
+				ret = bat_temp_table[i].temp + ((bat_temp_table[i].res - res)*5/(bat_temp_table[i].res-bat_temp_table[i-1].res));
+			else
+				ret = bat_temp_table[i].temp;
+
+			break;
+	    }
+   }
+	printk("Negative Temperature Coefficient,val = %lu ,res = %lu ret = %d \r\n",val,res,ret);
+	return ret;
+}
+
 static int rk817_battery_get_property(struct power_supply *psy,
 				      enum power_supply_property psp,
 				      union power_supply_propval *val)
@@ -2141,6 +2180,7 @@ static int rk817_battery_get_property(struct power_supply *psy,
 		break;
 	case POWER_SUPPLY_PROP_TEMP:
 		val->intval = battery->temperature;
+		val->intval = rk817_battery_get_temperature(battery);
 		if (battery->pdata->bat_mode == MODE_VIRTUAL)
 			val->intval = VIRTUAL_TEMPERATURE;
 		break;

 2、cat /sys/class/power_supply/battery/temp Obtenir la valeur de température

 

Sept、Article de référence

RK3566,rk817Allez.TS La fonction d'entrée analogique du pied est utilisée comme NTCDétection_lkdcomBlog de-CSDNBlogs

NTCCapteur de température395010k_ Tableau correspondant de la résistance à la température du Thermistor - Bibliothèque Baidu

原网站

版权声明
本文为[Xichen, lune de mer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206102037511503.html