From 1c179f260e506bb329d0b9e3d276666fb20712be Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Wed, 11 Dec 2024 17:16:20 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E7=94=B5=E6=B1=A0=E6=B8=A9?= =?utf8?q?=E5=BA=A6=E6=A3=80=E6=B5=8B=E9=A2=91=E7=8E=87=E4=B8=BA=E4=BA=94?= =?utf8?q?=E5=88=86=E9=92=9F=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../battery/service/battery_driver.cpp | 16 ++++++++++++---- .../battery/service/battery_service.cpp | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/code/sdk/application/battery/service/battery_driver.cpp b/code/sdk/application/battery/service/battery_driver.cpp index a6a4869b2..8b6424710 100644 --- a/code/sdk/application/battery/service/battery_driver.cpp +++ b/code/sdk/application/battery/service/battery_driver.cpp @@ -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(¤t_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) diff --git a/code/sdk/application/battery/service/battery_service.cpp b/code/sdk/application/battery/service/battery_service.cpp index 9096afe1d..91c8cfc60 100644 --- a/code/sdk/application/battery/service/battery_service.cpp +++ b/code/sdk/application/battery/service/battery_service.cpp @@ -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(¤t_battery_info->battery_voltage,ADC_CHANNEL_BAT_VOLTAGE); uapi_tcxo_delay_ms(20); - batteryservice_get_voltage_by_channel(¤t_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(¤t_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(¤t_battery_info->pcb_ntc_temp,ADC_CHANNEL_PCB_TEMP); // uapi_tcxo_delay_ms(20); } -- 2.17.1