LAPTOP-EG88H5BE\86151 3 gadi atpakaļ
vecāks
revīzija
ab06e6b63f

+ 17 - 4
inc/EmbeddedCoder_inc/BCUDisp.h

@@ -5,6 +5,19 @@
 extern uint16_T appv_V_cellU[cmnc_num_cellUNumMax];                        /* 静态电压 */
 extern uint8_T appd_st_preCyc;
 
+extern boolean_T  spmd_flg_firstRun;
+extern boolean_T  socd_flg_firstRun;
+extern boolean_T  sohd_flg_firstRun;
+extern boolean_T  blcd_flg_firstRun;
+extern boolean_T  sord_flg_firstRun;
+extern boolean_T  soed_flg_firstRun;
+extern boolean_T  iscd_flg_firstRun;
+extern boolean_T  pimd_flg_firstRun;
+extern boolean_T  sfmd_flg_firstRun;
+extern boolean_T  tmsd_flg_firstRun;
+extern boolean_T  cdmd_flg_firstRun;
+extern boolean_T  cmd_flg_firstRun;
+
 extern uint16_T blcv_Q_reqCpEi[cmnc_num_cellUNumMax];                      /*均衡需求容量 读取量(数组); */
 extern uint16_T blcv_Q_reqCpEo[cmnc_num_cellUNumMax];                      /*均衡需求容量 写入量(数组); */
 extern uint32_T blcv_Q_totalCpEi[cmnc_num_cellUNumMax];                    /*累计均衡容量 读取量(数组); */
@@ -138,11 +151,11 @@ extern uint8_T cmd_st_chrgSt;                            /* 充电状态  */
 extern int16_T cmd_I_chrgCurrReq;                       /* 充电需求电流  */
 extern uint8_T cmd_idx_chrgEndReason;                    /* 充电结束原因  */
 
-extern uint16_T cand_Nr_cellNr;                          /*循环发送的单体编号; */
+extern uint16_T cand_idx_cellNr;                          /*循环发送的单体编号; */
 extern uint16_T cand_Q_cellCap;                          /*循环发送的单体容量; */
 extern uint16_T cand_V_chrgStartStat;                    /*循环发送的充电前单体电压; */
-extern uint16_T cand_Q_reqCp;                            /*循环发送的单体需求均衡容量; */
-extern uint16_T cand_Q_totalCp;                          /*循环发送的单体累计均衡容量; */
+extern uint16_T cand_Q_blcReqCp;                            /*循环发送的单体需求均衡容量; */
+extern uint16_T cand_Q_blcTotalCp;                          /*循环发送的单体累计均衡容量; */
 
 extern int16_T  cdmv_V_deltOCV[cmnc_num_cellUNumMax];
 extern int16_T  cdmv_ohm_deltR[cmnc_num_cellUNumMax];
@@ -158,4 +171,4 @@ extern uint16_T test_countEn;
 
 
 
-
+


+ 1 - 1
inc/EmbeddedCoder_inc/BLC.h

@@ -2,6 +2,6 @@
 #include "BCUCal.h"
 #include "BCUDisp.h"
 #include "funlib.h"
-extern boolean_T FirstRun_BLC;
+
 extern void BLC_Init(void);
 extern void BLC(void);

+ 0 - 2
inc/EmbeddedCoder_inc/CDM.h

@@ -3,8 +3,6 @@
 #include "BCUDisp.h"
 #include "funlib.h"
 
-extern boolean_T FirstRun_CDM;
-
 extern void CDM_Init(void);
 extern void CDM(void);
 

+ 0 - 1
inc/EmbeddedCoder_inc/CM.h

@@ -4,7 +4,6 @@
 #include "numeric.h"
 #include "funlib.h"
 
-extern boolean_T FirstRun_CM;
 extern void CM_Init(void);
 extern void CM(void);
 

+ 1 - 1
inc/EmbeddedCoder_inc/ISC.h

@@ -2,7 +2,7 @@
 #include "BCUCal.h"
 #include "BCUDisp.h"
 #include "funlib.h"
-extern boolean_T FirstRun_ISC;
+
 extern void ISC_Init(void);
 extern void ISC(void);
 

+ 0 - 2
inc/EmbeddedCoder_inc/PIM.h

@@ -4,8 +4,6 @@
 #include "BCUDisp.h"
 #include "funlib.h"
 
-extern boolean_T FirstRun_PIM;
-
 extern void PIM_Init(void);
 extern void PIM(void);
 

+ 0 - 2
inc/EmbeddedCoder_inc/SFM.h

@@ -4,8 +4,6 @@
 #include <math.h>
 #include "funlib.h"
 
-extern boolean_T FirstRun_SFM;
-
 extern void SFM_Init(void);
 extern void SFM(void);
 

+ 1 - 3
inc/EmbeddedCoder_inc/SOC.h

@@ -5,11 +5,9 @@
 #include "BCUDisp.h"
 #include "funlib.h"
 
-extern boolean_T FirstRun_SOC;
 extern void SOC_Init(void);
 extern void SOC(void);
 //
 extern real_T docvmath(real_T soc );
-extern uint16_T SOC_LookUp(uint16_T battsoc, uint16_T x[3], uint16_T y[3]);
-extern uint16_T SOCfitSystem(uint16_T SOC,uint16_T *SOCfit, uint16_T m);
+
 

+ 0 - 1
inc/EmbeddedCoder_inc/SOE.h

@@ -2,7 +2,6 @@
 #include "BCUDisp.h"
 #include "funlib.h"
 
-extern boolean_T FirstRun_SOE;
 extern void SOE_Init(void);
 extern void SOE(void);
 

+ 0 - 1
inc/EmbeddedCoder_inc/SOH.h

@@ -2,7 +2,6 @@
 #include "BCUDisp.h"
 #include "funlib.h"
 
-extern boolean_T FirstRun_SOH;
 extern void SOH_Init(void);
 extern void SOH(void);
 //

+ 1 - 3
inc/EmbeddedCoder_inc/SOR.h

@@ -1,8 +1,6 @@
 #include "BCUCal.h"
 #include "BCUDisp.h"
-
-
-extern boolean_T FirstRun_SOR;
+#include "funlib.h"
 extern void SOR_Init(void);
 extern void SOR(void);
 

+ 1 - 4
inc/EmbeddedCoder_inc/SPM.h

@@ -7,10 +7,7 @@
 #include "CDM.h"
 #include "SOE.h"
 #include "SOR.h"
-
-
-
-extern boolean_T FirstRun_SPM;
+#include "PIM.h"
 
 extern void SPM_Init(void);
 extern void SPM(void);

+ 2 - 2
src/AppTaskTcp.c

@@ -581,9 +581,9 @@ static void TcpDataInfoAssembleSend()
                                 %d,%d,%d,%d,%d,,\
                                 %d,%d,%d,%d,%d,,\
                                 %d,%d,%d,%d",
-                    socd_pct_ahSoc, socd_pct_ekfSoc, socd_pct_battSoc, socd_pct_vcuSoc, socd_pct_cellBattSoc, sohv_Q_packCapArrEo[9], cdmv_ohm_deltR[cand_Nr_cellNr - 1],
+                    socd_pct_ahSoc, socd_pct_ekfSoc, socd_pct_battSoc, socd_pct_vcuSoc, socd_pct_cellBattSoc, sohv_Q_packCapArrEo[9], cdmv_ohm_deltR[cand_idx_cellNr - 1],
                     sfmd_I_curr, maxCellVol, minCellVol, sfmd_V_cellUAvrg, sfmv_V_cellU[0],
-                    cand_Nr_cellNr, cand_Q_cellCap, cand_V_chrgStartStat, ihd_tm_parkTime, sohd_Q_chrgEo,
+                    cand_idx_cellNr, cand_Q_cellCap, cand_V_chrgStartStat, ihd_tm_parkTime, sohd_Q_chrgEo,
                     pimd_V_ocv, pimd_R_ohm, pimd_R_polar, pimd_F_polar);
         }
         Debugcounter++;

+ 15 - 3
src/EmbeddedCoder_src/BCUDisp.c

@@ -4,6 +4,18 @@
 
 uint16_T appv_V_cellU[cmnc_num_cellUNumMax];
 uint8_T appd_st_preCyc;
