提交一种稳定浓度标定方法,和报警恢复降低阈值措施
This commit is contained in:
parent
8e5ab00fc4
commit
d72beaeaae
|
@ -2,8 +2,8 @@
|
||||||
* @Author: mbw
|
* @Author: mbw
|
||||||
* @Date: 2024-10-23 17:14:16
|
* @Date: 2024-10-23 17:14:16
|
||||||
* @LastEditors: mbw && 1600520629@qq.com
|
* @LastEditors: mbw && 1600520629@qq.com
|
||||||
* @LastEditTime: 2025-06-01 08:35:48
|
* @LastEditTime: 2025-06-04 08:54:13
|
||||||
* @FilePath: \1\ble_-tyq_-bjq_-ch32-v303\applications\main.c
|
* @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c
|
||||||
* @Descrt_thread_
|
* @Descrt_thread_
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
* Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
||||||
|
@ -27,6 +27,8 @@
|
||||||
#include "bsp_vin_detection.h"
|
#include "bsp_vin_detection.h"
|
||||||
#include "user_sys.h"
|
#include "user_sys.h"
|
||||||
#include "bsp_bt.h"
|
#include "bsp_bt.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
|
||||||
#define LOG_TAG "main"
|
#define LOG_TAG "main"
|
||||||
#define LOG_LVL LOG_LVL_DBG
|
#define LOG_LVL LOG_LVL_DBG
|
||||||
|
@ -162,10 +164,40 @@ void Preheat_Timer_Callback (void *parameter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define STABLE_THRESHOLD 0.01f // 1%波动视为稳定
|
||||||
|
|
||||||
|
uint16_t Get_Stable_Reading(uint8_t cnt, uint32_t timeout_ms)
|
||||||
|
{
|
||||||
|
uint32_t start = rt_tick_get();
|
||||||
|
uint16_t last = Get_Gas_VoltageAdcInt1000x();
|
||||||
|
uint16_t current;
|
||||||
|
uint8_t stable_count = 0;
|
||||||
|
|
||||||
|
while ((rt_tick_get() - start) < timeout_ms)
|
||||||
|
{
|
||||||
|
current = Get_Gas_VoltageAdcInt1000x();
|
||||||
|
|
||||||
|
float diff = fabs((float)(current - last) / last);// 差值
|
||||||
|
if (diff < STABLE_THRESHOLD)
|
||||||
|
{
|
||||||
|
stable_count++;
|
||||||
|
if (stable_count >= cnt) return current; // 连续n次稳定
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stable_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
last = current;
|
||||||
|
rt_thread_mdelay(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; // 超时
|
||||||
|
}
|
||||||
|
|
||||||
|
/*标定函数*/
|
||||||
int APP_Calibration_Handle(void)
|
int APP_Calibration_Handle(void)
|
||||||
{
|
{
|
||||||
uint8_t i = 0;
|
|
||||||
uint16_t gas_buf[10] = {0};
|
|
||||||
uint32_t gas_calibration_voltage = 0;
|
uint32_t gas_calibration_voltage = 0;
|
||||||
|
|
||||||
// if (Get_Gas_VoltageAdcInt1000x() > 400 && Get_Gas_VoltageAdcInt1000x() < 900)
|
// if (Get_Gas_VoltageAdcInt1000x() > 400 && Get_Gas_VoltageAdcInt1000x() < 900)
|
||||||
|
@ -193,8 +225,11 @@ int APP_Calibration_Handle (void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Calibration_flag = 1;
|
Calibration_flag = 1;
|
||||||
while (1)
|
uint8_t calibration_buf[2] = {0};
|
||||||
{
|
/* 获取10个数据 */
|
||||||
|
#if 0
|
||||||
|
uint8_t i = 0;
|
||||||
|
uint16_t gas_buf[10] = {0};
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
gas_buf[i] = Get_Gas_VoltageAdcInt1000x();
|
gas_buf[i] = Get_Gas_VoltageAdcInt1000x();
|
||||||
|
@ -207,8 +242,8 @@ int APP_Calibration_Handle (void)
|
||||||
}
|
}
|
||||||
if (i == 10)
|
if (i == 10)
|
||||||
{
|
{
|
||||||
gas_calibration_voltage = (uint16_t)gas_calibration_voltage / 10;
|
gas_calibration_voltage = (uint16_t)(gas_calibration_voltage / 10);
|
||||||
uint8_t calibration_buf[2] = {0};
|
|
||||||
calibration_buf[0] = gas_calibration_voltage & 0xFF; // 低字节
|
calibration_buf[0] = gas_calibration_voltage & 0xFF; // 低字节
|
||||||
calibration_buf[1] = (gas_calibration_voltage >> 8) & 0xFF; // 高字节
|
calibration_buf[1] = (gas_calibration_voltage >> 8) & 0xFF; // 高字节
|
||||||
LOG_D("calibration_buf[0] = %X calibration_buf[1] = %X", calibration_buf[0], calibration_buf[1]);
|
LOG_D("calibration_buf[0] = %X calibration_buf[1] = %X", calibration_buf[0], calibration_buf[1]);
|
||||||
|
@ -226,7 +261,31 @@ int APP_Calibration_Handle (void)
|
||||||
LOG_E("标定错误");
|
LOG_E("标定错误");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
gas_calibration_voltage = Get_Stable_Reading(5, 10000);//10s内连续5次稳定,则认为其标定浓度稳定,进行标定
|
||||||
|
if(gas_calibration_voltage == 0)
|
||||||
|
{
|
||||||
|
LOG_D("标定超时,标定错误");
|
||||||
|
Send_Laser_Alarm_Event(kNotCalibratedEvent);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
calibration_buf[0] = gas_calibration_voltage & 0xFF; // 低字节
|
||||||
|
calibration_buf[1] = (gas_calibration_voltage >> 8) & 0xFF; // 高字节
|
||||||
|
LOG_D("calibration_buf[0] = %X calibration_buf[1] = %X", calibration_buf[0], calibration_buf[1]);
|
||||||
|
Flash_Sys_Cfg(kAlarmLValueId, calibration_buf, 2);
|
||||||
|
LOG_D("标定完成");
|
||||||
|
Calibration_flag = 0;
|
||||||
|
Flash_Set_Calibration_State(kSysGasCalibStatus);
|
||||||
|
g_Calibration_status = kSysGasCalibStatus;
|
||||||
|
Send_Laser_Alarm_Event(kNormalDetectionEvents);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -253,7 +312,6 @@ int main (void)
|
||||||
}
|
}
|
||||||
BSP_VIN_Detection_Init();
|
BSP_VIN_Detection_Init();
|
||||||
|
|
||||||
|
|
||||||
rt_err_t result = RT_EINVAL;
|
rt_err_t result = RT_EINVAL;
|
||||||
rt_uint32_t received_event;
|
rt_uint32_t received_event;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author : stark1898y 1658608470@qq.com
|
* @Author : stark1898y 1658608470@qq.com
|
||||||
* @Date : 2024-06-18 15:48:01
|
* @Date : 2024-06-18 15:48:01
|
||||||
* @LastEditors: mbw && 1600520629@qq.com
|
* @LastEditors: mbw && 1600520629@qq.com
|
||||||
* @LastEditTime: 2025-02-21 11:27:34
|
* @LastEditTime: 2025-06-04 09:10:59
|
||||||
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_mq.c
|
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_mq.c
|
||||||
* @Description :
|
* @Description :
|
||||||
*
|
*
|
||||||
|
@ -118,7 +118,15 @@ static uint8_t Sensor_CheckData(void)
|
||||||
static rt_uint8_t fault_buf[SENSOR_SAMPLING_TIMS] = {0};
|
static rt_uint8_t fault_buf[SENSOR_SAMPLING_TIMS] = {0};
|
||||||
rt_uint16_t voltage = Get_Gas_VoltageAdcInt1000x();
|
rt_uint16_t voltage = Get_Gas_VoltageAdcInt1000x();
|
||||||
|
|
||||||
|
if(alarm_flag)
|
||||||
|
{
|
||||||
|
alarm_status_buffer[index] = ((voltage > Sensor_device.alarm_value - 50) && (voltage < MQ_VOLTAGE_HIGH_LIMIT)) ? kSensorAlarm : kSensorNormal;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
alarm_status_buffer[index] = ((voltage > Sensor_device.alarm_value) && (voltage < MQ_VOLTAGE_HIGH_LIMIT)) ? kSensorAlarm : kSensorNormal;
|
alarm_status_buffer[index] = ((voltage > Sensor_device.alarm_value) && (voltage < MQ_VOLTAGE_HIGH_LIMIT)) ? kSensorAlarm : kSensorNormal;
|
||||||
|
}
|
||||||
|
|
||||||
fault_buf[index] = ((voltage < MQ_VOLTAGE_LOW_LIMIT) || (voltage > MQ_VOLTAGE_HIGH_LIMIT)) ? kSensorFault : kSensorNormal;
|
fault_buf[index] = ((voltage < MQ_VOLTAGE_LOW_LIMIT) || (voltage > MQ_VOLTAGE_HIGH_LIMIT)) ? kSensorFault : kSensorNormal;
|
||||||
index++;
|
index++;
|
||||||
if (index >= SENSOR_SAMPLING_TIMS)
|
if (index >= SENSOR_SAMPLING_TIMS)
|
||||||
|
|
Loading…
Reference in New Issue