From 163b1f8571beb724fa82beb62b6ff2c3900d1395 Mon Sep 17 00:00:00 2001 From: payton Date: Mon, 29 Jan 2024 16:12:22 +0800 Subject: [PATCH] =?UTF-8?q?1.=E7=94=B5=E5=8E=8B=E5=88=86=E4=BD=8D=E8=B0=83?= =?UTF-8?q?=E6=95=B40129=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sf_app/code/include/sf_commu_mcu_reg.h | 2 +- .../sf_app/code/source/battery/sf_battery.c | 61 +++++++++++++++---- .../sifar/code/source/common/sf_common.c | 2 +- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/code/application/source/sf_app/code/include/sf_commu_mcu_reg.h b/code/application/source/sf_app/code/include/sf_commu_mcu_reg.h index 315c88769..e5b28e1b7 100755 --- a/code/application/source/sf_app/code/include/sf_commu_mcu_reg.h +++ b/code/application/source/sf_app/code/include/sf_commu_mcu_reg.h @@ -32,7 +32,7 @@ #define REG_SIZE 91 #define SF_MCU_NIGHT_MODE_LUMINANCE 160 -#define SF_BATT_RECOVERY 72 //S530 +#define SF_BATT_RECOVERY 75 //S530 /*REG POWER_OFFON*/ #define MCU_MODE_AUTO 0x00 diff --git a/code/application/source/sf_app/code/source/battery/sf_battery.c b/code/application/source/sf_app/code/source/battery/sf_battery.c index 32458df12..94f664a04 100755 --- a/code/application/source/sf_app/code/source/battery/sf_battery.c +++ b/code/application/source/sf_app/code/source/battery/sf_battery.c @@ -112,7 +112,32 @@ UINT32 sf_battery_voltage_convert(UINT32 resistanceGnd, UINT32 resistanceVin, UI } return volt; } +/************************************************* + Function: sf_battery_voltage_convert + Description: battery voltage convert + Input: resistanceGnd:Grounding terminal resistance,resistanceVin:Input resistance,adcVal:adc val + Output: N/A + Return: Volt * 10 + Others: N/A +*************************************************/ +UINT32 sf_li_battery_voltage_convert(UINT32 resistanceGnd, UINT32 resistanceVin, UINT32 adcVal) +{ + UINT32 volt = 0; + /*511 * (detected voltage) / (SARADC reference voltage) + DC input voltage x resistanceGnd/(resistanceGnd + resistanceVin) = detected voltage, + SARADC reference voltage:1.8V + */ + + //volt = 27 * adcVal * (resistanceGnd + resistanceVin) / resistanceGnd / 511; + //volt = 27 * adcVal * (resistanceGnd + resistanceVin) / resistanceGnd / 2696; + if(adcVal) + { + //volt = (27 * adcVal + 554) / 539; + volt = 27 * (adcVal + 24) * (resistanceGnd + resistanceVin) / resistanceGnd / 2696; + } + return volt; +} /************************************************* Function: sf_aa_battery_voltage_convert Description: battery voltage convert @@ -152,7 +177,19 @@ UINT32 sf_battery_convert_to_adc(UINT32 resistanceGnd, UINT32 resistanceVin, UIN } return adcVal; } +UINT32 sf_li_battery_convert_to_adc(UINT32 resistanceGnd, UINT32 resistanceVin, UINT32 volt) +{ + UINT32 adcVal = 0; + //adcVal = volt * resistanceGnd * 511 / 27 / (resistanceGnd + resistanceVin); + //adcVal = volt * resistanceGnd * 2696 / 27 / (resistanceGnd + resistanceVin); + if(volt) + { + //adcVal = (volt * 531 - 3097) / 27; + adcVal = volt * resistanceGnd * 2696 / 27 / (resistanceGnd + resistanceVin) - 270;//compensate 136 + } + return adcVal; +} UINT32 sf_aa_battery_convert_to_adc(UINT32 resistanceGnd, UINT32 resistanceVin, UINT32 volt) { UINT32 adcVal = 0; @@ -371,7 +408,7 @@ UINT32 sf_battery_adc_value_get_once(void) if(sf_adc_value_get(SF_ADC_LI, &batAdc) == SUCCESS) { - liPolymerVoltageVal = sf_battery_voltage_convert(24, 100, batAdc); + liPolymerVoltageVal = sf_li_battery_voltage_convert(24, 100, batAdc); //liPolymerVoltageVal += 2; // if(puiPara->BatteryLogSwitch) // printf("Li ADC Value:%d After Convert:%d(%d.%dV)\n",batAdc,liPolymerVoltageVal,liPolymerVoltageVal/10,liPolymerVoltageVal%10); @@ -717,7 +754,7 @@ signed int sf_battery_value_fast_get(void) if(puiPara->BatteryLogSwitch) { - printf("%s:%d [%d]Li Battery ADC Value=%d,After Convert:%d(%d.%dV)\n", __FUNCTION__, __LINE__, readBatCnt + 1, sf_battery_convert_to_adc(24, 100, batValueList[readBatCnt]), + printf("%s:%d [%d]Li Battery ADC Value=%d,After Convert:%d(%d.%dV)\n", __FUNCTION__, __LINE__, readBatCnt + 1, sf_li_battery_convert_to_adc(24, 100, batValueList[readBatCnt]), batValueList[readBatCnt], batValueList[readBatCnt] / 10, batValueList[readBatCnt] % 10); } } @@ -912,7 +949,7 @@ void sf_battery_level_polling(void) if(_LiPolymerVoltageVal) { - printf("Li Battery Adc:%d After Convert:(%d.%dV)\n\n", sf_battery_convert_to_adc(24, 100, _LiPolymerVoltageVal), _LiPolymerVoltageVal / 10, _LiPolymerVoltageVal % 10); + printf("Li Battery Adc:%d After Convert:(%d.%dV)\n\n", sf_li_battery_convert_to_adc(24, 100, _LiPolymerVoltageVal), _LiPolymerVoltageVal / 10, _LiPolymerVoltageVal % 10); } else { @@ -958,7 +995,7 @@ void sf_battery_level_polling(void) if(LiPolymerVoltageVal) { - printf("[average]Li Battery Adc:%d After Convert:(%d.%dV)\n\n", sf_battery_convert_to_adc(24, 100, LiPolymerVoltageVal), LiPolymerVoltageVal / 10, LiPolymerVoltageVal % 10); + printf("[average]Li Battery Adc:%d After Convert:(%d.%dV)\n\n", sf_li_battery_convert_to_adc(24, 100, LiPolymerVoltageVal), LiPolymerVoltageVal / 10, LiPolymerVoltageVal % 10); } else { @@ -1177,9 +1214,9 @@ UINT8 sf_battery_value_get(UINT8 nightMode) { batteryVal = LiPolymerVoltageVal; - if(batteryVal < 66) + if(batteryVal < 65) { - if(nightMode && (batteryVal >= 45)) + if(nightMode && (batteryVal >= 43)) value = 1; else value = 0; @@ -1235,9 +1272,9 @@ UINT8 sf_battery_value_get(UINT8 nightMode) if(puiPara->BatteryType == SF_BATT_ALKALINE) //ALK { - if(batteryVal < 63) + if(batteryVal < 62) { - if(nightMode && (batteryVal >= 45)) + if(nightMode && (batteryVal >= 43)) value = 1; else value = 0; @@ -1289,9 +1326,9 @@ UINT8 sf_battery_value_get(UINT8 nightMode) } else if(puiPara->BatteryType == SF_BATT_NI_MH) //NIH { - if(batteryVal < 61) + if(batteryVal < 60) { - if(nightMode && (batteryVal >= 45)) + if(nightMode && (batteryVal >= 43)) value = 1; else value = 0; @@ -1343,9 +1380,9 @@ UINT8 sf_battery_value_get(UINT8 nightMode) } else { - if(batteryVal < 63) + if(batteryVal < 62) { - if(nightMode && (batteryVal >= 45)) + if(nightMode && (batteryVal >= 43)) value = 1; else value = 0; diff --git a/code/lib/source/sifar/code/source/common/sf_common.c b/code/lib/source/sifar/code/source/common/sf_common.c index 4c59cc6ef..cc2e8b20a 100755 --- a/code/lib/source/sifar/code/source/common/sf_common.c +++ b/code/lib/source/sifar/code/source/common/sf_common.c @@ -2599,7 +2599,7 @@ BOOL sf_is_flash_voltage_abnormal(void) printf("powerVal=%d batteryType=%d \n", powerVal, batteryType); - if((/*SF_POWER_TYPE_DC*/1 != batteryType) && (powerVal < 56) ) + if((/*SF_POWER_TYPE_DC*/1 != batteryType) && (powerVal < 55) ) { printf("low battery no write flash\n"); return TRUE;