Browse Source

【3.0.0.33】 合并齐腾飞更改
Merge remote-tracking branch 'QX/V3-7250-QTF' into V3-V30XX-6060

* QX/V3-7250-QTF:
1.SOC及CMD的调用使能 变动 2.SFM 新增 温度1s升高超过20℃的 合理性故障; 新增 不一致性诊断 3.cdmv_V_deltOCV 及cdmv_ohm_deltR 的数据类型改为int16_T
1.修改 cdmv_V_deltOCV 及 cdmv_ohm_deltR 的数据类型 2.新增1s温度上升>20 的合理性故障

# Conflicts:
# src/EmbeddedCoder_src/SOC.c

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
0f56017f35

+ 2 - 2
inc/AppConfig.h

@@ -2,7 +2,7 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-11-05 10:34:37
+ * @LastEditTime : 2021-11-05 11:14:31
  * @Description  : App Config H file 配置文件,可以针对不同参数进行更改
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppConfig.h
  */
@@ -14,7 +14,7 @@
 #define DATA_MODULE_TYPE (1)           //1表示NB模块,2表示4G cat1
 #define EOLSTATE (0)                   //1表示下线检测跳过,使用默认值,0表示使用下线检测
 #define DEFAULT_SN "RLTEST00000000001" //默认上传的SN编码
-#define APPSWVERSION 0x03000020        //数据模块软件版本号
+#define APPSWVERSION 0x03000021        //数据模块软件版本号
 #define RELAYCONFIG 0                  //继电器配置
 #define TCP_ADD "iotp.fast-fun.cn"     //数据上传的地址
 #define TCP_PORT 8712                  //数据上传的端口

+ 7 - 2
inc/EmbeddedCoder_inc/BCUDisp.h

@@ -50,13 +50,18 @@ extern boolean_T ihd_st_disChrgMosControl;
 extern boolean_T ihd_st_relayControl;    
 extern uint8_T ihd_st_heatForceControl;
 extern uint8_T ihd_st_EOLState;
+extern boolean_T ihd_flg_urtRecFlg;
 
 extern int16_T sfmd_I_curr;                              /*处理后整包电流 */
 extern uint16_T sfmd_T_modTMax;                          /*处理后模组温度最小 */
 extern uint16_T sfmd_T_modTMin;                          /*处理后模组温度最大 */
+extern uint16_T sfmd_idx_modTMax;                          /*处理后模组温度最小 */
+extern uint16_T sfmd_idx_modTMin;                          /*处理后模组温度最大 */
 extern uint16_T sfmd_V_cellUAvrg;                        /*处理后单体电压平均 */
 extern uint16_T sfmd_V_cellUMax;                         /*处理后单体电压最大 */
 extern uint16_T sfmd_V_cellUMin;                         /*处理后单体电压最小 */
+extern uint16_T sfmd_idx_cellUMin;
+extern uint16_T sfmd_idx_cellUMax;
 extern boolean_T sfmd_flg_cellUDisable;                  /*单体电压有效标志位 ; 0为有效;1为无效 */
 extern boolean_T sfmd_flg_currDisable;                   /*电流有效标志位 ; 0为有效;1为无效 */
 extern boolean_T sfmd_flg_modTDisable;                   /*模组温度有效标志位 ; 0为有效;1为无效 */
@@ -117,8 +122,8 @@ extern uint16_T cand_V_chrgStartStat;                    /*循环发送的充电
 extern uint16_T cand_Q_reqCp;                            /*循环发送的单体需求均衡容量; */
 extern uint16_T cand_Q_totalCp;                          /*循环发送的单体累计均衡容量; */
 
-extern uint16_T  cdmv_V_deltOCV[cmnc_num_cellUNumMax];
-extern uint16_T  cdmv_ohm_deltR[cmnc_num_cellUNumMax];
+extern int16_T  cdmv_V_deltOCV[cmnc_num_cellUNumMax];
+extern int16_T  cdmv_ohm_deltR[cmnc_num_cellUNumMax];
 extern boolean_T cdmd_flg_deltOCVDisable;
 
 extern uint16_T test_efkSocMin;

+ 1 - 0
inc/EmbeddedCoder_inc/SFM.h

@@ -1,6 +1,7 @@
 #include "rtwtypes.h"
 #include "BCUCal.h"
 #include "BCUDisp.h"
+#include <math.h>
 extern boolean_T FirstRun_SFM;
 
 extern void SFM_Init(void);

+ 7 - 7
src/AppTaskControl.c

