气压计1s读一次,过采样率128,测量成功

This commit is contained in:
lmx
2025-12-10 19:17:54 +08:00
parent d92818a894
commit 5ecd42b5cf
9 changed files with 32 additions and 551 deletions

View File

@ -129,7 +129,7 @@ void sensor_collect_task(void){
while(1){//4组地磁数据、16组六轴数据、1组气压计数据
interval++;
mmc5603nj_read_mag_data(&mmc5603nj_buffer);
mmc5603nj_read_mag_data(&mmc5603nj_buffer); //地磁的采样率为100Hz每10ms读一次
for(int i = (interval-1)*4; i < interval*4; i++){
send_data.sensor_package[i].mmc5603nj_buffer[0] = (int32_t)(mmc5603nj_buffer.x * 1000.0f);
send_data.sensor_package[i].mmc5603nj_buffer[1] = (int32_t)(mmc5603nj_buffer.y * 1000.0f);
@ -165,11 +165,11 @@ void sensor_collect_task(void){
SL_data_index += MPU_FIFO_LEN/4;
if(interval >= 4){
if(interval >= 4){ //40ms
interval = 0;
SL_data_index = 0;
#if BMP280
bmp280_read_data(&temperature, &pressure);//每40ms读取一次
bmp280_read_data(&temperature, &pressure);//每40ms读取一次高精度的采样率为26.5Hz
#else
WF_GET_Temperature_Pressure(&temperature, &pressure);
#endif
@ -178,7 +178,7 @@ void sensor_collect_task(void){
send_data.sensor_package[i].pressure = (int32_t)(pressure * 1000.0f);
}
xlog("temperature: %.2f,pressure: %.2f\n",temperature,pressure);
// xlog("temperature: %.2f,pressure: %.2f\n",temperature,pressure);
// xlog("fifo_num:%d\n",fifo_num);
send_data.checkout_1 = 0xBE;
@ -454,7 +454,7 @@ void sensor_test_task(void){
while(1){
WF_GET_Temperature_Pressure(&temperature, &pressure);
xlog("temperature: %.3f,pressure: %.3f\n",temperature,pressure);
os_time_dly(40);
os_time_dly(100);
}
}

View File

@ -150,7 +150,7 @@ uint8_t WF_Init() {
xlog("Parsed Coefficients: c0=%d, c1=%d, c00=%ld, c10=%ld, c01=%d, c11=%d, c20=%d, c21=%d, c30=%d\n",
c0, c1, c00, c10, c01, c11, c20, c21, c30);
#if 1 //连续测量
#if 0 //连续测量
// 配置压力、温度和通用寄存器为连续测量模式
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_32 << 4) | PM_PRC_1); //reg: 0x06
// 温度配置: 内部传感器 (TMP_INT_SENSOR), 32Hz测量速率 (TMP_RATE_32), 16x过采样 (TMP_PRC_16) -> 0x54
@ -165,7 +165,7 @@ uint8_t WF_Init() {
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_1 << 4) | PM_PRC_128); //reg: 0x06压力
wf282a_write_reg(WF_TMP_CFG, TMP_EXT_SENSOR | (TMP_RATE_1 << 4) | TMP_PRC_128); //reg: 0x07温度
//过采样率大于8要对移位置配置1
// wf282a_write_reg(WF_CFG_REG, 0x0C); //reg: 0x09
wf282a_write_reg(WF_CFG_REG, 0x0C); //reg: 0x09
delay(40); // 稍长一点的延迟,确保传感器开始正常工作
#endif
@ -193,25 +193,34 @@ uint8_t WF_GetID() {
//外部调用
void WF_GET_Temperature_Pressure(float* temperature, float* precessure){
#if 0 //单词测量模式
#if 0 //连续测量模式
int32_t Traw = Get_Traw();
xlog("DEBUG: Traw = %ld\n", Traw);
delay(5);
int32_t Praw = Get_Praw();
xlog("DEBUG: Praw = %ld\n", Praw);
#else //单次测量
wf282a_write_reg(WF_MEAS_CFG, 0x02); //内部进行一次温度测量
delay(200);
delay(500);
int32_t Traw = Get_Traw();
xlog("DEBUG: Traw = %ld\n", Traw);
wf282a_write_reg(WF_MEAS_CFG, 0x01); //内部进行一次压力测量
delay(200);
int32_t Praw = Get_Praw();
#else
int32_t Traw = Get_Traw();
delay(500);
int32_t Praw = Get_Praw();
xlog("DEBUG: Praw = %ld\n", Praw);
#endif
float Traw_sc = (float)Traw / KT; // 缩放原始温度值
float Praw_sc = (float)Praw / KP; // 缩放原始压力值
float Traw_sc = (float)Traw / KT; // 缩放原始温度值
double Praw_sc = (double)Praw / KP; // 缩放原始压力值
double precessure_tmp = 0;
*temperature = (float)c0 * 0.5f + (float)c1 * Traw_sc;
*precessure = (float)c00
+ Praw_sc * ((float)c10 + Praw_sc * ((float)c20 + Praw_sc * (float)c30))
+ Traw_sc * (float)c01
+ Traw_sc * Praw_sc * ((float)c11 + Praw_sc * (float)c21);
precessure_tmp = (double)c00
+ Praw_sc * ((double)c10 + Praw_sc * ((double)c20 + Praw_sc * (double)c30))
+ Traw_sc * (double)c01
+ Traw_sc * Praw_sc * ((double)c11 + Praw_sc + (double)c21);
xlog("temperature:%.3f,precessure: %.3f\n",*temperature, precessure_tmp);
*precessure = (float)precessure_tmp; // 传出
}
float WF_Altitude_Calculate() {
float pressure_pa = WF_Pressure_Calculate();

View File

@ -14,8 +14,8 @@ Oversampling Rate Scale Factor (kP or kT)
64 times (High Precision) 1040384
128 times 2088960
*/
#define KT 524288.0f
#define KP 524288.0f
#define KT 1572864.0f
#define KP 1572864.0f
#define WF_PULL_UP 0 //外部是否接的上拉
// I2C 从设备地址