+boolean_T  spmd_flg_firstRun;
+boolean_T  socd_flg_firstRun;
+boolean_T  sohd_flg_firstRun;
+boolean_T  blcd_flg_firstRun;
+boolean_T  sord_flg_firstRun;
+boolean_T  soed_flg_firstRun;
+boolean_T  iscd_flg_firstRun;
+boolean_T  pimd_flg_firstRun;
+boolean_T  sfmd_flg_firstRun;
+boolean_T  tmsd_flg_firstRun;
+boolean_T  cdmd_flg_firstRun;
+boolean_T  cmd_flg_firstRun;
 
 uint16_T blcv_Q_reqCpEi[cmnc_num_cellUNumMax];                      /*均衡需求容量 读取量(数组); */
 uint16_T blcv_Q_reqCpEo[cmnc_num_cellUNumMax];                      /*均衡需求容量 写入量(数组); */
@@ -139,11 +151,11 @@ uint8_T cmd_st_chrgSt;                           /* 充电状态  */
 int16_T cmd_I_chrgCurrReq;                       /* 充电需求电流  */
 uint8_T cmd_idx_chrgEndReason;                    /* 充电结束原因  */
         
-uint16_T cand_Nr_cellNr;                          /*循环发送的单体编号; */
+uint16_T cand_idx_cellNr;                          /*循环发送的单体编号; */
 uint16_T cand_Q_cellCap;                          /*循环发送的单体容量; */
 uint16_T cand_V_chrgStartStat;                    /*循环发送的充电前单体电压; */
-uint16_T cand_Q_reqCp;                            /*循环发送的单体需求均衡容量; */
-uint16_T cand_Q_totalCp;                          /*循环发送的单体累计均衡容量; */
+uint16_T cand_Q_blcReqCp;                            /*循环发送的单体需求均衡容量; */
+uint16_T cand_Q_blcTotalCp;                          /*循环发送的单体累计均衡容量; */
 
 int16_T  cdmv_V_deltOCV[cmnc_num_cellUNumMax] = {0};
 int16_T  cdmv_ohm_deltR[cmnc_num_cellUNumMax] = {0};

+ 12 - 19
src/EmbeddedCoder_src/BLC.c

@@ -1,10 +1,9 @@
 #include "BLC.h"
 
-boolean_T FirstRun_BLC;
 ////////////////////////////////////////////////////////////////////////////
 void BLC_Init(void)
 {
-    FirstRun_BLC = true;
+    blcd_flg_firstRun = true;
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -13,7 +12,6 @@ void BLC(void)
     uint16_T i;
     static uint16_T blcn_Q_reqCpEE[cmnc_num_cellUNumMax];
     static uint32_T blcn_Q_totalCpEE[cmnc_num_cellUNumMax];
-    uint16_T MaxCp;
     
     static boolean_T blcn_flg_judge;
     boolean_T blcn_flg_enable;
@@ -32,30 +30,25 @@ void BLC(void)
     static real_T temp[cmnc_num_cellUNumMax];
     uint16_T blcn_Q_impleCp[cmnc_num_cellUNumMax];
 
-	if(FirstRun_BLC)
+	if(blcd_flg_firstRun)
 	{
-	   for (i = 0; i < cmnc_num_cellUNum; i++)
-	   {
-	       temp[i] = 0;
-           blcn_Q_reqCpEo_Delay[i] = 0;
-	       blcn_Q_reqCpNow[i] = 0;
-	  }
+	  memset(blcn_Q_reqCpEo_Delay,0,sizeof(blcn_Q_reqCpEo_Delay));
+	  memset(temp,0,sizeof(temp)); 
 	}
     //=========================================================================
     //---------------------------------EE校验----------------------------------
     //=========================================================================
     
-    if(FirstRun_BLC)
+    if(blcd_flg_firstRun)
     {
-        MaxCp = ArrMax(&blcv_Q_reqCpEi[0], cmnc_num_cellUNum);
-        if(MaxCp > cmnc_Q_ratedCp * 100)
+        if(ArrMax(blcv_Q_reqCpEi, cmnc_num_cellUNum) > cmnc_Q_ratedCp)
         {
-            memset(blcn_Q_reqCpEE,0, sizeof(blcn_Q_reqCpEE));
+            memset(blcn_Q_reqCpEE,  0, sizeof(blcn_Q_reqCpEE));
             memset(blcn_Q_totalCpEE,0, sizeof(blcn_Q_totalCpEE));
         }
         else
         {
-            memcpy(blcn_Q_reqCpEE,blcv_Q_reqCpEi, sizeof(blcv_Q_reqCpEi));
+            memcpy(blcn_Q_reqCpEE,  blcv_Q_reqCpEi, sizeof(blcv_Q_reqCpEi));
             memcpy(blcn_Q_totalCpEE,blcv_Q_totalCpEi, sizeof(blcn_Q_totalCpEE));
         }	
     }
@@ -63,7 +56,7 @@ void BLC(void)
     //=========================================================================
     //---------------------------------使能判断--------------------------------
     //=========================================================================
-    if(FirstRun_BLC)
+    if(blcd_flg_firstRun)
     {
 		blcn_flg_judge	= (ihd_tm_parkTime >= cmnc_tm_parkTime)&& !sfmd_flg_cellUDisable && (sfmd_I_curr > -10 && sfmd_I_curr < 10);
     }
@@ -72,7 +65,7 @@ void BLC(void)
     //=========================================================================
     //---------------------------------需求计算--------------------------------
     //=========================================================================
-    if(FirstRun_BLC)
+    if(blcd_flg_firstRun)
     {
         //压差法
         if(blcn_flg_judge)
@@ -166,11 +159,11 @@ void BLC(void)
         }
 
 		blcn_Q_impleCp[i] = (uint16_T) (temp[i] /3600 * 1000);
-        blcv_Q_reqCpEo[i] = ( (int16_T)(blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]) < 0 ? 0 :blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]);
+        blcv_Q_reqCpEo[i] = ((int16_T)(blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]) < 0 ? 0 :blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]);
         blcv_Q_totalCpEo[i] = (uint32_T) (blcn_Q_totalCpEE[i] + blcn_Q_impleCp[i]);  
     }
     //
-    FirstRun_BLC = false;
+    blcd_flg_firstRun = false;
     memcpy(blcn_Q_reqCpEo_Delay,blcv_Q_reqCpEo, sizeof(blcn_Q_reqCpEE));
 
 }

+ 11 - 13
src/EmbeddedCoder_src/CDM.c

@@ -1,10 +1,8 @@
 #include "CDM.h"
 
-static boolean_T FirstRun_CDM;
-
 void CDM_Init(void)
 {
-    FirstRun_CDM = true;
+    cdmd_flg_firstRun = true;
 }
 
 void CDM(void)
@@ -22,16 +20,16 @@ void CDM(void)
     real_T arf[cmnc_num_cellUNumMax];
     uint16_T i;
     static uint8_T cmdn_st_workStat_Delay;
-    static uint8_T cdmn_N_Cnt;
+    static uint8_T cdmn_num_Cnt;
 
     //
     if (cmdn_st_workStat_Delay != 1 && ihd_st_workStat == 1)
     {
-        FirstRun_CDM = true;
+        cdmd_flg_firstRun = true;
     }
     
     //
-    if (FirstRun_CDM)
+    if (cdmd_flg_firstRun)
     {
         for (i = 0; i < cmnc_num_cellUNum; i++)
         {
@@ -44,7 +42,7 @@ void CDM(void)
             deltaR[i] = 0;
             deltaES[i] = 0;
             deltaRS[i] = 0;
-            cdmn_N_Cnt = 0;
+            cdmn_num_Cnt = 0;
         }
     }
     //
@@ -79,23 +77,23 @@ void CDM(void)
             }
         }
         //
-        cdmn_N_Cnt = cdmn_N_Cnt + 1;
+        cdmn_num_Cnt = cdmn_num_Cnt + 1;
         for (i = 0; i < cmnc_num_cellUNum; i++)
         {
             deltaES[i] = deltaES[i] + deltaE[i];
             deltaRS[i] = deltaRS[i] + deltaR[i];
         }
 
-        if (cdmn_N_Cnt >= 10)
+        if (cdmn_num_Cnt >= 10)
         {
             for (i = 0; i < cmnc_num_cellUNum; i++)
             {
-                cdmv_V_deltOCV[i] = (int16_T)(deltaES[i] / cdmn_N_Cnt * 1000);
-                cdmv_ohm_deltR[i] = (int16_T)(deltaRS[i] / cdmn_N_Cnt * 1000 * 1000);
+                cdmv_V_deltOCV[i] = (int16_T)(deltaES[i] / cdmn_num_Cnt * 1000);
+                cdmv_ohm_deltR[i] = (int16_T)(deltaRS[i] / cdmn_num_Cnt * 1000 * 1000);
                 deltaES[i] = 0;
                 deltaRS[i] = 0;
             }
-            cdmn_N_Cnt = 0;
+            cdmn_num_Cnt = 0;
         }
     }
     else