@@ -18,13 +18,6 @@ static void ControlTask(void *arg)
 {
     /*AD采样初始化*/
     UINT32 param;
-    AdcSendReq(ADC_REQ_BITMAP_VBAT_CALI, &param, 1, ADC_GET_RESULT_TIMOUT);
-    AdcSendReq(ADC_REQ_BITMAP_INRES_CALI, &param, 1, ADC_GET_RESULT_TIMOUT);
-    NetSocDisplay(LED_SOC_0, LED_TURN_OFF);
-    NetSocDisplay(LED_SOC_1, LED_TURN_OFF);
-    NetSocDisplay(LED_SOC_2, LED_TURN_OFF);
-    NetSocDisplay(LED_SOC_3, LED_TURN_OFF);
-    FaultDisplay(LED_TURN_OFF);
     PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_IDLE);
     UINT32 CurrentTime = 0;
     UINT8 AdcOrder = 1;
@@ -35,6 +28,13 @@ static void ControlTask(void *arg)
         {
         case PROCESS_CONTROL_STATE_IDLE:
         {
+            AdcSendReq(ADC_REQ_BITMAP_VBAT_CALI, &param, 1, ADC_GET_RESULT_TIMOUT);
+            AdcSendReq(ADC_REQ_BITMAP_INRES_CALI, &param, 1, ADC_GET_RESULT_TIMOUT);
+            NetSocDisplay(LED_SOC_0, LED_TURN_OFF);
+            NetSocDisplay(LED_SOC_1, LED_TURN_OFF);
+            NetSocDisplay(LED_SOC_2, LED_TURN_OFF);
+            NetSocDisplay(LED_SOC_3, LED_TURN_OFF);
+            FaultDisplay(LED_TURN_OFF);
             osDelay(100);
             PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_WORK);
             break;

+ 1 - 0
src/EmbeddedCoder_src/BCU.c

@@ -75,6 +75,7 @@ void BCU(void)
                     ihd_flg_HVILFlt = Lockstatus;
                     ihd_st_workStat = BattWorkStateDelay;
                     ihd_flg_urtRecFlt = UartErrorFlag;
+					ihd_flg_urtRecFlg = UartRecvFlag;
                     ihd_st_chrgConnect = chargerConnectState;
                     ihd_flg_cellULowFlt = ((battWarningState)&0x01) == 1;
                     ihd_flg_battULowFlt = ((battWarningState >> 1) & 0x01) == 1;

+ 7 - 2
src/EmbeddedCoder_src/BCUDisp.c

@@ -50,13 +50,18 @@ boolean_T ihd_st_disChrgMosControl;
 boolean_T ihd_st_relayControl;    
 uint8_T ihd_st_heatForceControl;             
 uint8_T ihd_st_EOLState;                   
+boolean_T ihd_flg_urtRecFlg;
 
 int16_T sfmd_I_curr;                              /*处理后整包电流 */
 uint16_T sfmd_T_modTMax;                          /*处理后模组温度最小 */
 uint16_T sfmd_T_modTMin;                          /*处理后模组温度最大 */
+uint16_T sfmd_idx_modTMax;                          /*处理后模组温度最小 */
+uint16_T sfmd_idx_modTMin;                          /*处理后模组温度最大 */
 uint16_T sfmd_V_cellUAvrg;                        /*处理后单体电压平均 */
 uint16_T sfmd_V_cellUMax;                         /*处理后单体电压最大 */
 uint16_T sfmd_V_cellUMin;                         /*处理后单体电压最小 */
+uint16_T sfmd_idx_cellUMin;
+uint16_T sfmd_idx_cellUMax;
 boolean_T sfmd_flg_cellUDisable;                  /*单体电压有效标志位 ; 0为有效;1为无效 */
 boolean_T sfmd_flg_currDisable;                   /*电流有效标志位 ; 0为有效;1为无效 */
 boolean_T sfmd_flg_modTDisable;                   /*模组温度有效标志位 ; 0为有效;1为无效 */
@@ -117,8 +122,8 @@ uint16_T cand_V_chrgStartStat;                    /*循环发送的充电前单
 uint16_T cand_Q_reqCp;                            /*循环发送的单体需求均衡容量; */
 uint16_T cand_Q_totalCp;                          /*循环发送的单体累计均衡容量; */
 
-uint16_T  cdmv_V_deltOCV[cmnc_num_cellUNumMax] ;
-uint16_T  cdmv_ohm_deltR[cmnc_num_cellUNumMax] ;
+int16_T  cdmv_V_deltOCV[cmnc_num_cellUNumMax] ;
+int16_T  cdmv_ohm_deltR[cmnc_num_cellUNumMax] ;
 boolean_T cdmd_flg_deltOCVDisable;
 
 uint16_T test_efkSocMin;

+ 8 - 7
src/EmbeddedCoder_src/CDM.c

@@ -27,7 +27,6 @@ void CDM(void)
         FirstRun_CDM = true;
     }
     ihd_st_workStat_Delay = ihd_st_workStat;
