07-13-2019 02:18 AM - edited 07-13-2019 02:21 AM
BMP38x self-test v1.1.3 appears to suffer from multiple bugs.
Bug 1 - Inappropriate plausible temperature range
The maximum plausible temperature is defined as 40 degC on line 54 of bmp38x_selftest.c. The BMP388 datasheet specifies an operating temperature up to 85 degC. In practise, operating temperatures will often exceed 40 degC due to warm climates and/or heat generated by electronics.
Bug 2 - Scaling errors for BMP3_DOUBLE_PRECISION_COMPENSATION
If using BMP3_DOUBLE_PRECISION_COMPENSATION then the self-test will always fail with BMP3_IMPLAUSIBLE_PRESSURE due to scaling errors. This is because the API will provide measurements in units of degC and 100*hPa but the API defines the plausible ranges in units of 100*degC and 100*100*hPa (scaled once in definition and then again within if statement). I suggest the issue is fixed by defining different plausible limits when BMP3_DOUBLE_PRECISION_COMPENSATION is defined.
Bug 3 - Corrupted variables when not using BMP3_DOUBLE_PRECISION_COMPENSATION
This issue can be demonstrated by printing the measurement values inside the internal function, analyze_sensor_data, on line 185 of bmp38x_selftest.c as shown below.
static int8_t analyze_sensor_data(const struct bmp3_data *sens_data)
{
int8_t rslt = BMP3_SENSOR_OK;
// **************** START OF DEBUG CODE ****************
#ifdef BMP3_DOUBLE_PRECISION_COMPENSATION
printf("t=%f, p=%f\r\n", sens_data->temperature, sens_data->pressure);
#else
printf("t=%ld, p=%lu\r\n", (long int)sens_data->temperature, (long unsigned int)sens_data->pressure);
#endif
// **************** END OF DEBUG CODE ****************
if ((sens_data->temperature < BMP3_MIN_TEMPERATURE) || (sens_data->temperature > BMP3_MAX_TEMPERATURE))
{
rslt = BMP3_IMPLAUSIBLE_TEMPERATURE;
}
if (rslt == BMP3_SENSOR_OK)
{
if ((sens_data->pressure / 100 < BMP3_MIN_PRESSURE) || (sens_data->pressure / 100 > BMP3_MAX_PRESSURE))
{
rslt = BMP3_IMPLAUSIBLE_PRESSURE;
}
}
return rslt;
}
If using BMP3_DOUBLE_PRECISION_COMPENSATION then the above modification will result in the following typical output:
t=58.103809, p=101310.782827
If not using BMP3_DOUBLE_PRECISION_COMPENSATION then the above modification will result in the following typical output:
t=1, p=5752
It appears that the pressure value is the temperature measurement (100*degC), and the temperature value is always 1. This corruption only occurs within the function, analyze_sensor_data. There are no issues with values obtained using the function, bmp3_get_sensor_data.
Solved! Go to Solution.
07-15-2019 10:49 AM - edited 07-15-2019 10:59 AM
Hi sebmadgwick,
Thank you for your feedback, I shall report these issues immediately.
Regarding bug#1 : This "plausible" temperature and pressure range and is to be modified by the end customer depending on the specific range for the test facility. For example, a customer in Denver would expect the pressure to be much lower due to altitude.
bug #2 an #3 will be investigated.
07-15-2019 10:03 PM
Thank you for the quick response.
A preferable solution to bug#2 is to calculate local variables with the correct scaling as shown below. This requires fewer lines of code, avoids mixing types, and avoids duplicate definitions of the plausible limits.
static int8_t analyze_sensor_data(const struct bmp3_data *sens_data)
{
int8_t rslt = BMP3_SENSOR_OK;
#ifdef BMP3_DOUBLE_PRECISION_COMPENSATION
int16_t temperature = sens_data->temperature * 100.0;
uint32_t pressure = sens_data->pressure * 100.0;
#else
int16_t temperature = sens_data->temperature;
uint32_t pressure = sens_data->pressure;
#endif
if ((temperature < BMP3_MIN_TEMPERATURE) || (temperature > BMP3_MAX_TEMPERATURE))
{
rslt = BMP3_IMPLAUSIBLE_TEMPERATURE;
}
if (rslt == BMP3_SENSOR_OK)
{
if ((pressure / 100 < BMP3_MIN_PRESSURE) || (pressure / 100 > BMP3_MAX_PRESSURE))
{
rslt = BMP3_IMPLAUSIBLE_PRESSURE;
}
}
return rslt;
}
07-15-2019 10:10 PM - edited 07-15-2019 10:11 PM
Please ignore bug#3. I am no longer able to replace this issue for reasons unknown.
Self test now works correctly but the above fix (for bug#2) is required if using BMP3_DOUBLE_PRECISION_COMPENSATION.
07-16-2019 11:12 AM
Bug 1---In the datasheet, the temperature mentioned from -40 to 85 is the operating temperature range for the sensor. During the selftest, the temperature will not exceed 40 as in the API because temperature during the production line higher than 40 is not acceptable.
Bug 2--- Thanks for feedback,the API unit definition error will send back to internal team for analysis.
Bug 3--- As mentioned in the question, the no issues with values obtained using the function, bmp3_get_sensor_data which means the sensor data from sensor API is correct. Therefore, it is not possible to have this error during the selftest. Because the selftest just get data from the sensor API, then analysis it. Only the reason for this issue is from the debug code printf("t=%ld, p=%lu\r\n", (long int)sens_data->temperature, (long unsigned int)sens_data->pressure);