@@ -105,7 +103,7 @@ void CDM(void)
 		memset(cdmv_ohm_deltR,0,sizeof(cdmv_ohm_deltR));
     }
 	
-    FirstRun_CDM = false;
+    cdmd_flg_firstRun = false;
 	cmdn_st_workStat_Delay = ihd_st_workStat;
 }
 

+ 4 - 6
src/EmbeddedCoder_src/CM.c

@@ -1,9 +1,9 @@
 #include "CM.h"
 
-boolean_T FirstRun_CM;
+
 void CM_Init(void)
 {
-    FirstRun_CM = true;
+    cmd_flg_firstRun = true;
 }
 
 void CM(void)
@@ -21,7 +21,7 @@ void CM(void)
 	static boolean_T First;
     static uint8_T cmd_st_chrgSt_end;
 	static boolean_T chrgFul;
-    if(FirstRun_CM)
+    if(cmd_flg_firstRun)
     {
         cmn_V_cellUMax = 0;
         cmn_V_cellUMin = 0;
@@ -137,8 +137,6 @@ void CM(void)
             cmd_idx_chrgEndReason = 2 ; // 因电池故障限制充电;
         }
 
-
-		
         First = false;
     }
     else
@@ -147,7 +145,7 @@ void CM(void)
         cmd_idx_chrgEndReason = 0;
     }
 
-    FirstRun_CM = false;
+    cmd_flg_firstRun = false;
 	//printf("fltAct:%d,chrgMod:%d,chrgSt:%d,chrgCurrReq:%d,chrgEndReason:%d\n\n",sfmd_st_fltAct,cmd_st_chrgMod,cmd_st_chrgSt,cmd_I_chrgCurrReq,cmd_idx_chrgEndReason);
 }
 

+ 12 - 16
src/EmbeddedCoder_src/ISC.c

@@ -1,11 +1,8 @@
 #include "ISC.h"
 
-
-boolean_T FirstRun_ISC;
-
 void ISC_Init(void)
 {
-    FirstRun_ISC = true;
+    iscd_flg_firstRun = true;
 }
 //-------------------------------------------------------------------------
 
@@ -23,10 +20,10 @@ void ISC(void)
     static boolean_T iscd_flg_disChrgFlt;
     static uint16_T TimeCtn;
     static uint16_T RunCtn;
-    static uint16_T iscn_N_fltNr[cmnc_num_cellUNumMax];
+    static uint16_T iscn_num_fltNr[cmnc_num_cellUNumMax];
     static boolean_T iscd_flg_fulStat;
     //初值
-    if(FirstRun_ISC)
+    if(iscd_flg_firstRun)
     {
         iscd_flg_timedWakeUpFlt = false;
         iscd_flg_disChrgFlt = false;
@@ -35,7 +32,7 @@ void ISC(void)
 		memset(iscn_pct_cellSoc2,0, sizeof(iscn_pct_cellSoc2));
 		memset(iscn_Q_cellAh,0, sizeof(iscn_Q_cellAh));
 		memset(iscn_Q_deltAh,0, sizeof(iscn_Q_deltAh));
-        memset(iscn_N_fltNr,0, sizeof(iscn_N_fltNr));
+        memset(iscn_num_fltNr,0, sizeof(iscn_num_fltNr));
         TimeCtn = 0;
         RunCtn = 0;
     }
@@ -43,7 +40,7 @@ void ISC(void)
     //================高端SOC点诊断=================================== 0.1A
     //=====================================================================
     RunCtn = (RunCtn + 1) > 60000 ? 60000 : (RunCtn + 1);