-    
     if (FirstRun_CDM)
     {
         for (i = 0;i < cmnc_num_cellUNum;i++)
@@ -46,10 +45,11 @@ void CDM(void)
     {
         for (i = 0;i < cmnc_num_cellUNum;i++)
         {
-            cmdn_V_cellUDelt[i] = (real_T)(sfmv_V_cellU[i]  -sfmd_V_cellUAvrg) * 0.001;
+            cmdn_V_cellUDelt[i] = (real_T)(sfmv_V_cellU[i]  - sfmd_V_cellUAvrg) * 0.001;
         }
         cdmn_I_curr = (real_T) sfmd_I_curr * 0.1;
         //
+   
         for (i = 0;i < cmnc_num_cellUNum;i++)
         {
             K[0] = (P[0][i]  + cdmn_I_curr * P[1][i])/(Lambda + P[0][i] + cdmn_I_curr * P[2][i] + ( P[1][i] + cdmn_I_curr * P[3][i]) * cdmn_I_curr);
@@ -61,13 +61,13 @@ void CDM(void)
             P[1][i] = ((1 -K[0])* P[1][i] -P[3][i] * K[0] * cdmn_I_curr) /Lambda;
             P[2][i] = (-K[1] *P[0][i] +P[2][i] * (1 - K[1] * cdmn_I_curr))/Lambda;
             P[3][i] = (-K[1] *P[1][i] +P[3][i] * (1 - K[1] * cdmn_I_curr))/Lambda;
-        }
+	    }
         //
         cdmd_flg_deltOCVDisable = false;
-        for (i = 0;i < 1;i++)
-        {
-            cdmv_V_deltOCV[i] = (uint16_T) (deltaE[i]  * 1000);
-            cdmv_ohm_deltR[i] = (uint16_T) (deltaR[i]  * 1000 * 10);
+        for (i = 0;i < cmnc_num_cellUNum;i++)
+        {   
+            cdmv_V_deltOCV[i] = (int16_T) (deltaE[i]  * 1000);
+            cdmv_ohm_deltR[i] = (int16_T) (deltaR[i]  * 1000 * 1000);
             if(arf[i] > 0.05 && arf[i] < -0.05)
             {
                 cdmd_flg_deltOCVDisable = true;
@@ -79,4 +79,5 @@ void CDM(void)
         cdmd_flg_deltOCVDisable = false;
     }
     FirstRun_CDM = false;
+	
 }

File diff suppressed because it is too large
+ 305 - 76
src/EmbeddedCoder_src/SFM.c


+ 95 - 84
src/EmbeddedCoder_src/SOC.c

@@ -45,7 +45,7 @@ void SOC(void)
     static real_T Up_Min_Delay;
     static real_T Up_Max_Delay;
     static real_T Up_Avrg_Delay;
-    uint16_T cellSocMax;
+	uint16_T cellSocMax;
     uint16_T cellSocMin;
     real_T Q;
     real_T battcurr;
@@ -60,6 +60,8 @@ void SOC(void)
     static int16_T ahSoc0_est;
     static uint16_T ekfSoc0_est;
     //
+    uint16_T socd_V_chrgCCV;
+	uint16_T socd_V_disChrgCCV;
     static boolean_T overFlg;
     static boolean_T fulFlg;
     static uint8_T overCntl;
@@ -114,17 +116,17 @@ void SOC(void)
         onceFlg_chrg = true;
         onceFlg_dischrg = true;
     }
-
+    
     //=====================================================================
     ////////////////////////初始值获取//////////////////////////////////////
     //=====================================================================
     if (FirstRun_SOC)
     { //
         if (socd_pct_battSocEi > 1000 || socd_pct_bcuSocEi > 1000 || ihd_st_EOLState == 0 ||
-            (((int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) > 300 || (int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) < -300) && ihd_tm_parkTime > cmnc_tm_parkTime))
+                (((int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) > 300 || (int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) < -300) && ihd_tm_parkTime > cmnc_tm_parkTime))
         {
             socn_pct_battSocEE = look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg, (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
-            socn_pct_bcuSocEE = look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg, (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+            socn_pct_bcuSocEE  = look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg, (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
         }
         else
         {
@@ -138,14 +140,14 @@ void SOC(void)
         }
         socn_Q_cap = (uint16_T)((uint16_T)((uint32_T)sohd_pct_bcuSoh * cmnc_Q_ratedCp / 2000U) << 1);
     }
-
+	
     //printf("1----  battSocEi:%d,bcuSocEi:%d,battSocEE:%d,bcuSocEE:%d\n",socd_pct_battSocEi,socd_pct_bcuSocEi,socn_pct_battSocEE,socn_pct_bcuSocEE);
     //======================================================================
     ////////////////////////EKFSOC//////////////////////////////////////////
     //======================================================================
     battcurr = (real_T)sfmd_I_curr * 0.1;
     Q = (real_T)socn_Q_cap * 0.1;
-
+    
     //-------------------------EKFmin---------------------------------------
     if (FirstRun_SOC)
     {
@@ -157,21 +159,21 @@ void SOC(void)
         P_Min_Delay[3] = 10;
     }
     //参数查表
-    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) * 0.001;
-    Ro = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])), 12U) * 0.001 * 0.001;
-    Rp = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
-    C = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
+    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])),   12U) * 0.001;
+    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),   12U) * 0.001 * 0.001;
+    Rp  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
+    C   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
     A[3] = exp(-1 / (Rp * C));
