Browse Source

修改3 增加温度滤波

LAPTOP-EG88H5BE\86151 3 years ago
parent
commit
8b2df30c58
3 changed files with 35 additions and 2 deletions
  1. 1 0
      inc/EmbeddedCoder_inc/funlib.h
  2. 14 2
      src/AppFunc.c
  3. 20 0
      src/EmbeddedCoder_src/funlib.c

+ 1 - 0
inc/EmbeddedCoder_inc/funlib.h

@@ -6,6 +6,7 @@ extern uint16_T  ArrMin(uint16_T *Data, uint16_T m);
 extern int16_T ArrMean(int16_T *Data, uint16_T n);
 
 extern uint16_T  DataFilt(uint16_T in, uint16_T *out, uint16_T Lim);
+extern uint8_T DataFilt8(uint8_T in, uint8_T *out, uint8_T Lim);
 
 extern uint16_T look1_i16tu16(int16_T u0, const int16_T *bp0,  const uint16_T *table, uint16_T MaxLen);
 extern uint16_T look1_u16tu16(uint16_T u0, const uint16_T *bp0,  const uint16_T *table, uint16_T MaxLen);

+ 14 - 2
src/AppFunc.c

@@ -11,6 +11,7 @@
 #include "numeric.h"
 #include "hal_module_adapter.h"
 #include "BCUDisp.h"
+#include "funlib.h"
 /**
  * @brief : 保护板保护状态解码
  * @param {*}
@@ -818,6 +819,7 @@ BOOL uartBattInfoDecode(UINT8 *dataPtr)
 	UINT16 Batt_current;
 	UINT8 BATT_CELL_VOL_NUM = 0, BATT_TEMP_NUM = 0;
 	UINT32 Battsumvoltage = 0;
+	static BOOL First_Run = true;
 	BATT_CELL_VOL_NUM = (dataPtr[(0x00) * 2] << 8) | (dataPtr[(0x00) * 2 + 1]);
 	BATT_TEMP_NUM = ((dataPtr[(0x01) * 2] << 8) | (dataPtr[(0x01) * 2 + 1])) - BMS_OTHER_TEMP;
 	if ((AppDataInfo.BattCellCount != BATT_CELL_VOL_NUM || AppDataInfo.BattTempCount != BATT_TEMP_NUM) && (BATT_CELL_VOL_NUM != 0) && (BATT_TEMP_NUM != 0))
@@ -882,10 +884,20 @@ BOOL uartBattInfoDecode(UINT8 *dataPtr)
 	avrgCellVol = Battsumvoltage / BATT_CELL_VOL_NUM;
 	battWorkState = (dataPtr[(0x03 + BATT_CELL_VOL_NUM) * 2 + 1]) & 0x03; //电池状态(原始数据),0表示静置,1表示放电,2表示充电
 	TEMP_NUM = BATT_TEMP_NUM + BMS_OTHER_TEMP;
+
+	
+	
 	for (i = 0; i < BATT_TEMP_NUM; i++)
-	{
-		battCellTemp[i] = dataPtr[(0x06 + BATT_CELL_VOL_NUM + i) * 2 + 1];
+	{   
+	    if(First_Run)
+	    {
+		   battCellTemp[i] = dataPtr[(0x06 + BATT_CELL_VOL_NUM + i) * 2 + 1];
+	    }
+		battCellTemp[i] = DataFilt8(dataPtr[(0x06 + BATT_CELL_VOL_NUM + i) * 2 + 1],&battCellTemp[i],5);
 	}
+	First_Run = FALSE;
+
+	
 	MOSTemp = dataPtr[(0x06 + BATT_CELL_VOL_NUM + BATT_TEMP_NUM) * 2 + 1];
 	packTemp = dataPtr[(0x06 + BATT_CELL_VOL_NUM + BATT_TEMP_NUM + 1) * 2 + 1];
 	chargerConnectState = (dataPtr[(0x03 + BATT_CELL_VOL_NUM) * 2 + 1] >> 2) & 0x01; //充电器连接状态,0表示未连接,1表示已连接

+ 20 - 0
src/EmbeddedCoder_src/funlib.c

@@ -71,6 +71,26 @@ uint16_T DataFilt(uint16_T in, uint16_T *out, uint16_T Lim)
     return *out;
 }
 
+// ---------------------滤波控制变动速率-------------------------------------- 
+uint8_T DataFilt8(uint8_T in, uint8_T *out, uint8_T Lim)
+{
+    int8_T delt;
+    delt = (int8_T)(in - *out);
+    if (delt > Lim)
+    {
+        *out = *out + (delt > Lim ? Lim : delt);
+    }
+    if (delt < -Lim)
+    {
+        *out = *out + (delt < -Lim  ? -Lim  : delt);
+    }
+    if (delt <= Lim && delt >= -Lim)
+    {
+        *out = in;
+    }
+    return *out;
+}
+
 //-------------------uint16 to uint16的一维查表--------------------------------------  
 uint16_T look1_u16tu16(uint16_T u0, const uint16_T *bp0, const uint16_T *table, uint16_T MaxLen)
 {