-    if(FirstRun_ISC)
+    if(iscd_flg_firstRun)
     {
         //
         if(ArrMax(iscv_Q_remainCpEi,cmnc_num_cellUNum) > cmnc_Q_ratedCp)
@@ -89,7 +86,7 @@ void ISC(void)
     //=====================================================================
     //================定时唤醒诊断======================================1A
     //=====================================================================
-    if(appd_st_preCyc == 1 && ihd_tm_parkTime >= cmnc_tm_parkTime && sfmd_I_curr < 10 && sfmd_I_curr > -10 && FirstRun_ISC)
+    if(appd_st_preCyc == 1 && ihd_tm_parkTime >= cmnc_tm_parkTime && sfmd_I_curr < 10 && sfmd_I_curr > -10 && iscd_flg_firstRun)
     {
         for (i = 0; i < cmnc_num_cellUNum;i++)
         {
@@ -117,8 +114,7 @@ void ISC(void)
         TimeCtn = TimeCtn + 1;
         for (i = 0; i < cmnc_num_cellUNum;i++)
         {
-            //Ah[i] =(int16_T)((uint16_T)((uint32_T) socv_pct_cellSoc[i]  * sohv_Q_cellCap[i] / 2000U) << 1);
-            iscn_Q_cellAh[i]=(uint16_T) ((real_T)( socv_pct_cellSoc[i] * 0.1) * (real_T)( sohv_Q_cellCap[i] * 0.1)/100 * 100);
+            iscn_Q_cellAh[i] = (uint16_T)((uint32_T)(socv_pct_cellSoc[i] * sohv_Q_cellCap[i])/1000);
         }
         if (TimeCtn == 60)
         {
@@ -132,15 +128,15 @@ void ISC(void)
             }
             for (i = 0; i < cmnc_num_cellUNum;i++)
             {
-                if((real_T)(ArrMean(iscn_Q_deltAh,cmnc_num_cellUNum) -  iscn_Q_deltAh[i]) * 0.01/(TimeCtn - 60) * 3600 > 2 )
+                if((real_T)(ArrMean(iscn_Q_deltAh,cmnc_num_cellUNum) -  iscn_Q_deltAh[i]) * 0.1/(TimeCtn - 60) * 3600 > 2 )
                 {
-                    iscn_N_fltNr[i] =  (iscn_N_fltNr[i] + 1) > 60000 ? 60000 : (iscn_N_fltNr[i] + 1);
+                    iscn_num_fltNr[i] =  (iscn_num_fltNr[i] + 1) > 60000 ? 60000 : (iscn_num_fltNr[i] + 1);
                 }
                 else
                 {
-                    iscn_N_fltNr[i] = 0;
+                    iscn_num_fltNr[i] = 0;
                 }
-                if (iscn_N_fltNr[i] > 600)
+                if (iscn_num_fltNr[i] > 600)
                 {
                     iscd_flg_disChrgFlt = true;
                 }
@@ -159,7 +155,7 @@ void ISC(void)
     /////
     iscd_flg_flt = iscd_flg_disChrgFlt||iscd_flg_timedWakeUpFlt ||iscd_flg_fulStat;
 
-	FirstRun_ISC = false;
+	iscd_flg_firstRun = false;
 }
 
 

+ 5 - 6
src/EmbeddedCoder_src/PIM.c

@@ -1,11 +1,10 @@
 #include "PIM.h"
 
-static boolean_T FirstRun_PIM;
 #define pimd_L_rls 51
 
 void PIM_Init(void)
 {
-    FirstRun_PIM = true;
+    pimd_flg_firstRun = true;
 }
 
 void PIM(void)
@@ -32,11 +31,11 @@ void PIM(void)
     //重置
     if (pimn_st_workStat_Delay != 1 && ihd_st_workStat == 1)
     {
-        FirstRun_PIM = true;
+        pimd_flg_firstRun = true;
     }
     
     //初值
-    if (FirstRun_PIM)
+    if (pimd_flg_firstRun)
     {
         pimn_M_P[0][0] = 10; pimn_M_P[0][1] =  0;  pimn_M_P[0][2] =  0;  pimn_M_P[0][3] =  0;
         pimn_M_P[1][0] =  0; pimn_M_P[1][1] = 10;  pimn_M_P[1][2] =  0;  pimn_M_P[1][3] =  0;
@@ -52,7 +51,7 @@ void PIM(void)
     }
 
     //限定记忆长度
-    if (FirstRun_PIM)
+    if (pimd_flg_firstRun)
     {
         for (i = 0; i < pimd_L_rls; i++)
         {
@@ -179,7 +178,7 @@ void PIM(void)
 
     //
     pimn_st_workStat_Delay = ihd_st_workStat;
-    FirstRun_PIM = false; 
+    pimd_flg_firstRun = false; 
 }
 
 

+ 12 - 14
src/EmbeddedCoder_src/SFM.c

@@ -1,12 +1,11 @@
 #include "SFM.h"
 
-boolean_T FirstRun_SFM;
 DiagThrstruct DiagThr;
 DiagTimestruct DiagTime;
 
 void SFM_Init(void)
 {
-    FirstRun_SFM = true;
+    sfmd_flg_firstRun = true;
 }
 
 void SFM(void)
@@ -161,11 +160,11 @@ void SFM(void)
 
     if (ihd_flg_urtRecFlt_Delay)
     {
-        FirstRun_SFM = true;
+        sfmd_flg_firstRun = true;
     }
     ihd_flg_urtRecFlt_Delay = ihd_flg_urtRecFlt;
     //初值
-    if (FirstRun_SFM)
+    if (sfmd_flg_firstRun)
     {
 
         memset(&DiagThr, 0, sizeof(DiagThr));
@@ -294,7 +293,7 @@ void SFM(void)
     {
         Cntl = 0;
         // 矩阵更新
-        for (j = 0; j < 4 && FirstRun_SFM; j++)
+        for (j = 0; j < 4 && sfmd_flg_firstRun; j++)
         {
             for (i = 0; i < cmnc_num_cellUNum; i++)
             {
@@ -385,7 +384,6 @@ void SFM(void)
         }
         else
         {
-            // sfmd_V_cellUAvrg = SumU / UNum;
             sfmd_V_cellUAvrg = (SumU - sfmd_V_cellUMax - sfmd_V_cellUMin) / (UNum - 2);
         }
 
@@ -467,7 +465,7 @@ void SFM(void)
 
     // 61 模组温度合理性故障
     sfmd_flg_modTRationFlt = false;
-    for (i = 0; i < cmnc_num_modTNum && FirstRun_SFM; i++)
+    for (i = 0; i < cmnc_num_modTNum && sfmd_flg_firstRun; i++)
     {
         modTArr[i] = ihv_T_modT[i];
     }
@@ -701,9 +699,9 @@ void SFM(void)
     sfmd_flg_disChrgMosTOverMisFlt = JudgeTimeSystem(!sfmd_flg_interComFlt, sfmd_flg_disChrgMosTOverFlt2 != ihd_flg_disChrgMosTOverFlt, &DiagTime.N162, 2);
 
     // 163 soc不匹配
-    sfmd_flg_socMisFlt = 0 && !FirstRun_SFM && (!sfmd_flg_interComFlt) && ((int16_T)(socd_pct_vcuSoc - ihd_pct_soc) > 100 || (int16_T)(socd_pct_vcuSoc - ihd_pct_soc) < -100);
+    sfmd_flg_socMisFlt = 0 && !sfmd_flg_firstRun && (!sfmd_flg_interComFlt) && ((int16_T)(socd_pct_vcuSoc - ihd_pct_soc) > 100 || (int16_T)(socd_pct_vcuSoc - ihd_pct_soc) < -100);
     // 164 SOH 不匹配
-    sfmd_flg_sohMisFlt = !FirstRun_SFM && (!sfmd_flg_interComFlt) && ((int16_T)(sohd_pct_bcuSoh - ihd_pct_soh) > 50 || (int16_T)(sohd_pct_bcuSoh - ihd_pct_soh) < -50);
+    sfmd_flg_sohMisFlt = !sfmd_flg_firstRun && (!sfmd_flg_interComFlt) && ((int16_T)(sohd_pct_bcuSoh - ihd_pct_soh) > 50 || (int16_T)(sohd_pct_bcuSoh - ihd_pct_soh) < -50);
 
     // 178
     sfmd_flg_deltRFlt = false;
@@ -782,7 +780,7 @@ void SFM(void)
     if (CntA >= 0)
     {
         CntA = 0;
-        for (j = 0; j < 4 && FirstRun_SFM; j++)
+        for (j = 0; j < 4 && sfmd_flg_firstRun; j++)
         {
             for (i = 0; i < cmnc_num_modTNum; i++)
             {
@@ -844,7 +842,7 @@ void SFM(void)
     ////32 加热回路常闭故障
     if (!sfmd_flg_modTAllFlt)
     {
-        if (FirstRun_SFM)
+        if (sfmd_flg_firstRun)
         {
             for (i = 0; i < 10; i++)
             {
@@ -869,7 +867,7 @@ void SFM(void)
 
     if (!sfmd_flg_heatPanT1OpenFlt && !sfmd_flg_heatPanT1RationFlt && (int16_T)(ihd_T_heatPanT1 - ihd_T_heatPanT1_Delay1) > -10 && (int16_T)(ihd_T_heatPanT1 - ihd_T_heatPanT1_Delay1) < 20)
     {
-        if (FirstRun_SFM)
+        if (sfmd_flg_firstRun)
         {
             for (i = 0; i < 10; i++)
             {
@@ -895,7 +893,7 @@ void SFM(void)
 
     if (!sfmd_flg_heatPanT2OpenFlt && !sfmd_flg_heatPanT2RationFlt && (int16_T)(ihd_T_heatPanT2 - ihd_T_heatPanT2_Delay1) > -10 && (int16_T)(ihd_T_heatPanT2 - ihd_T_heatPanT2_Delay1) < 20)
     {
-        if (FirstRun_SFM)
+        if (sfmd_flg_firstRun)
         {
             for (i = 0; i < 10; i++)
             {
@@ -1754,7 +1752,7 @@ void SFM(void)
     sfmd_flg_cellUDisable = sfmd_flg_interComFlt || sfmd_flg_volFlt;
     sfmd_flg_currDisable = sfmd_flg_interComFlt || sfmd_flg_currOpenFlt;
     sfmd_flg_modTDisable = sfmd_flg_interComFlt || sfmd_flg_modTOpenFlt || sfmd_flg_modTRationFlt;
-    FirstRun_SFM = false;
+    sfmd_flg_firstRun = false;
 }
 
 //===============================================================================

+ 84 - 149
src/EmbeddedCoder_src/SOC.c

@@ -1,11 +1,9 @@
 #include "SOC.h"
 
-boolean_T FirstRun_SOC;
-
 //---------------SOC初始化-----------------------------------------------
 void SOC_Init(void)
 {
-    FirstRun_SOC = true;
+    socd_flg_firstRun = true;
 }
 
 
@@ -17,7 +15,6 @@ void SOC(void)
     static uint16_T socn_pct_battSocEE;
     static uint16_T socn_pct_bcuSocEE;
     static uint16_T socn_Q_cap;
-	//static int16_T socn_ohm_cellRAvrg;
     //
     real_T Q;
     real_T battcurr;
@@ -58,38 +55,36 @@ void SOC(void)
     static real_T ahDelay;
     int16_T ahSoc;
     //
+    boolean_T socn_flg_ekfDisable;
     static uint16_T  ekfInvalidCntl;
     static boolean_T onceFlg_est;
     static int16_T   ahSoc0_est;
     static uint16_T  ekfSoc0_est;
     // 
-    uint16_T socd_V_chrgCCV;
-	uint16_T socd_V_disChrgCCV;
+    uint16_T socn_V_chrgCCV;
+	uint16_T socn_V_disChrgCCV;
     static boolean_T overFlg;
     static boolean_T fulFlg;
-    static uint8_T overCntl;
-    static uint8_T fulCntl;
+    static uint16_T overCntl;
+    static uint16_T fulCntl;
     static boolean_T onceFlg_utrckOver;
     static int16_T   ahSoc0_utrckOver;
     static uint16_T  estSoc0_utrckOver;
     static uint16_T Soc_Delay;
     static boolean_T lowFlg;
-    static uint8_T lowCntl;
+    static uint16_T lowCntl;
     static boolean_T onceFlg_utrckLow;
     static int16_T ahSoc0_utrckLow;
     static uint16_T estSoc0_utrckLow;
     uint16_T socn_pct_utrackSoc;
     uint16_T socTemp;
-    static uint8_T chrgCntl;
-    static uint8_T disChrgCntl;
     //
     //
-    static uint8_T statCntl;
-    boolean_T statFlg;
-    static uint8_T ihd_st_chrgSta_Delay;
-    static uint16_T socd_pct_battSoc_Delay;
-    static uint16_T socd_pct_battSoc0;
-    static uint16_T socd_pct_bcuSoc0;
+    static uint16_T statCntl;
+    static uint8_T  socn_st_workStat_Delay;
+    static uint16_T socn_pct_battSoc_Delay;
+    static uint16_T socn_pct_battSoc0;
+    static uint16_T socn_pct_bcuSoc0;
     uint16_T delSOC;
     uint16_T bcuSoc;
     int16_T  coinSoc;
@@ -99,11 +94,11 @@ void SOC(void)
     static boolean_T onceFlg_chrg;
     static boolean_T onceFlg_dischrg;
 
-	static uint16_T socd_pct_battSoc_save;
-	static uint16_T socd_pct_bcuSoc_save;
+	static uint16_T socn_pct_battSoc_save;
+	static uint16_T socn_pct_bcuSoc_save;
     uint16_T i;
     //
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         onceFlg_est = true;
         ekfInvalidCntl = 0;
@@ -113,24 +108,25 @@ void SOC(void)
         overFlg = false;
         fulFlg = false;
         lowFlg = false;
+		statCntl = 0;
         Soc_Delay = 0;
         onceFlg_utrckOver = true;
         onceFlg_utrckLow = true;
-        ihd_st_chrgSta_Delay = 0;
-        socd_pct_battSoc_Delay = 0;
+        socn_st_workStat_Delay = 0;
+        socn_pct_battSoc_Delay = 0;
         onceFlg_chrg = true;
         onceFlg_dischrg = true;
-		socd_pct_battSoc_save = 0;
-		socd_pct_bcuSoc_save = 0;	
+		socn_pct_battSoc_save = 0;
+		socn_pct_bcuSoc_save = 0;	
     }
     
     //=====================================================================
-    ////////////////////////初始值获取//////////////////////////////////////
+    ////////////////////////初始值获取/EE校验//////////////////////////////
     //=====================================================================
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     { //
         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 && sfmd_I_curr < 10 && sfmd_I_curr > -10))
+           (((int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) > 300 || (int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) < -300) && ihd_tm_parkTime >= cmnc_tm_parkTime && sfmd_I_curr < 10 && sfmd_I_curr > -10))
         {
             socn_pct_battSocEE = look1_u16tu16(sfmd_V_cellUAvrg, cmnm_V_ocv, cmnm_pct_soc, 13);
             socn_pct_bcuSocEE  = look1_u16tu16(sfmd_V_cellUAvrg, cmnm_V_ocv, cmnm_pct_soc, 13);
@@ -138,7 +134,7 @@ void SOC(void)
         else
         {
             socn_pct_battSocEE = socd_pct_battSocEi;
-            socn_pct_bcuSocEE = socd_pct_bcuSocEi;
+            socn_pct_bcuSocEE  = socd_pct_bcuSocEi;
         }
         //
         if (ihd_tm_parkTime >= cmnc_tm_parkTime  && sfmd_I_curr < 10 && sfmd_I_curr > -10)
@@ -146,7 +142,6 @@ void SOC(void)
             socn_pct_battSocEE = look1_u16tu16(sfmd_V_cellUAvrg, cmnm_V_ocv, cmnm_pct_soc, 13);
         }
         socn_Q_cap = (uint16_T)((uint16_T)((uint32_T)sohd_pct_bcuSoh * cmnc_Q_ratedCp / 2000U) << 1);
-		//socn_ohm_cellRAvrg = ArrMean(&sorv_ohm_cellREi[0], cmnc_num_cellUNum);
     }
 	
     //printf("1----  battSocEi:%d,bcuSocEi:%d,battSocEE:%d,bcuSocEE:%d\n",socd_pct_battSocEi,socd_pct_bcuSocEi,socn_pct_battSocEE,socn_pct_bcuSocEE);
@@ -157,7 +152,7 @@ void SOC(void)
     Q = (real_T)socn_Q_cap * 0.1;
     
     //-------------------------EKFmin---------------------------------------
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         soc_Min_Delay = (real_T)socn_pct_battSocEE * 0.1;
         Up_Min_Delay = 0;
@@ -220,7 +215,7 @@ void SOC(void)
     socn_flg_ekfInvalidMin = (deltU > 0.01) || (deltU < -0.01);
     //printf("2----socmin:%f,U:%d,R:%f\n",soc_Min_Delay,sfmd_V_cellUMin,Ro);
 	//------------------------EKFSOCmax-----------------------------------
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         soc_Max_Delay = (real_T)socn_pct_battSocEE * 0.1;
         Up_Max_Delay = 0;
@@ -282,7 +277,7 @@ void SOC(void)
     //输出
     EKFSOCMax = (uint16_T)(soc_Max_Delay * 10);
     socn_flg_ekfInvalidMax = (deltU > 0.01) || (deltU < -0.01);
-    //printf("4----socmax:%f,U:%d,R:%f\n\n",soc_Max_Delay,sfmd_V_cellUMax,Ro);
+    //printf("3----socmax:%f,U:%d,R:%f\n\n",soc_Max_Delay,sfmd_V_cellUMax,Ro);
     //-----------------------EKFSOC----------------------------------------
     socn_flg_ekfInvalid = socn_flg_ekfInvalidMax || socn_flg_ekfInvalidMin;
     if (EKFSOCMax > 800)
@@ -299,10 +294,10 @@ void SOC(void)
     }
     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);
+   //printf("4----socd_pct_ekfSoc:%d,EKFSOCMax:%d,EKFSOCMin:%d,\n",socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin);
 
    //-------------------------EKFavrg---------------------------------------
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         soc_Avrg_Delay = (real_T)socn_pct_battSocEE * 0.1;
         Up_Avrg_Delay = 0;
@@ -393,7 +388,7 @@ void SOC(void)
     //======================================================================
     ////////////////////////AhSOC//////////////////////////////////////////
     //======================================================================
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         ahDelay = (real_T)(socn_pct_battSocEE * 0.1);
     }
@@ -419,16 +414,8 @@ void SOC(void)
     //======================================================================
     ///////////////////////estSOC//////////////////////////////////////////
     //======================================================================
-    if (!socn_flg_ekfInvalid)
-    {
-        ekfInvalidCntl = (ekfInvalidCntl + 1) > 250 ? 250 : (ekfInvalidCntl + 1);
-    }
-    else
-    {
-        ekfInvalidCntl = 0;
-    }
-    
-    if (ekfInvalidCntl < 20)
+    socn_flg_ekfDisable = !JudgeTimeSystem(1,!socn_flg_ekfInvalid,&ekfInvalidCntl,20);
+    if (socn_flg_ekfDisable)
     {
         if (onceFlg_est)
         {  
@@ -460,37 +447,12 @@ void SOC(void)
     //======================================================================
     if (ihd_st_workStat == 2)
     {
-        disChrgCntl = 0;
-        chrgCntl = (chrgCntl + 1) > 250 ? 250 : (chrgCntl + 1);
         lowCntl = 0;
         lowFlg = false;
-	    socd_V_chrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_chrgCor,socm_V_chrgCor,3); 
-		if (sfmd_V_cellUMax >= socd_V_chrgCCV)
-        {
-            overCntl = (overCntl + 1) > 250 ? 250 : (overCntl + 1);
-        }
-        else
-        {
-            overCntl = 0;
-        }
-        if (overCntl > 2 || overFlg)
-        {
-            overFlg = 1;
-        }
-        //
-        if (sfmd_V_cellUMax >= cmnc_V_chrgFul)
-        {
-            fulCntl = (fulCntl + 1) > 250 ? 250 : (fulCntl + 1);
-        }
-        else
-        {
-            fulCntl = 0;
-        }
-        if ((fulCntl > 2) || fulFlg)
-        {
-            fulFlg = 1;
-        }
-        
+		
+	    socn_V_chrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_chrgCor,socm_V_chrgCor,3); 
+		overFlg = JudgeTimeSystem(1,sfmd_V_cellUMax >= socn_V_chrgCCV,&overCntl,2) || overFlg;
+        fulFlg  = JudgeTimeSystem(1,sfmd_V_cellUMax >= cmnc_V_chrgFul,&fulCntl ,2) || fulFlg;
         //
         if (overFlg)
         {
@@ -502,15 +464,11 @@ void SOC(void)
             }
             socTemp = (uint16_T)(ahSoc - ahSoc0_utrckOver + estSoc0_utrckOver);
         }
-        else if (chrgCntl > 2)
+        else
         {
             onceFlg_utrckOver = true;
             socTemp = socd_pct_estSoc > socc_pct_chrgCor ? socc_pct_chrgCor : socd_pct_estSoc;
         }
-        else
-        {
-            socTemp = socd_pct_estSoc;
-        }
         //
         socn_pct_utrackSoc = Soc_Delay + (socTemp > Soc_Delay ? (socTemp - Soc_Delay) : 0);
         Soc_Delay = socn_pct_utrackSoc;
@@ -528,8 +486,6 @@ void SOC(void)
     }
     else
     {
-        chrgCntl = 0;
-        disChrgCntl = (disChrgCntl + 1) > 250 ? 250 : (disChrgCntl + 1);
         Soc_Delay = 0;
         overCntl = 0;
         overFlg = false;
@@ -537,96 +493,73 @@ void SOC(void)
         fulCntl = 0;
 		if (!cdmd_flg_deltOCVDisable)
 		{
-		    socd_V_disChrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_disChrgCor,socm_V_disChrgCor,3) + (uint16_T)(sfmd_I_curr * (cdmv_ohm_deltR[sfmd_idx_cellUMin]) * 0.001 * 0.1);
+		    socn_V_disChrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_disChrgCor,socm_V_disChrgCor,3) + (uint16_T)(sfmd_I_curr * (cdmv_ohm_deltR[sfmd_idx_cellUMin]) * 0.001 * 0.1);
 		}
 		else
 		{
-		    socd_V_disChrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_disChrgCor,socm_V_disChrgCor,3);
+		    socn_V_disChrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_disChrgCor,socm_V_disChrgCor,3);
 		}
-		
-        if (sfmd_V_cellUMin <= socd_V_disChrgCCV) 
-        {
-            lowCntl = (lowCntl + 1) > 250 ? 250 : (lowCntl + 1);
-        }
-        else
-        {
-            lowCntl = 0;
-        }
-        if (lowCntl > 2 || lowFlg)
-        {
-            lowFlg = true;
-        }
+		lowFlg = JudgeTimeSystem(1,sfmd_V_cellUMin <= socn_V_disChrgCCV,&lowCntl,2) || lowFlg;
         //
         if (lowFlg)
         {
             if (onceFlg_utrckLow)
             {
                 onceFlg_utrckLow = false;
-                ahSoc0_utrckLow = ahSoc;
+                ahSoc0_utrckLow  = ahSoc;
                 estSoc0_utrckLow = socc_pct_disChrgCor;
             }
             socn_pct_utrackSoc = (int16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) > 0 ? (uint16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) : 0;
         }
-        else if (disChrgCntl > 2)
+        else 
         {
             onceFlg_utrckLow = true;
             socn_pct_utrackSoc = socd_pct_estSoc < socc_pct_disChrgCor ? socc_pct_disChrgCor : socd_pct_estSoc;
         }
-        else
-        {
-            socn_pct_utrackSoc = socd_pct_estSoc;
-        }
-       //  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);
+		
+        //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);
     }
-    socd_pct_battSoc = socn_pct_utrackSoc;
+    socd_pct_battSoc   = socn_pct_utrackSoc;
     socd_pct_battSocEo = socn_pct_utrackSoc;
 
     
     //===============================================================================================================================================================
     ////////////////////////////////////////////////BCUSOC///////////////////////////////////////////////////////////////////////////////////////////////////////////
     //=============================================================================================================================================================== 
-    if (sfmd_I_curr < 10 && sfmd_I_curr > -10)
-    {
-        statCntl = (statCntl + 1) > 250 ? 250 : (statCntl + 1);
-    }
-    else
-    {
-        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)(socd_pct_battSoc  - socd_pct_battSoc_Delay) > 5 || (int16_T)(socd_pct_battSoc - socd_pct_battSoc_Delay) < -5) || statFlg);
-    
-    ihd_st_chrgSta_Delay = ihd_st_workStat;
-    socd_pct_battSoc_Delay = socd_pct_battSoc;
+    Flg = (socd_flg_firstRun || (socn_st_workStat_Delay == 2 && ihd_st_workStat != 2) || (socn_st_workStat_Delay != 2 && ihd_st_workStat == 2) ||
+          ((int16_T)(socd_pct_battSoc  - socn_pct_battSoc_Delay) > 5 || (int16_T)(socd_pct_battSoc - socn_pct_battSoc_Delay) < -5) ||
+          JudgeTimeSystem(1,sfmd_I_curr < 10 && sfmd_I_curr > -10,&statCntl ,3));
+	
+    socn_st_workStat_Delay = ihd_st_workStat;
+    socn_pct_battSoc_Delay = socd_pct_battSoc;
     
     //
     if (Flg)
     {
-        socd_pct_battSoc0 = socd_pct_battSoc;
-        if (FirstRun_SOC)
+        socn_pct_battSoc0 = socd_pct_battSoc;
+        if (socd_flg_firstRun)
         {
-            socd_pct_bcuSoc0 = socn_pct_bcuSocEE;
+            socn_pct_bcuSoc0 = socn_pct_bcuSocEE;
         }
         else
         {
-            socd_pct_bcuSoc0 = socd_pct_bcuSoc;
+            socn_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);
+        delSOC = socn_pct_battSoc0 > socn_pct_bcuSoc0 ? (socn_pct_battSoc0 - socn_pct_bcuSoc0) : (socn_pct_bcuSoc0 - socn_pct_battSoc0);
+        coinSoc = (socn_pct_battSoc0 > socn_pct_bcuSoc0 ? socn_pct_battSoc0 : socn_pct_bcuSoc0) + (delSOC > 50 ? 50 : delSOC);
         
-        x[0] = socd_pct_battSoc0;
-        x[1] = coinSoc > socc_pct_battSocUp ? socc_pct_battSocUp : (uint16_T)coinSoc;
+        x[0] = socn_pct_battSoc0 > socc_pct_battSocUp - 2 ? socc_pct_battSocUp - 2 : socn_pct_battSoc0;
+        x[1] = coinSoc > socc_pct_battSocUp - 1 ? socc_pct_battSocUp - 1: (uint16_T)coinSoc;
         x[2] = socc_pct_battSocUp;
         
-        y[0] = socd_pct_bcuSoc0;
-        y[1] = coinSoc > socc_pct_battSocUp ? socc_pct_battSocUp : (uint16_T)coinSoc;
+        y[0] = socn_pct_bcuSoc0 > socc_pct_battSocUp - 2 ? socc_pct_battSocUp - 2 : socn_pct_bcuSoc0;;
+        y[1] = coinSoc > socc_pct_battSocUp - 1 ? socc_pct_battSocUp - 1: (uint16_T)coinSoc;
         y[2] = socc_pct_battSocUp;
         bcuSoc = look1_u16tu16(socd_pct_battSoc, x, y,3);
         
@@ -637,6 +570,7 @@ void SOC(void)
             onceFlg_dischrg = true;
             socd_pct_bcuSoc = bcuSoc;
         }
+		
         socd_pct_bcuSoc = DataFilt(bcuSoc, &socd_pct_bcuSoc, 1);
         
         //
@@ -648,20 +582,21 @@ void SOC(void)
         {
             socd_pct_bcuSoc = socd_pct_bcuSoc > (socc_pct_battSocUp - 1) ? (socc_pct_battSocUp - 1) : socd_pct_bcuSoc;
         }
-       //printf("10-----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);
+       //printf("10-----x:[%d-%d-%d],y:[%d-%d-%d],battSOC:%d,bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],socd_pct_battSoc,bcuSoc,socd_pct_bcuSoc);
     }
     else
     {
         //
-        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));
+        delSOC = socn_pct_battSoc0 > socn_pct_bcuSoc0 ? (socn_pct_battSoc0 - socn_pct_bcuSoc0) : (socn_pct_bcuSoc0 - socn_pct_battSoc0);
+        coinSoc = (int16_T)((socn_pct_battSoc0 < socn_pct_bcuSoc0 ? socn_pct_battSoc0 : socn_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;
+        x[1] = coinSoc < socc_pct_battSocLow + 1 ? socc_pct_battSocLow + 1 : (uint16_T)coinSoc;
+        x[2] = socn_pct_battSoc0 < socc_pct_battSocLow + 2 ? socc_pct_battSocLow + 2 : (uint16_T)socn_pct_battSoc0;
+		
         y[0] = socc_pct_battSocLow;
-        y[1] = coinSoc > socc_pct_battSocLow ? (uint16_T)coinSoc : socc_pct_battSocLow;
-        y[2] = socd_pct_bcuSoc0;
+        y[1] = coinSoc < socc_pct_battSocLow + 1 ? socc_pct_battSocLow + 1 : (uint16_T)coinSoc;
+        y[2] = socn_pct_bcuSoc0 < socc_pct_battSocLow + 2 ? socc_pct_battSocLow + 2 : (uint16_T)socn_pct_bcuSoc0;
         bcuSoc = look1_u16tu16(socd_pct_battSoc, x, y,3);
         
         //
@@ -671,7 +606,9 @@ void SOC(void)
             onceFlg_dischrg = false;
             socd_pct_bcuSoc = bcuSoc;
         }
+		
         socd_pct_bcuSoc = DataFilt(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;
@@ -680,22 +617,24 @@ void SOC(void)
 	
     socd_pct_vcuSoc =  (uint16_T)((uint32_T)((socd_pct_bcuSoc - socc_pct_battSocLow) * 1000) / (socc_pct_battSocUp - socc_pct_battSocLow)); 
 	
-    //printf("BattSOC:%d,BCUSOC:%d,VcuSoc:%d\n",socd_pct_battSoc,socd_pct_bcuSoc,socd_pct_vcuSoc);
     //================================================================================================
     //------------------EEsave-------------------------------------------=============================
     //================================================================================================
-    if ((int16_T)(socd_pct_battSoc - socd_pct_battSoc_save) > 10 || (int16_T)(socd_pct_battSoc - socd_pct_battSoc_save) < -10 || (int16_T)(socd_pct_bcuSoc - socd_pct_bcuSoc_save) > 10 || (int16_T)(socd_pct_bcuSoc - socd_pct_bcuSoc_save) < -10 )
+    if ((int16_T)(socd_pct_battSoc - socn_pct_battSoc_save) > 10 || (int16_T)(socd_pct_battSoc - socn_pct_battSoc_save) < -10 || (int16_T)(socd_pct_bcuSoc - socn_pct_bcuSoc_save) > 10 || (int16_T)(socd_pct_bcuSoc - socn_pct_bcuSoc_save) < -10 )
     {
         socd_flg_EEsave = 1;
-        socd_pct_battSoc_save = socd_pct_battSoc;
-	    socd_pct_bcuSoc_save  = socd_pct_bcuSoc;
+        socn_pct_battSoc_save = socd_pct_battSoc;
+	    socn_pct_bcuSoc_save  = socd_pct_bcuSoc;
     }
     else
     {
         socd_flg_EEsave = 0;
     }
+
 	
-    FirstRun_SOC = false;
+    socd_flg_firstRun = false;
+
+	//printf("\n");
 }
 
 
@@ -706,14 +645,10 @@ void SOC(void)
 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) +
-            -0.00371 * soc) +
-            0.02732;
+    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) +
+           -0.00371 * soc) +0.02732;
     return docv;
 }
 