-
+    
     B[0] = 1 / Q / 3600 * 100;
     B[1] = Rp * (1 - exp(-1 / (Rp * C)));
-
+    
     H[0] = docvmath(soc_Min_Delay);
     H[1] = 1;
-
+    
     //先验
     soc1 = soc_Min_Delay * A[0] + B[0] * battcurr;
     Up1 = Up_Min_Delay * A[3] + B[1] * battcurr;
@@ -180,15 +182,15 @@ void SOC(void)
     P1[1] = P_Min_Delay[1] * A[3] + 0.001;
     P1[2] = P_Min_Delay[2] * A[3] + 0.001;
     P1[3] = P_Min_Delay[3] * A[3] * A[3] + 0.001;
-
+    
     //增益
     K[0] = (P1[0] * H[0] + P1[2]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
     K[1] = (P1[1] * H[0] + P1[3]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
-
+    
     //后验
     deltU = (real_T)sfmd_V_cellUMin * 0.001 - UL;
     soc_Min_Delay = soc1 + K[0] * deltU;
-
+    
     if (soc_Min_Delay < (real_T)socc_pct_battSocLow * 0.1)
     {
         soc_Min_Delay = (real_T)socc_pct_battSocLow * 0.1;
@@ -197,14 +199,14 @@ void SOC(void)
     {
         soc_Min_Delay = (real_T)socc_pct_battSocUp * 0.1;
     }
-
+    
     Up_Min_Delay = Up1 + K[1] * deltU;
     //P更新
     P_Min_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
     P_Min_Delay[1] = -K[1] * H[0] * P1[0] + P1[1] * (1 - K[1]);
     P_Min_Delay[2] = (1 - K[0] * H[0]) * P1[2] - K[0] * P1[3];
     P_Min_Delay[3] = -K[1] * H[0] * P1[2] + P1[3] * (1 - K[1]);
-
+    
     //输出
     EKFSOCMin = (uint16_T)(soc_Min_Delay * 10);
     socn_flg_ekfInvalidMin = (deltU > 0.01) || (deltU < -0.01);
@@ -220,39 +222,39 @@ void SOC(void)
         P_Max_Delay[3] = 10;
     }
     // 参数查表
-    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) * 0.001;
-    Ro = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])), 12U) * 0.001 * 0.001;
-    Rp = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
-    C = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
+    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])),   12U) * 0.001;
+    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),   12U) * 0.001 * 0.001;
+    Rp  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
+    C   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
     A[3] = exp(-1 / (Rp * C));
-
+    
     B[0] = 1 / Q / 3600 * 100;
     B[1] = Rp * (1 - exp(-1 / (Rp * C)));
-
+    
     H[0] = docvmath(soc_Max_Delay);
     H[1] = 1;
-
+    
     //先验
     soc1 = soc_Max_Delay * A[0] + B[0] * battcurr;
     Up1 = Up_Max_Delay * A[3] + B[1] * battcurr;
     UL = ocv + battcurr * Ro + Up1;
-
+    
     P1[0] = P_Max_Delay[0] + 0.001;
     P1[1] = P_Max_Delay[1] * A[3] + 0.001;
     P1[2] = P_Max_Delay[2] * A[3] + 0.002;
     P1[3] = P_Max_Delay[3] * A[3] * A[3] + 0.001;
