|
最近在写一个PX4飞控板的MS5611测试程序,可是读出来的温度数值都在32度左右,气压在50402.(实际温度在18度,气压在100009这个级别才是)。测试了好多SPI的程序。就是不正确。不知道原因了?看气压曲线,我用手在1.6m上下动,曲线到时对的,温度用嘴吹吹也能上升?可这么大的偏差是咋回事?
void Baro_Init(void)
{
Baro_Cmd_Reset();
Baro_Read_Coe();
}
float Baro_Get_Alt3(void)
{
int64_t OFF2=0;
int64_t SENS2=0;
float altitude;
// uint8_t n_crc; // crc value of the prom
// cmd_reset(); // reset the module after powerup
// uint8_t n_crc; // crc value of the prom
// cmd_reset(); // reset the module after powerup
for (uint8_t i = 0; i < 8; i++){
C[i] = Baro_Cmd_Prom(i);
}
// read calibration coefficients
D1=Baro_Adc(CMD_ADC_D1+CMD_ADC_4096); // read uncompensated pressure
D2=Baro_Adc(CMD_ADC_D2+CMD_ADC_4096); // read uncompensated temperature
// calcualte 1st order pressure and temperature (MS5607 1st order algorithm)
// C[1] = 40127;
// C[2] = 36924;
// C[3] = 23317;
// C[4] = 23282;
// C[5] = 33464;
// C[6] = 28312;
// D1 = 9085466;
// D2 = 8569150;
dT = D2 - (uint32_t)C[5] * 256;
OFF = (int64_t)C[2] * 65536 + (int64_t)C[4] * dT / 128;
SENS = (int64_t)C[1] * 32768 + (int64_t)C[3] * dT / 256;
TEMP = 2000 + ((int64_t) dT * C[6]) / 8388608;
//printf("TEMP is :%ld ",TEMP);
OFF2 = 0;
SENS2 = 0;
if (TEMP < 2000)
{
OFF2 = 5 * ((TEMP - 2000) * (TEMP - 2000)) / 2;
SENS2 = 5 * ((TEMP - 2000) * (TEMP - 2000)) / 4;
}
if (TEMP < -1500)
{
OFF2 = OFF2 + 7 * ((TEMP + 1500) * (TEMP + 1500));
SENS2 = SENS2 + 11 * ((TEMP + 1500) * (TEMP + 1500)) / 2;
}
OFF = OFF - OFF2;
SENS = SENS - SENS2;
P = (D1 * SENS / 2097152 - OFF) / 32768;
//printf("P is :%ld \r\n ",P);
printf("%ld\r\n",P);
//altitude = (((pow((P / p1), (-(A * RR) / g))) * T1) - T1) / A;
//printf("altitude is :%f\r\n",altitude);
return altitude;
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|