+ 3 - 6
src/EmbeddedCoder_src/SOE.c

@@ -1,11 +1,8 @@
 #include "SOE.h"
 
-
-boolean_T FirstRun_SOE;
-
 void SOE_Init(void)
 {
-    FirstRun_SOE = true;
+    soed_flg_firstRun = true;
 }
 //-------------------------------------------------------------------------
 void SOE(void)
@@ -15,7 +12,7 @@ void SOE(void)
 
 	
 	// 满电能量
-    if(FirstRun_SOE)
+    if(soed_flg_firstRun)
     {
         soen_V_battOcv = 0;
         for(i = socc_pct_battSocUp ;i >= socc_pct_battSocLow + 1;i--)
@@ -39,7 +36,7 @@ void SOE(void)
         soed_E_nowEng = 0;
     }
     soed_pct_nowStat = (uint16_T)((uint32_T)(soed_E_nowEng * 1000)/soed_E_fullEng);
-    FirstRun_SOE = false;   
+    soed_flg_firstRun = false;   
 }
 
 

+ 22 - 31
src/EmbeddedCoder_src/SOH.c

@@ -1,11 +1,8 @@
 #include "SOH.h"
 
-
-boolean_T FirstRun_SOH;
-
 void SOH_Init(void)
 {
-    FirstRun_SOH = true ;
+    sohd_flg_firstRun = true ;
 }
 
 void SOH(void)