-
+    
     //增益
     K[0] = (P1[0] * H[0] + P1[2]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
     K[1] = (P1[1] * H[0] + P1[3]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
-
+    
     //后验
     deltU = (real_T)sfmd_V_cellUMax * 0.001 - UL;
     soc_Max_Delay = soc1 + K[0] * deltU;
-
+    
     if (soc_Max_Delay < (real_T)socc_pct_battSocLow * 0.1)
     {
         soc_Max_Delay = (real_T)socc_pct_battSocLow * 0.1;
@@ -262,7 +264,7 @@ void SOC(void)
         soc_Max_Delay = (real_T)socc_pct_battSocUp * 0.1;
     }
     Up_Max_Delay = Up1 + K[1] * deltU;
-
+    
     //P更新
     P_Max_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
     P_Max_Delay[1] = -K[1] * H[0] * P1[0] + P1[1] * (1 - K[1]);
@@ -287,8 +289,10 @@ void SOC(void)
         factor = (uint16_T)(((uint16_T)(((uint32_T)(EKFSOCMin - 200) << 6) / (800 - (EKFSOCMax - EKFSOCMin) - 200)) * 25U) >> 4);
     }
     socd_pct_ekfSoc = (uint16_T)(((1 - (real_T)(factor * 0.01)) * (real_T)(EKFSOCMin * 0.1) + (real_T)(factor * 0.01) * (real_T)(EKFSOCMax * 0.1)) * 10);
+   
+    //printf("4----socd_pct_ekfSoc:%d,EKFSOCMax:%d,EKFSOCMin:%d,\n",socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin);
 
-    //-------------------------EKFavrg---------------------------------------
+   //-------------------------EKFavrg---------------------------------------
     if (FirstRun_SOC)
     {
         soc_Avrg_Delay = (real_T)socn_pct_battSocEE * 0.1;
@@ -299,21 +303,21 @@ void SOC(void)
         P_avrg_Delay[3] = 10;
     }
     //参数查表
-    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) * 0.001;
-    Ro = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])), 12U) * 0.001 * 0.001;
-    Rp = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
-    C = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
+    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])),   12U) * 0.001;
+    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),   12U) * 0.001 * 0.001;
+    Rp  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
+    C   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
     A[3] = exp(-1 / (Rp * C));
-
+    
     B[0] = 1 / Q / 3600 * 100;
     B[1] = Rp * (1 - exp(-1 / (Rp * C)));
-
+    
     H[0] = docvmath(soc_Avrg_Delay);
     H[1] = 1;
-
+    
     //先验
     soc1 = soc_Avrg_Delay * A[0] + B[0] * battcurr;
     Up1 = Up_Avrg_Delay * A[3] + B[1] * battcurr;
@@ -322,15 +326,15 @@ void SOC(void)
     P1[1] = P_avrg_Delay[1] * A[3] + 0.001;
     P1[2] = P_avrg_Delay[2] * A[3] + 0.001;
     P1[3] = P_avrg_Delay[3] * A[3] * A[3] + 0.001;
