فهرست منبع

2.1.5_20200904 TC013054-MB2001-A-V1r1
1、车速检测,增加限值处理,提高抗干扰性;
2、车速滤波采用滑动中值滤波;
3、软件版本:2.1.5_20200904 特性说明:TC013054-MB2001-A-V1r1

dail.zhou 4 سال پیش
والد
کامیت
aa68d649d2

+ 7 - 1
Core/Src/gpio.c

@@ -151,6 +151,7 @@ void Disable_PwmGpio_Out(void)
 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
 {
 	static uint32_t SignalTrigCount = 0;
+	static uint32_t DiffTime_ms_Old = 0;
 	
 	if(GPIO_Pin == SPEED_SENSOR_Pin)
 	{
@@ -159,14 +160,19 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
 		if(MC_SpeedSensorData.IsStopFlag == TRUE)
 		{
 		  MC_SpeedSensorData.TrigSysTime = HAL_GetTick();
-			MC_SpeedSensorData.DiffTime_ms = 0;
+			MC_SpeedSensorData.DiffTime_ms = 0xFFFFFFFF;
 			MC_SpeedSensorData.IsStopFlag = FALSE;
 		}
 		else
 		{
 		  MC_SpeedSensorData.DiffTime_ms = HAL_GetTick() - MC_SpeedSensorData.TrigSysTime;
+			if(MC_SpeedSensorData.DiffTime_ms < 75)//限制车速测量最高值,抗干扰,3600/0.075*2.19/1000 = 105km/h
+			{
+			  MC_SpeedSensorData.DiffTime_ms = DiffTime_ms_Old;
+			}
 			MC_SpeedSensorData.TrigSysTime = HAL_GetTick();
 		}
+		DiffTime_ms_Old = MC_SpeedSensorData.DiffTime_ms;
 		//车轮圈数更新
 		SignalTrigCount++;
 		MC_SpeedSensorData.WheelTurnCount = SignalTrigCount / ((MC_ConfigParam1.SpeedSensorPoles == 0) ? 1: MC_ConfigParam1.SpeedSensorPoles);

BIN
MDK-ARM/bin/MC_VOLANS-TC013054-MB2001-A-V1r1_V2r1r5_20200904.bin


BIN
MDK-ARM/bin/QD007A_CTL_APP.bin


+ 4 - 0
User/Inc/math_tools.h

@@ -3,9 +3,12 @@
 
 #include "stm32f1xx_hal.h"
 #include "math.h"
+#include "string.h"
 
 extern uint16_t MovingAverageFilter(uint16_t InputData, uint16_t* Array, uint16_t Length);
+extern uint16_t MovingMiddleFilter(uint16_t InputData, uint16_t* Array, uint16_t Length);
 extern uint16_t GetAverageData(uint16_t* Input, uint16_t Length);
+extern uint16_t GetMiddleData(uint16_t* Input, uint16_t Length);
 extern uint16_t Function_Linear_3Stage(uint16_t Th1, int16_t K1, uint16_t Th2, int16_t K2, uint16_t InputData);
 extern uint16_t Coefficient_GainCal(uint16_t Min, uint16_t Max, uint16_t Th, uint16_t InputData);
 extern uint16_t TriangleWaveGenerate(uint32_t Time_Zero, uint16_t Time1, uint16_t Time2, uint16_t PeakValue);
@@ -24,4 +27,5 @@ extern int16_t accDecProcess(int16_t V_Set,	\
 											int32_t* V_SetMiddle);
 extern uint16_t Standard_deviation_aver(uint16_t *data,uint8_t len, uint16_t *pAver);
 extern uint8_t CheckArrayIs0(uint8_t* Data, uint16_t Len);
+extern void MinToMax(uint16_t* Input, uint16_t Length);
 #endif

+ 73 - 0
User/Src/math_tools.c

@@ -23,6 +23,29 @@ uint16_t MovingAverageFilter(uint16_t InputData, uint16_t* Array, uint16_t Lengt
 	return Result;
 }
 
+/*
+滑动中值滤波
+InputData:最新采集值
+Array:缓存队列
+Length:缓存大小
+运行一次后,缓存队列最后一个数据为最新采集值,前面数据依次前移,返回值为缓存队列平均值
+*/
+uint16_t MovingMiddleFilter(uint16_t InputData, uint16_t* Array, uint16_t Length)
+{
+	uint16_t Result, i;
+	
+	Result = GetMiddleData(Array, Length);
+	
+	for(i=0; i<(Length - 1); i++)
+	{
+	  Array[i] = Array[i+1];
+	}
+	
+	Array[Length - 1] = InputData;
+
+	return Result;
+}
+
 /*
 取平均值
 Input:输入数组
@@ -43,6 +66,38 @@ uint16_t GetAverageData(uint16_t* Input, uint16_t Length)
 	return Result;
 }
 
+/*
+取中间值
+Input:输入数组
+Length:有效数据长度
+返回值为输入数组平均值 
+*/
+uint16_t GetMiddleData(uint16_t* Input, uint16_t Length)
+{
+  uint16_t i, Result = 0;
+	uint16_t Temp[32];
+	
+	if(Length > 32)
+	{
+	  return 0xFFFF;
+	}
+	
+	for(i = 0; i < Length; i++)
+	{
+	  Temp[i] = Input[i];
+	}
+	MinToMax(Temp, Length);
+	if(Length % 2 == 0)//长度为偶数,取中间两个数的平均值
+	{
+	  Result = (Temp[(Length >> 1) -1] + Temp[Length  >> 1]) >> 1;
+	}
+	else//长度为奇数,取中间数
+	{
+	  Result = Temp[(Length - 1) >> 1];
+	}
+	return Result;
+}
+
 /*
 三段曲线计算
 0< InputData < Th1 :       y = 1 - (Th1 - InputData) * K1
@@ -387,3 +442,21 @@ uint8_t CheckArrayIs0(uint8_t* Data, uint16_t Len)
 	return 0;
 }
 
+/*小到达排序*/
+void MinToMax(uint16_t* Input, uint16_t Len)
+{
+  uint16_t i, j, Temp;
+	for(i=0; i<Len - 1; i++)
+	{
+	  for (j=0; j<Len - 1 - i; j++)
+		{
+			if (Input[j] > Input[j + 1])
+			{
+					Temp = Input[j];
+					Input[j] = Input[j + 1];
+					Input[j + 1] = Temp;//交换
+			}
+		}
+	}
+}
+

+ 2 - 3
User/Src/speed_sensor.c

@@ -60,9 +60,8 @@ void SpeedSensor_Process(MC_SpeedSensorData_Struct_t* p_MC_SpeedSensorData, uint
 			}
 			p_MC_SpeedSensorData->Speed_Data = (uint32_t)WheelSize * 360 / Poles  / p_MC_SpeedSensorData->DiffTime_ms;//单位0.1km/h
 			
-			//滑动均值滤波
-			*AvgResult = MovingAverageFilter(p_MC_SpeedSensorData->Speed_Data, FiltTemp, sizeof(FiltTemp) >> 1);
-			
+			//中值滤波
+			*AvgResult = MovingMiddleFilter(p_MC_SpeedSensorData->Speed_Data, FiltTemp, sizeof(FiltTemp) >> 1);
 			//在确定停止前进行衰减
 			if((HAL_GetTick() - p_MC_SpeedSensorData->TrigSysTime) > (p_MC_SpeedSensorData->DiffTime_ms * 2))
 			{

+ 1 - 1
User/Src/var.c

@@ -490,7 +490,7 @@ void Var_Init(void)
 	//MC版本信息初始化,Mode和SN从EEPROM读取
   strncpy(MC_VerInfo.HW_Version, (char*)"QD007G.         ", 16);
 	strncpy(MC_VerInfo.FW_Version, (char*)"V2r1r5_20200904.", 16);
-	strncpy(Firmware_Special, (char*)"TC013054-MB2001-A-V1.           ", 32);
+	strncpy(Firmware_Special, (char*)"TC013054-MB2001-A-V1r1.         ", 32);
 		
 	//电机型号
 	strncpy(MC_VerInfo.Mode, (char*)"VL6500 & VS7500.", 16);

+ 4 - 0
修改说明.txt

@@ -335,6 +335,10 @@ V2.1.5_20200903
 3、调整Smart档助力体验;
 4、软件版本:2.1.5_20200904 特性说明:TC013054-MB2001-A-V1
 
+2.1.5_20200904 TC013054-MB2001-A-V1r1
+1、车速检测,增加限值处理,提高抗干扰性;
+2、车速滤波采用滑动中值滤波;
+3、软件版本:2.1.5_20200904 特性说明:TC013054-MB2001-A-V1r1