|
@@ -462,47 +462,86 @@ void RD_SaveAndUpdateInfo(MC_GearSt_Struct_t GearSt, MC_AssistRunMode_Struct_t M
|
|
|
MC_AssistRunMode_Old = MC_AssistRunMode;
|
|
|
}
|
|
|
|
|
|
+//运行周期200ms
|
|
|
uint8_t Battery_SocCal(uint16_t Voltage_mV)
|
|
|
{
|
|
|
-
|
|
|
- static uint32_t PeriodTimeCnt = 0;
|
|
|
- static uint8_t Result = 0,Result_Pre=0;
|
|
|
+ static uint16_t TimeDelayCnt = 0;
|
|
|
+ static uint32_t FiltSum = 0;
|
|
|
+ static uint8_t FiltCnt = 0;
|
|
|
+ static uint8_t Result = 0, Result_Pre=0;
|
|
|
+ static TrueOrFalse_Flag_Struct_t InitFlag = FALSE;
|
|
|
uint16_t i;
|
|
|
- uint16_t num;
|
|
|
- uint32_t batteryTotalQ,batteryRemainQ;
|
|
|
- uint16_t Voltage;
|
|
|
-
|
|
|
- Voltage = Voltage_mV / 10;
|
|
|
+ uint16_t TableNum;
|
|
|
+ uint32_t batteryTotalQ, batteryRemainQ;
|
|
|
+ uint16_t Vol_Avg = 0;
|
|
|
|
|
|
- num = sizeof(battery_VoltageQuantity)/4;
|
|
|
-
|
|
|
- batteryTotalQ = battery_VoltageQuantity[num-1][1];
|
|
|
+ TableNum = sizeof(battery_VoltageQuantity) / 4;
|
|
|
+ batteryTotalQ = battery_VoltageQuantity[TableNum - 1][1];
|
|
|
batteryRemainQ = batteryTotalQ;
|
|
|
|
|
|
- Result_Pre = MC_RunInfo.SOC;
|
|
|
- Result = Result_Pre;
|
|
|
-
|
|
|
- if((HAL_GetTick() - PeriodTimeCnt) > 2000)//计算周期2s
|
|
|
+ TimeDelayCnt++;
|
|
|
+ //初始化电压上升较慢,开机时动态效果
|
|
|
+ if(TimeDelayCnt <= 10) return 0;
|
|
|
+ else if(TimeDelayCnt <= 15) return 10;
|
|
|
+ else if(TimeDelayCnt <= 20) return 25;
|
|
|
+ else if(TimeDelayCnt <= 25) return 45;
|
|
|
+ else if(TimeDelayCnt <= 30) return 65;
|
|
|
+ else if(TimeDelayCnt <= 35) return 85;
|
|
|
+ else
|
|
|
{
|
|
|
- PeriodTimeCnt = HAL_GetTick();
|
|
|
- for(i=0;i<num;i++)
|
|
|
+ if(InitFlag == FALSE)//等待约5s后,计算一次初始值
|
|
|
{
|
|
|
- if(battery_VoltageQuantity[i][0] <= Voltage)
|
|
|
- {
|
|
|
- batteryRemainQ = batteryTotalQ - battery_VoltageQuantity[i][1] ; //A*s
|
|
|
- break;
|
|
|
- }
|
|
|
- else//电池电压低于最小值
|
|
|
+ InitFlag = TRUE;
|
|
|
+ for(i=0; i<TableNum; i++)
|
|
|
{
|
|
|
- batteryRemainQ = 0;
|
|
|
+ if(battery_VoltageQuantity[i][0] <= (Voltage_mV / 10))
|
|
|
+ {
|
|
|
+ batteryRemainQ = batteryTotalQ - battery_VoltageQuantity[i][1];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else//电池电压低于最小值
|
|
|
+ {
|
|
|
+ batteryRemainQ = 0;
|
|
|
+ }
|
|
|
}
|
|
|
+ Result = batteryRemainQ * 100 / batteryTotalQ;
|
|
|
}
|
|
|
- Result = batteryRemainQ * 100 / batteryTotalQ;
|
|
|
- if(Result >= Result_Pre)
|
|
|
+ else//第一次计算后,采用25组电压平均值
|
|
|
{
|
|
|
- Result = Result_Pre;
|
|
|
+ Result_Pre = MC_RunInfo.SOC;
|
|
|
+ Result = Result_Pre;
|
|
|
+
|
|
|
+ //取25组数据的平均值计算SOC
|
|
|
+ FiltSum += Voltage_mV;
|
|
|
+ FiltCnt++;
|
|
|
+ if(FiltCnt >= 25)
|
|
|
+ {
|
|
|
+ Vol_Avg = FiltSum / 25;
|
|
|
+ FiltSum = 0;
|
|
|
+ FiltCnt = 0;
|
|
|
+ //查表计算SOC
|
|
|
+ for(i=0; i<TableNum; i++)
|
|
|
+ {
|
|
|
+ if(battery_VoltageQuantity[i][0] <= (Vol_Avg / 10))
|
|
|
+ {
|
|
|
+ batteryRemainQ = batteryTotalQ - battery_VoltageQuantity[i][1] ; //A*s
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else//电池电压低于最小值
|
|
|
+ {
|
|
|
+ batteryRemainQ = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Result = batteryRemainQ * 100 / batteryTotalQ;
|
|
|
+ if(Result > Result_Pre)//电量上升时,突变较小,取上次计算值
|
|
|
+ {
|
|
|
+ if((Result < (Result_Pre + 30)) && (Result < 90))
|
|
|
+ {
|
|
|
+ Result = Result_Pre;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ return Result;
|
|
|
}
|
|
|
- return Result;
|
|
|
}
|
|
|
-
|