-
+    
     //增益
     K[0] = (P1[0] * H[0] + P1[2]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
     K[1] = (P1[1] * H[0] + P1[3]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
-
+    
     //后验
     deltU = (real_T)sfmd_V_cellUAvrg * 0.001 - UL;
     soc_Avrg_Delay = soc1 + K[0] * deltU;
-
+    
     if (soc_Avrg_Delay < (real_T)socc_pct_battSocLow * 0.1)
     {
         soc_Avrg_Delay = (real_T)socc_pct_battSocLow * 0.1;
@@ -339,25 +343,25 @@ void SOC(void)
     {
         soc_Avrg_Delay = (real_T)socc_pct_battSocUp * 0.1;
     }
-
+    
     Up_Avrg_Delay = Up1 + K[1] * deltU;
     //P更新
     P_avrg_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
     P_avrg_Delay[1] = -K[1] * H[0] * P1[0] + P1[1] * (1 - K[1]);
     P_avrg_Delay[2] = (1 - K[0] * H[0]) * P1[2] - K[0] * P1[3];
     P_avrg_Delay[3] = -K[1] * H[0] * P1[2] + P1[3] * (1 - K[1]);
-
+    
     //输出
     EKFSOCAvrg = (uint16_T)(soc_Avrg_Delay * 10);
     socn_flg_ekfInvalidAvrg = (deltU > 0.01) || (deltU < -0.01);
     //
-    for (i = 0; i < cmnc_num_cellUNum; i++)
+    for(i = 0;i < cmnc_num_cellUNum;i++)
     {
-        socv_pct_cellSoc[i] = look1_iu16lu16n16tu16_binlcase((look1_iu16lu16n16tu16_binlcase(EKFSOCAvrg, (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) + cdmv_V_deltOCV[i]), (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+        socv_pct_cellSoc[i] = look1_iu16lu16n16tu16_binlcase((look1_iu16lu16n16tu16_binlcase(EKFSOCAvrg, (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) + cdmv_V_deltOCV[i]), (&(cmnm_V_ocv[0])),(&(cmnm_pct_soc[0])),12U);
     }
     //socn_flg_ekfInvalid = socn_flg_ekfInvalidAvrg || cdmd_flg_deltOCVDisable;
-    cellSocMax = ArrMax(&socv_pct_cellSoc[0], cmnc_num_cellUNum);
-    cellSocMin = ArrMin(&socv_pct_cellSoc[0], cmnc_num_cellUNum);
+    cellSocMax = ArrMax(&socv_pct_cellSoc[0],cmnc_num_cellUNum);
+    cellSocMin = ArrMin(&socv_pct_cellSoc[0],cmnc_num_cellUNum);
     if (cellSocMax > 800)
     {
         factor = 100;
@@ -371,8 +375,10 @@ void SOC(void)
         factor = (uint16_T)(((uint16_T)(((uint32_T)(cellSocMin - 200) << 6) / (800 - (cellSocMax - cellSocMin) - 200)) * 25U) >> 4);
     }
     socd_pct_cellBattSoc = (uint16_T)(((1 - (real_T)(factor * 0.01)) * (real_T)(cellSocMin * 0.1) + (real_T)(factor * 0.01) * (real_T)(cellSocMax * 0.1)) * 10);
+    
+ 
+    
 
-    //printf("4----factor:%d,socd_pct_ekfSoc:%d,EKFSOCMax:%d,EKFSOCMin:%d,\n",factor,socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin);
     //======================================================================
     ////////////////////////AhSOC//////////////////////////////////////////
     //======================================================================
@@ -382,7 +388,7 @@ void SOC(void)
     }
     else
     {
-        ahDelay = ahDelay + battcurr / (real_T)(cmnc_Q_ratedCp * 0.1) / 36.0;
+        ahDelay = ahDelay + battcurr / (real_T)(cmnc_Q_ratedCp * 0.1) / 36.0;//cmnc_Q_ratedCp
     }
     ahSoc = (int16_T)(ahDelay * 10);
     if (ahSoc > socc_pct_battSocUp)
@@ -397,6 +403,8 @@ void SOC(void)
     {
         socd_pct_ahSoc = (uint16_T)ahSoc;
     }
+	 //  printf("S_%d   %d   %d   %d   %d   %d   %d   %d\n",socd_pct_cellBattSoc,cellSocMax,cellSocMin,socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin,ahSoc,EKFSOCAvrg);
+	 //  printf("E_%d   %d   %d   %d   %d   %d   %d   %d\n",cdmv_V_deltOCV[0],cdmv_V_deltOCV[1],cdmv_V_deltOCV[15],cdmv_V_deltOCV[16],cdmv_ohm_deltR[0],cdmv_ohm_deltR[1],cdmv_ohm_deltR[15],cdmv_ohm_deltR[16]);
     //printf("5----ahDelay:%f,ahSoc:%d,battcurr:%f,sfmd_I_curr:%d\n",ahDelay,ahSoc,battcurr,sfmd_I_curr);
     //======================================================================
     ///////////////////////estSOC//////////////////////////////////////////
@@ -409,12 +417,12 @@ void SOC(void)
     {
         ekfInvalidCntl = 0;
     }
-
+    
     if (ekfInvalidCntl < 20)
     {
         if (onceFlg_est)
-        {
-            ahSoc0_est = ahSoc;
+        {  
+            ahSoc0_est  = ahSoc;
             ekfSoc0_est = socd_pct_ekfSoc;
             onceFlg_est = false;
         }
@@ -425,7 +433,7 @@ void SOC(void)
         onceFlg_est = true;
         socd_pct_estSoc = socd_pct_ekfSoc;
     }
-
+    
     //
     if (socd_pct_estSoc > socc_pct_battSocUp)
     {
@@ -445,7 +453,9 @@ void SOC(void)
         chrgCntl = (chrgCntl + 1) > 250 ? 250 : (chrgCntl + 1);
         lowCntl = 0;
         lowFlg = false;
-        if (sfmd_V_cellUMax >= look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_chrgCor[0])), (&(socm_V_chrgCor[0])), 2U))
+		//socd_V_chrgCCV = look1_iu16lu16n16tu16_binlcase(socc_pct_chrgCor, (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) + sfmd_I_curr * (look1_iu16lu16n16tu16_binlcase(socc_pct_chrgCor, (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])), 12U) + cdmv_ohm_deltR[sfmd_idx_cellUMax]) * 0.001 * 0.1;
+		socd_V_chrgCCV = look1_is16lu16n16tu16_binlcase(sfmd_I_curr,&socm_I_chrgCor[0],&socm_V_chrgCor[0],2U); 
+		if (sfmd_V_cellUMax >= socd_V_chrgCCV)
         {
             overCntl = (overCntl + 1) > 250 ? 250 : (overCntl + 1);
         }
@@ -470,7 +480,7 @@ void SOC(void)
         {
             fulFlg = 1;
         }
-
+        
         //
         if (overFlg)
         {
@@ -494,7 +504,7 @@ void SOC(void)
         //
         socn_pct_utrackSoc = Soc_Delay + (socTemp > Soc_Delay ? (socTemp - Soc_Delay) : 0);
         Soc_Delay = socn_pct_utrackSoc;
-
+        
         if (fulFlg)
         {
             socn_pct_utrackSoc = socc_pct_battSocUp;
@@ -503,7 +513,7 @@ void SOC(void)
         {
             socn_pct_utrackSoc = socn_pct_utrackSoc > (socc_pct_battSocUp - 1) ? (socc_pct_battSocUp - 1) : socn_pct_utrackSoc;
         }
-
+        
         //printf("7----overCntl:%d,overFlg:%d,fulCntl:%d,fulFlg:%d,ahSoc0_utrckOver:%d,estSoc0_utrckOver:%d,socn_pct_utrackSoc:%d,socTemp:%d\n",overCntl,overFlg,fulCntl,fulFlg,ahSoc0_utrckOver,estSoc0_utrckOver,socn_pct_utrackSoc,socTemp);
     }
     else
@@ -515,7 +525,9 @@ void SOC(void)
         overFlg = false;
         fulFlg = false;
         fulCntl = 0;
-        if (sfmd_V_cellUMin <= look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_disChrgCor[0])), (&(socm_V_disChrgCor[0])), 2U))
+		
+		socd_V_disChrgCCV = look1_iu16lu16n16tu16_binlcase(socc_pct_disChrgCor, (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) + sfmd_I_curr * (look1_iu16lu16n16tu16_binlcase(socc_pct_chrgCor, (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])), 12U) + cdmv_ohm_deltR[sfmd_idx_cellUMin]) * 0.001 * 0.1;
+        if (sfmd_V_cellUMin <= socd_V_disChrgCCV)
         {
             lowCntl = (lowCntl + 1) > 250 ? 250 : (lowCntl + 1);
         }
@@ -549,7 +561,7 @@ void SOC(void)
         }
         // printf("8----lowCntl:%d,lowFlg:%d,ahSoc0_utrckLow:%d,estSoc0_utrckLow:%d,socn_pct_utrackSoc:%d\n",lowCntl,lowFlg,ahSoc0_utrckLow,estSoc0_utrckLow,socn_pct_utrackSoc);
     }
