重写大气压采集,添加了平均滤波,去除一个最大最小值求10次采集的平均,避免了偶尔一次采集不到数据造成的大气压为0的BUG

This commit is contained in:
95384 2024-11-09 09:25:43 +08:00
parent 82330e7bc6
commit e71ef7ec06
5 changed files with 63 additions and 26 deletions

View File

@ -685,11 +685,11 @@ void my_update_mcs_param(float new_wind_speed, float new_wind_dirction)
}
//默认第一个数据为最大或者最小
float temp_min_direction = win_10min.ave_direction_data[0];
float temp_max_direction = win_10min.ave_direction_data[0];
float temp_min_speed = win_10min.ave_speed_data[0];
float temp_max_speed = win_10min.ave_speed_data[0];
//统计
float temp_min_direction = win_10min.direction_data[0];
float temp_max_direction = win_10min.direction_data[0];
float temp_min_speed = win_10min.speed_data[0];
float temp_max_speed = win_10min.speed_data[0];
//遍历10min内所有数据寻找最大最小
for (int i = 0; i < win_10min.count; i++) {
if (win_10min.direction_data[i] < temp_min_direction) {
temp_min_direction = win_10min.direction_data[i]; // 更新风向最小值
@ -741,7 +741,7 @@ void tem_hum_update_task(void const * argument)
my_update_mcs_param(av_speed, av_angle);
//采集HP203B数据(大气压)
Hp203bReadPressure();
get_press_data();
}
}

View File

@ -1,5 +1,6 @@
#include "hp203b.h"
#include "i2c.h"
#include "filter.h"
#include "anemometer_dev.h"
@ -26,10 +27,11 @@ void hp203_set_mode()
*
*·µ»Ø£ºÎÞ
*****************************/
float Hp203bReadPressure(void)
{
float ret = 0.0;
long Hp203b_Pressure = 0;
uint8_t Hp203bPressure_Temp[3] = {0};
void Hp203bReadPressure(void)
{
uint8_t read_command[1] = {HP20X_READ_P};
HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, read_command, 1, 0xff);
@ -42,7 +44,40 @@ void Hp203bReadPressure(void)
Hp203b_Pressure |= Hp203bPressure_Temp[2];
Hp203b_Pressure = Hp203b_Pressure / 100;
g_stMcs_Para.pressure = Hp203b_Pressure;
ret = Hp203b_Pressure;
return ret;
}
/****************************
*get_press_data
*
*Press--
*
*
*
*****************************/
#define COLLECT_PRESS_DATA_NUM 10
BOOL get_press_data(void)
{
U_DataType collect_pressure[30]={0x00};
for(int i=0; i<COLLECT_PRESS_DATA_NUM; i++){
collect_pressure[i].fValue = Hp203bReadPressure();
osDelay(1);
}
U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_PRESS_DATA_NUM, FILTER_DATA_TYPE_FLOAT);
if(tmp_press.fValue < 300)
{
tmp_press.fValue = 300;
return FALSE;
}
if(tmp_press.fValue > 1200)
{
tmp_press.fValue = 1200;
return FALSE;
}
g_stMcs_Para.pressure = tmp_press.fValue;
return TRUE;
}

View File

@ -7,6 +7,7 @@ extern "C" {
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "comm_types.h"
#define IIC_SDA_PIN GPIO_PIN_4
#define IIC_SDA_PORT GPIOB
@ -24,7 +25,8 @@ extern "C" {
#define HP20X_CONVERT_OSR1024 0x48
void hp203_set_mode();
void Hp203bReadPressure(void);
float Hp203bReadPressure(void);
BOOL get_press_data(void);
#ifdef __cplusplus

File diff suppressed because one or more lines are too long

View File

@ -30,7 +30,7 @@
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
</ArmDriver>
<DebugChecksum>
<Checksum>3487728483</Checksum>
<Checksum>1821370641</Checksum>
</DebugChecksum>
<Exceptions>
<StopOnUncaught>_ 0</StopOnUncaught>