修改电池温度检测频率为五分钟一次 1511/1 1511/head
authorpenglei <1624952103@qq.com>
Wed, 11 Dec 2024 09:16:20 +0000 (17:16 +0800)
committerpenglei <1624952103@qq.com>
Wed, 11 Dec 2024 09:16:20 +0000 (17:16 +0800)
code/sdk/application/battery/service/battery_driver.cpp
code/sdk/application/battery/service/battery_service.cpp

index a6a4869..8b64247 100644 (file)
@@ -568,7 +568,8 @@ static bool adc_get_sample_result(float *voltage, uint8_t channel)
     uint32_t stick = 0;
     uint32_t sample_zero_count = 0;
     //开启 battery NTC 开关
-    uapi_gpio_set_val(BATTERY_NTC_GPIO,GPIO_LEVEL_LOW);
+    if(channel != ADC_CHANNEL_BAT_VOLTAGE)
+        uapi_gpio_set_val(BATTERY_NTC_GPIO,GPIO_LEVEL_LOW);
        
     if (channel >= ADC_CHANNEL_4) {
         sample_number = HAL_ADC_SAMPLE_NUMBER_CONFIG_1;
@@ -639,8 +640,9 @@ static bool adc_get_sample_result(float *voltage, uint8_t channel)
     }
     // osal_printk("channel = %d , stick = %d , voltage = %.04f.\r\n", channel,stick,*voltage);
         
-    //关闭 battery NTC 电源     
-    uapi_gpio_set_val(BATTERY_NTC_GPIO,GPIO_LEVEL_HIGH);
+    //关闭 battery NTC 电源   
+    if(channel != ADC_CHANNEL_BAT_VOLTAGE) 
+        uapi_gpio_set_val(BATTERY_NTC_GPIO,GPIO_LEVEL_HIGH);
 
     UNUSED(discard_number);
     return true;
@@ -798,7 +800,13 @@ uint8_t batteryservice_get_battery_temp(float *temp)
 {
     battery_info_t *current_battery_info = get_current_battery_info();
     *temp = current_battery_info->battery_ntc_temp;
-   
+    // PRINT("*temp : %.3f\n",*temp);
+    if(!*temp)
+    {
+        batteryservice_get_voltage_by_channel(&current_battery_info->battery_ntc_temp,ADC_CHANNEL_BAT_TEMP);
+        uapi_tcxo_delay_ms(20);   
+        *temp = current_battery_info->battery_ntc_temp;
+    }
     return 0;
 }
 uint8_t batteryservice_get_pcb_temp(float *temp)
index 9096afe..91c8cfc 100644 (file)
@@ -278,14 +278,25 @@ uint8_t get_charge_stat(void)
         return 0;
 }
 
+static uint8_t bat_temp_cnt = 0;
 
 static void battery_check_voltage(void)
 {
     battery_info_t *current_battery_info = get_current_battery_info();
     batteryservice_get_voltage_by_channel(&current_battery_info->battery_voltage,ADC_CHANNEL_BAT_VOLTAGE);
     uapi_tcxo_delay_ms(20);
-    batteryservice_get_voltage_by_channel(&current_battery_info->battery_ntc_temp,ADC_CHANNEL_BAT_TEMP);
-    uapi_tcxo_delay_ms(20);
+
+    if(bat_temp_cnt >= 8) //5分钟左右检测一次电池温度
+    {
+        bat_temp_cnt = 0;
+        batteryservice_get_voltage_by_channel(&current_battery_info->battery_ntc_temp,ADC_CHANNEL_BAT_TEMP);
+        // printf("current_battery_info->battery_ntc_temp : %.3f \n",current_battery_info->battery_ntc_temp);
+        uapi_tcxo_delay_ms(20);
+    }
+    else
+    {
+        bat_temp_cnt ++;
+    }
     // batteryservice_get_voltage_by_channel(&current_battery_info->pcb_ntc_temp,ADC_CHANNEL_PCB_TEMP);
     // uapi_tcxo_delay_ms(20);    
 }