-    //===================================================================
+	//===================================================================
     //------------------EEsave
     //==================================================================
     socd_pct_battSoc = socn_pct_utrackSoc;
@@ -563,11 +575,11 @@ void SOC(void)
     {
         socd_flg_EEsave = 0;
     }
-
-    //=====================================================================
-    //////////////////////////////BCUSOC///////////////////////////////////
-    //=====================================================================
-
+    
+    //===============================================================================================================================================================
+    ////////////////////////////////////////////////////////////////////BCUSOC///////////////////////////////////////////////////////////////////////////////////////
+    //===============================================================================================================================================================
+    
     if (sfmd_I_curr < 10 && sfmd_I_curr > -10)
     {
         statCntl = (statCntl + 1) > 250 ? 250 : (statCntl + 1);
@@ -577,12 +589,12 @@ void SOC(void)
         statCntl = 0;
     }
     statFlg = statCntl > 2;
-
+    
     Flg = (FirstRun_SOC || (ihd_st_chrgSta_Delay == 2 && ihd_st_workStat != 2) || (ihd_st_chrgSta_Delay != 2 && ihd_st_workStat == 2) || ((int16_T)(socn_pct_utrackSoc - socn_pct_utrackSoc_Delay) > 20 || (int16_T)(socn_pct_utrackSoc - socn_pct_utrackSoc_Delay) < -20) || statFlg);
-
+    
     ihd_st_chrgSta_Delay = ihd_st_workStat;
     socn_pct_utrackSoc_Delay = socn_pct_utrackSoc;
-
+    
     //
     if (Flg)
     {
@@ -596,23 +608,23 @@ void SOC(void)
             socd_pct_bcuSoc0 = socd_pct_bcuSoc;
         }
     }