@@ -36,16 +33,16 @@ void SOH(void)
     //
     static uint16_T sohn_V_chrgStartStat[cmnc_num_cellUNumMax];
     static uint8_T sohn_st_workStat_Delay;
-    static boolean_T sohn_flg_chrgEnd_Delay;
-    boolean_T sohn_flg_chrgEnd;
     //
     static real_T Ahincr;
-    int32_T  tmp_0; 
+    int16_T  tmp_0; 
     static boolean_T sfmn_flg_currFlt_keep;
     static boolean_T sohn_flg_currFlt;
     boolean_T DisEn;
-    
-    if(FirstRun_SOH)
+
+
+	//初值
+    if(sohd_flg_firstRun)
     {   
         sohn_flg_update = true;
         sfmn_flg_currFlt_keep = false;
@@ -63,15 +60,11 @@ void SOH(void)
 		   memset(sohv_V_chrgStartStatEo,0, sizeof(sohv_V_chrgStartStatEo));
 		   sohd_Q_chrgEo = 0 ;
 		   sohd_flg_chrgEndEo = 0; 
-
-		}
-		
+		}	
     }
   
 
-
-	
-    if(FirstRun_SOH)
+    if(sohd_flg_firstRun)
     {
         //=======================================================================================
         //--------------------------EE校验-------------------------------------------------------
@@ -116,7 +109,7 @@ void SOH(void)
         {
             sohn_flg_countEn = false;
         }
-        test_countEn = sohn_flg_countEn;
+        
 		//=======================================================================================
         //------------------------SOH 计算-------------------------------------------------------
         //=======================================================================================
@@ -129,27 +122,26 @@ void SOH(void)
                 soc1[i] =  look1_u16tu16(sohn_V_chrgStartStatEE[i],cmnm_V_ocv, cmnm_pct_soc, 13U);
                 deltSoc[i] = soc2[i] - soc1[i];
                 sohv_Q_cellCapArrEo[i] = (uint16_T)( (real_T)(sohn_Q_chrgEE * 0.1) / (real_T)(deltSoc[i]  * 0.1/100)  * 10);
-				test_cellCap[i] = sohv_Q_cellCapArrEo[i];
+
                 if( (int16_T)(sohv_Q_cellCapArrEo[i]) - sohn_Q_cellCapArrEE[i] > sohc_Q_updateDeltThr  ||  (int16_T)(sohv_Q_cellCapArrEo[i]) - sohn_Q_cellCapArrEE[i] < -sohc_Q_updateDeltThr  )
                 {
                     sohn_flg_update = false;
                     break;
                 }
             }
