123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "gas_sensor.h"
- #include "math_tools.h"
- uint16_t GasSensor_OffSet = 0;
- #define ZeroOffSetData 100
- //指拨零点值初始化
- void GasSensorOffSet_Init(uint16_t* OffSet, uint16_t AdcData)
- {
- *OffSet = AdcData + ZeroOffSetData;
- }
- //指拨零点值更新
- void GasSensorOffSetData_Update(uint16_t* PresentData, uint16_t AdcData, MC_ErrorCode_Struct_t* p_MC_ErrorCode)
- {
- static uint16_t Array[50];
- static TrueOrFalse_Flag_Struct_t IsArrayFullFalg = FALSE;
- uint8_t i = 0;
- uint16_t TempData;
- static uint32_t ErrorDelayTimeCnt = 0;
-
- //刚开机时,数组未存满
- if(IsArrayFullFalg == FALSE)
- {
- Array[i++] = AdcData;
- if(i >= 50)
- {
- IsArrayFullFalg = TRUE;
- i = 0;
- }
- }
- //存满后取滑动均值
- else
- {
- TempData = MovingAverageFilter(AdcData, Array, sizeof(Array) / 2) + ZeroOffSetData;
- if(TempData < *PresentData)
- {
- //更新零点值
- *PresentData = TempData;
- }
- }
- //判断零点是否超出范围
- if(*PresentData <= 1500)
- {
- ErrorDelayTimeCnt = HAL_GetTick();
- p_MC_ErrorCode->ERROR_Bit.Fault_GasSensor = 0;
- }
- if((HAL_GetTick() - ErrorDelayTimeCnt) > 10000)
- {
- p_MC_ErrorCode->ERROR_Bit.Fault_GasSensor = 1;
- }
- }
|