-
+    
     //printf("9----statCntl:%d,statFlg:%d,Flg:%d,socd_pct_bcuSoc0:%d,socd_pct_bcuSoc0:%d,Flg:%d\n",statCntl,statFlg,Flg,socd_pct_bcuSoc0,socd_pct_bcuSoc0,Flg);
     //
     if (ihd_st_workStat == 2)
     {
         delSOC = socd_pct_battSoc0 > socd_pct_bcuSoc0 ? (socd_pct_battSoc0 - socd_pct_bcuSoc0) : (socd_pct_bcuSoc0 - socd_pct_battSoc0);
         coinSoc = (socd_pct_battSoc0 > socd_pct_bcuSoc0 ? socd_pct_battSoc0 : socd_pct_bcuSoc0) + (delSOC > 50 ? 50 : delSOC);
-
+        
         x[0] = socd_pct_battSoc0;
         x[1] = coinSoc > socc_pct_battSocUp ? socc_pct_battSocUp : (uint16_T)coinSoc;
         x[2] = socc_pct_battSocUp;
-
+        
         y[0] = socd_pct_bcuSoc0;
         y[1] = coinSoc > 1000 ? 1000 : (uint16_T)coinSoc;
         y[2] = 1000;
         bcuSoc = SOC_LookUp(socd_pct_battSoc, &x[0], &y[0]);
-
+        
         //
         if (onceFlg_chrg)
         {
@@ -621,7 +633,7 @@ void SOC(void)
             socd_pct_bcuSoc = 2000;
         }
         socd_pct_bcuSoc = SOCfitSystem(bcuSoc, &socd_pct_bcuSoc, 1);
-
+        
         //
         if (fulFlg)
         {
@@ -638,7 +650,7 @@ void SOC(void)
         //
         delSOC = socd_pct_battSoc0 > socd_pct_bcuSoc0 ? (socd_pct_battSoc0 - socd_pct_bcuSoc0) : (socd_pct_bcuSoc0 - socd_pct_battSoc0);
         coinSoc = (int16_T)((socd_pct_battSoc0 < socd_pct_bcuSoc0 ? socd_pct_battSoc0 : socd_pct_bcuSoc0) - (delSOC > 50 ? 50 : delSOC));
-
+        
         x[0] = socc_pct_battSocLow;
         x[1] = coinSoc > socc_pct_battSocLow ? (uint16_T)coinSoc : socc_pct_battSocLow;
         x[2] = socd_pct_battSoc0;
@@ -646,7 +658,7 @@ void SOC(void)
         y[1] = coinSoc > 0 ? (uint16_T)coinSoc : 0;
         y[2] = socd_pct_bcuSoc0;
         bcuSoc = SOC_LookUp(socd_pct_battSoc, &x[0], &y[0]);
-
+        
         //
         if (onceFlg_dischrg)
         {
@@ -654,14 +666,13 @@ void SOC(void)
             onceFlg_dischrg = false;
             socd_pct_bcuSoc = 2000;
         }
-
+        
         socd_pct_bcuSoc = SOCfitSystem(bcuSoc, &socd_pct_bcuSoc, 1);
         //printf("11-----x:[%d-%d-%d],y:[%d-%d-%d],bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],bcuSoc,socd_pct_bcuSoc);
     }
     //
     socd_pct_bcuSocEo = socd_pct_bcuSoc;
     FirstRun_SOC = false;
-
     //printf("\n");
 }
 
@@ -670,13 +681,13 @@ real_T docvmath(real_T soc)
 {
     real_T docv;
     docv = ((((((-1.0936E-13 * pow(soc, 7.0) +
-                 3.9249E-11 * pow(soc, 6.0)) +
-                -5.5776E-9 * pow(soc, 5.0)) +
-               3.996E-7 * pow(soc, 4.0)) +
-              -1.5332E-5 * pow(soc, 3.0)) +
-             soc * soc * 0.0003192) +
+            3.9249E-11 * pow(soc, 6.0)) +
+            -5.5776E-9 * pow(soc, 5.0)) +
+            3.996E-7 * pow(soc, 4.0)) +
+            -1.5332E-5 * pow(soc, 3.0)) +
+            soc * soc * 0.0003192) +
             -0.00371 * soc) +
-           0.02732;
+            0.02732;
     return docv;
 }
 ////
@@ -695,7 +706,7 @@ uint16_T SOC_LookUp(uint16_T battsoc, uint16_T x[3], uint16_T y[3])
     //
     if (battsoc > x[0] && battsoc < x[1]) //(x-x0)*(y1-y0)/(x1-x0)+y0
     {
-
+        
         bcusoc = (uint16_T)((real_T)((battsoc - x[0]) * 0.1) * (real_T)((y[1] - y[0]) * 0.1) / (real_T)((x[1] - x[0]) * 0.1) * 10) + y[0];
     }
     //
@@ -723,6 +734,6 @@ uint16_T SOCfitSystem(uint16_T SOC, uint16_T *SOCfit, uint16_T m)
     {
         *SOCfit = SOC;
     }
-
+    
     return *SOCfit;
 }

+ 3 - 3
src/EmbeddedCoder_src/SPM.c

@@ -36,10 +36,10 @@ void SPM(void)
   //调用SOX算法
   SOH();
   BLC();
-  if (!ihd_flg_urtRecFlt || sfmd_V_cellUMax == 0)
+  if (ihd_flg_urtRecFlg)
   {
-      SOC();
-	  CDM();
+      CDM();
+	  SOC();
   }
   // 循环发送数组
   cand_Q_cellCap = sohv_Q_cellCapArrEo[cand_Nr_cellNr-1];

Some files were not shown because too many files changed in this diff