-            DisEn = (ArrMin(soc2 , cmnc_num_cellUNum) > sohc_pct_low &&   ArrMin(soc2 , cmnc_num_cellUNum) < sohc_pct_up) 
-                  ||(ArrMax(soc2 , cmnc_num_cellUNum) > sohc_pct_low &&   ArrMax(soc2 , cmnc_num_cellUNum) < sohc_pct_up)
-                  ||(ArrMin(soc1 , cmnc_num_cellUNum) > sohc_pct_low &&   ArrMin(soc1 , cmnc_num_cellUNum) < sohc_pct_up)
-                  ||(ArrMax(soc1, cmnc_num_cellUNum) > sohc_pct_low &&    ArrMax(soc1 , cmnc_num_cellUNum) < sohc_pct_up);
+            DisEn = (ArrMin(soc2 , cmnc_num_cellUNum) > sohc_pct_low &&  ArrMin(soc2 , cmnc_num_cellUNum) < sohc_pct_up) 
+                  ||(ArrMax(soc2 , cmnc_num_cellUNum) > sohc_pct_low &&  ArrMax(soc2 , cmnc_num_cellUNum) < sohc_pct_up)
+                  ||(ArrMin(soc1 , cmnc_num_cellUNum) > sohc_pct_low &&  ArrMin(soc1 , cmnc_num_cellUNum) < sohc_pct_up)
+                  ||(ArrMax(soc1 , cmnc_num_cellUNum) > sohc_pct_low &&  ArrMax(soc1 , cmnc_num_cellUNum) < sohc_pct_up);
 			//===================
             if(sohn_flg_update && !DisEn)
             {   
 				for(i = 0;i < cmnc_num_cellUNum;i++)
  				{
- 				     temp[i] = (real_T) (soc2[i] * 0.1) /100;
-                     chrgCellCapArr[i] =    (uint16_T)( (real_T)(sohv_Q_cellCapArrEo[i] * 0.1)*(1 - temp[i]) * 10);
-                     disChrgCellCapArr[i] = (uint16_T)( (real_T)(sohv_Q_cellCapArrEo[i] * 0.1)*(    temp[i]) * 10);
+                     chrgCellCapArr[i] =    (uint16_T)((uint32_T)(sohv_Q_cellCapArrEo[i] * (1000 - soc2[i]))/1000);
+                     disChrgCellCapArr[i] = (uint16_T)((uint32_T)(sohv_Q_cellCapArrEo[i] * (        soc2[i]))/1000);
  				} 
-                 chrgCap_Min    = ArrMin(chrgCellCapArr , cmnc_num_cellUNum);
+                 chrgCap_Min    = ArrMin(chrgCellCapArr   , cmnc_num_cellUNum);
                  disChrgCap_Min = ArrMin(disChrgCellCapArr, cmnc_num_cellUNum);
                  for(i = 0; i < 9;i++)
                  {
@@ -183,9 +175,9 @@ void SOH(void)
      //=======================================================================================
      //----------------------充电前信息-------------------------------------------------------
      //=======================================================================================
-     if (FirstRun_SOH)
+     if (sohd_flg_firstRun)
      {
-     	memcpy(sohn_V_chrgStartStat,appv_V_cellU, sizeof(appv_V_cellU));
+     	 memcpy(sohn_V_chrgStartStat,appv_V_cellU, sizeof(appv_V_cellU));
      }
      
      if(sfmd_I_curr < 10 && sfmd_I_curr > -10 && !sfmd_flg_cellUDisable)
@@ -220,8 +212,8 @@ void SOH(void)
         sfmn_flg_currFlt_keep = false;
         Ahincr = 0;
     }
-	//printf("sohd_Q_chrgEo:%d\n",sohd_Q_chrgEo);
-	 //=======================================================================================
+
+	//=======================================================================================
     //----------------------充电结速信息------------------------------------------------------
     //=======================================================================================
     if((ihd_st_workStat != 2) && (sohn_st_workStat_Delay == 2))
@@ -236,8 +228,7 @@ void SOH(void)
 
     //
     sohn_st_workStat_Delay = ihd_st_workStat;
-	FirstRun_SOH = false;	
-	
+	sohd_flg_firstRun = false;	
 }
 
 

