From 62b0540034c1a1342bfb170347215fa655829b18 Mon Sep 17 00:00:00 2001 From: payton Date: Mon, 4 Sep 2023 14:52:22 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=88=A4=E6=96=AD=E7=94=B5=E6=B1=A0=E7=94=B5?= =?UTF-8?q?=E5=8E=8B0=E5=80=BC=E7=9A=84=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sf_app/code/source/battery/sf_battery.c | 20 +++++++++--- .../driver/na51089/source/mcu/sf_battery.c | 31 ++++++++++++++----- 2 files changed, 40 insertions(+), 11 deletions(-) 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 b5954dddb..0302e2229 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 @@ -104,7 +104,10 @@ UINT32 sf_battery_voltage_convert(UINT32 resistanceGnd, UINT32 resistanceVin, UI //volt = 27 * adcVal * (resistanceGnd + resistanceVin) / resistanceGnd / 511; //volt = 27 * adcVal * (resistanceGnd + resistanceVin) / resistanceGnd / 2696; - volt = (27 * adcVal + 554) / 539; + if(adcVal) + { + volt = (27 * adcVal + 554) / 539; + } return volt; } @@ -126,7 +129,10 @@ UINT32 sf_aa_battery_voltage_convert(UINT32 resistanceGnd, UINT32 resistanceVin, */ //volt = 27 * adcVal * (resistanceGnd + resistanceVin) / resistanceGnd / 511; - volt = (27 * adcVal + 3097) / 531; + if(adcVal) + { + volt = (27 * adcVal + 3097) / 531; + } return volt; } @@ -136,7 +142,10 @@ UINT32 sf_battery_convert_to_adc(UINT32 resistanceGnd, UINT32 resistanceVin, UIN //adcVal = volt * resistanceGnd * 511 / 27 / (resistanceGnd + resistanceVin); //adcVal = volt * resistanceGnd * 2696 / 27 / (resistanceGnd + resistanceVin); - adcVal = (volt * 539 - 554) / 27; + if(volt) + { + adcVal = (volt * 539 - 554) / 27; + } return adcVal; } @@ -146,7 +155,10 @@ UINT32 sf_aa_battery_convert_to_adc(UINT32 resistanceGnd, UINT32 resistanceVin, //adcVal = volt * resistanceGnd * 511 / 27 / (resistanceGnd + resistanceVin); //adcVal = volt * resistanceGnd * 2696 / 27 / (resistanceGnd + resistanceVin); - adcVal = (volt * 531 - 3097) / 27; + if(volt) + { + adcVal = (volt * 531 - 3097) / 27; + } return adcVal; } UINT32 sf_get_max_value(UINT32 *_ValueList) diff --git a/rtos/code/driver/na51089/source/mcu/sf_battery.c b/rtos/code/driver/na51089/source/mcu/sf_battery.c index 82e38f313..68c0861ba 100755 --- a/rtos/code/driver/na51089/source/mcu/sf_battery.c +++ b/rtos/code/driver/na51089/source/mcu/sf_battery.c @@ -108,7 +108,10 @@ UINT32 sf_battery_voltage_convert(UINT32 resistanceGnd, UINT32 resistanceVin, UI //volt = 27 * adcVal * (resistanceGnd + resistanceVin) / resistanceGnd / 511; //volt = 27 * adcVal * (resistanceGnd + resistanceVin) / resistanceGnd / 2696; - volt = (27 * adcVal + 554) / 539; + if(adcVal) + { + volt = (27 * adcVal + 554) / 539; + } return volt; } @@ -130,7 +133,10 @@ UINT32 sf_aa_battery_voltage_convert(UINT32 resistanceGnd, UINT32 resistanceVin, */ //volt = 27 * adcVal * (resistanceGnd + resistanceVin) / resistanceGnd / 511; - volt = (27 * adcVal + 3097) / 531; + if(adcVal) + { + volt = (27 * adcVal + 3097) / 531; + } return volt; } @@ -140,7 +146,10 @@ UINT32 sf_battery_convert_to_adc(UINT32 resistanceGnd, UINT32 resistanceVin, UIN //adcVal = volt * resistanceGnd * 511 / 27 / (resistanceGnd + resistanceVin); //adcVal = volt * resistanceGnd * 2696 / 27 / (resistanceGnd + resistanceVin); - adcVal = (volt * 539 - 554) / 27; + if(volt) + { + adcVal = (volt * 539 - 554) / 27; + } return adcVal; } @@ -150,7 +159,10 @@ UINT32 sf_aa_battery_convert_to_adc(UINT32 resistanceGnd, UINT32 resistanceVin, //adcVal = volt * resistanceGnd * 511 / 27 / (resistanceGnd + resistanceVin); //adcVal = volt * resistanceGnd * 2696 / 27 / (resistanceGnd + resistanceVin); - adcVal = (volt * 531 - 3097) / 27; + if(volt) + { + adcVal = (volt * 531 - 3097) / 27; + } return adcVal; } UINT32 sf_get_max_value(UINT32 *_ValueList) @@ -1659,9 +1671,14 @@ void sf_BatteryInfoSave(char *name, FST_FILE fd) }*/ //printf("fileName:%s\n",SF_BATTERY_TEST_FILE); //fd = FileSys_OpenFile(SF_BATTERY_TEST_FILE, FST_OPEN_ALWAYS | FST_OPEN_WRITE); - - LibatAdc = sf_battery_convert_to_adc(24, 100, LiPolymerVoltageValTest); - batAdc = sf_battery_convert_to_adc(24, 100, BatVoltageValTest); + if(LiPolymerVoltageValTest) + { + LibatAdc = sf_battery_convert_to_adc(24, 100, LiPolymerVoltageValTest); + } + if(BatVoltageValTest) + { + batAdc = sf_aa_battery_convert_to_adc(24, 100, BatVoltageValTest); + } sprintf(tmpBuf, "%s BatAdc=%lu BatVal=%lu LiBatAdc=%lu LiBatVal=%lu TemperAdc=%lu\r\n", name, batAdc, BatVoltageValTest, LibatAdc, LiPolymerVoltageValTest, TemperAdc);