+ 5 - 8
src/EmbeddedCoder_src/SOR.c

@@ -1,11 +1,8 @@
 #include "SOR.h"
 
-
-boolean_T FirstRun_SOR;
-
 void SOR_Init(void)
 {
-    FirstRun_SOR = true;
+    sord_flg_firstRun = true;
 }
 //-------------------------------------------------------------------------
 void SOR(void)
@@ -20,15 +17,15 @@ void SOR(void)
     uint16_T j;
 	
     //
-    if(FirstRun_SOR)
+    if(sord_flg_firstRun)
     {
         sorn_num_ctn = 0;
         sorn_I_curr = sfmd_I_curr;
         memcpy(sorn_V_cellU,sfmv_V_cellU, sizeof(sfmv_V_cellU));
     }
-    if(FirstRun_SOR)
+    if(sord_flg_firstRun)
     {
-        if(ArrMax((&(sorv_ohm_cellREi[0])) , cmnc_num_cellUNum) > 65000)
+        if(ArrMax((sorv_ohm_cellREi, cmnc_num_cellUNum) > 65000)
         {
             memset(sorn_ohm_cellREE,0, sizeof(sorn_ohm_cellREE));
         }
@@ -64,5 +61,5 @@ void SOR(void)
 	
 	sorn_I_curr = sfmd_I_curr;
     memcpy(sorn_V_cellU,sfmv_V_cellU, sizeof(sfmv_V_cellU));
-    FirstRun_SOR = false;
+    sord_flg_firstRun = false;
 }

+ 18 - 19
src/EmbeddedCoder_src/SPM.c

@@ -1,7 +1,5 @@
 #include "SPM.h"
 
-boolean_T FirstRun_SPM;
-
 void SPM_Init(void)
 {
   SOH_Init();
@@ -11,30 +9,30 @@ void SPM_Init(void)
   PIM_Init();
   SOE_Init();
   SOR_Init();
-  FirstRun_SPM = true;
+  spmd_flg_firstRun = true;
 }
 
 void SPM(void)
 {
-  static uint16_T spmd_Nr_cellNr;
+  static uint16_T spmn_num_cellNr;
   uint8_T Feq = 30;
-  if (FirstRun_SPM)
+  if (spmd_flg_firstRun)
   {
-    spmd_Nr_cellNr = 0;
-    cand_Nr_cellNr = 1;
+    spmn_num_cellNr = 0;
+    cand_idx_cellNr = 1;
   }
-  spmd_Nr_cellNr = spmd_Nr_cellNr + 1;
-  if (spmd_Nr_cellNr % Feq == 0)
+  spmn_num_cellNr = spmn_num_cellNr + 1;
+  if (spmn_num_cellNr % Feq == 0)
   {
-    cand_Nr_cellNr ++;
+    cand_idx_cellNr ++;
   }
-  else if (spmd_Nr_cellNr > 60000)
+  else if (spmn_num_cellNr > 60000)
   {
-    spmd_Nr_cellNr = 0;
+    spmn_num_cellNr = 0;
   }
-  if (cand_Nr_cellNr > cmnc_num_cellUNum)
+  if (cand_idx_cellNr > cmnc_num_cellUNum)
   {
-    cand_Nr_cellNr = 1;
+    cand_idx_cellNr = 1;
   }
   //调用SOX算法
   SOH();
@@ -48,11 +46,12 @@ void SPM(void)
 	  SOR();
   }
   // 循环发送数组
-  cand_Q_cellCap = sohv_Q_cellCapArrEo[cand_Nr_cellNr-1];
-  cand_V_chrgStartStat = sohv_V_chrgStartStatEo[cand_Nr_cellNr-1];
-  cand_Q_reqCp   = blcv_Q_reqCpEo[cand_Nr_cellNr-1];
-  cand_Q_totalCp = blcv_Q_totalCpEo[cand_Nr_cellNr-1];
-  FirstRun_SPM = false;
+  cand_Q_cellCap = sohv_Q_cellCapArrEo[cand_idx_cellNr-1];
+  cand_V_chrgStartStat = sohv_V_chrgStartStatEo[cand_idx_cellNr-1];
+  cand_Q_blcReqCp   = blcv_Q_reqCpEo[cand_idx_cellNr-1];
+  cand_Q_blcTotalCp = blcv_Q_totalCpEo[cand_idx_cellNr-1];
+  
+  spmd_flg_firstRun = false;
 }
 
 

+ 10 - 10
src/EmbeddedCoder_src/funlib.c

@@ -2,7 +2,7 @@
 
 
 
-//-------------------数组取最大-------------------------------------
+//-------------------uint16数组取最大-------------------------------------
 uint16_T  ArrMax(uint16_T *Data, uint16_T n)
 {
     uint16_T i;
@@ -18,7 +18,7 @@ uint16_T  ArrMax(uint16_T *Data, uint16_T n)
 	return DataMax;
 }
 
-//-----------------数组取最小-------------------------------------
+//-----------------uint16数组取最小-------------------------------------
 uint16_T  ArrMin(uint16_T *Data, uint16_T n)
 {
     uint16_T i;
@@ -35,7 +35,7 @@ uint16_T  ArrMin(uint16_T *Data, uint16_T n)
 }
 //
 
-/////////////////////////////////////////////////////////////////////////////////
+/////////////////////////// int16数组求均值////////////////////////////////////
 int16_T ArrMean(int16_T *Data, uint16_T n)
 {
     uint16_T i;
@@ -51,9 +51,7 @@ int16_T ArrMean(int16_T *Data, uint16_T n)
 }
 
 
-
-
-// 滤波控制变动速率
+// ---------------------滤波控制变动速率-------------------------------------- 
 uint16_T DataFilt(uint16_T in, uint16_T *out, uint16_T Lim)
 {
     int16_T delt;
@@ -76,6 +74,8 @@ uint16_T DataFilt(uint16_T in, uint16_T *out, uint16_T Lim)
 //-------------------uint16 to uint16的一维查表--------------------------------------  
 uint16_T look1_u16tu16(uint16_T u0, const uint16_T *bp0, const uint16_T *table, uint16_T MaxLen)
 {
+    
+
 	uint32_T bpIdx = 0;
 	uint32_T iLeft = 0;
 	uint32_T iRght = 0;
@@ -120,11 +120,11 @@ uint16_T look1_u16tu16(uint16_T u0, const uint16_T *bp0, const uint16_T *table,
 		yL_0d0 = table[iLeft];
 		if (yR_0d0 >= yL_0d0)
 		{
-			y = ((uint16_T)((uint32_T)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
+			y = (uint16_T)(((uint32_T)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
 		}
 		else
 		{
-			y = ((uint16_T)(yL_0d0 - ((uint32_T)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft])));
+			y = (uint16_T)((yL_0d0 - ((uint32_T)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft])));
 		}
 	}
 	else
@@ -182,11 +182,11 @@ uint16_T look1_i16tu16(int16_T u0, const int16_T *bp0, const uint16_T *table, ui
 		yL_0d0 = table[iLeft];
 		if (yR_0d0 >= yL_0d0)
 		{
-			y = ((uint16_T)((uint32_T)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
+			y = (uint16_T)(((uint32_T)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
 		}
 		else
 		{
-			y = ((uint16_T)(yL_0d0 - ((uint32_T)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft])));
+			y = (uint16_T)((yL_0d0 - ((uint32_T)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft])));
 		}
 	}
 	else