Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMP3 sensor API: computation error in T/P compensation functions (integer version)

    BMP3 sensor API: computation error in T/P compensation functions (integer version)

    jbi
    New Poster

    Hi all,
    I compiled a test setup for the BMP388 on a 16-bit MCU. Sensor readout worked fine, but the compensated temperature and pressure readings were far off (142 instead of 25 degrees). Then I defined BMP3_DOUBLE_PRECISION_COMPENSATION, which solved the issue: temp and pressure readings were good.
    Investigation a bit, I came to the conclusion that the error is in the temp/pressure compensation functions (integer version) in bmp3.c.

    In bmp3.c, static int64_t compensate_temperature(), line 2452:

    partial_data1 = ((int64_t)uncomp_data->temperature - (256 * calib_data->reg_calib_data.par_t1));


    This computation caused an overflow on my 16-bit MCU, because 256 was promoted as int16_t. On a 32-bit MCU, there probably is no overflow occurring, because 256 would be promoted as int32_t. I guess the function was tested on a 32-bit architecture.

    I solved the issue by changing explicitely declaring the literal as int32_t:

    partial_data1 = ((int64_t)uncomp_data->temperature - ((int32_t)256 * calib_data->reg_calib_data.par_t1));

    There are more literals affected further below: lines 2494, 2495:

    partial_data5 = (reg_calib_data->par_p2 - (int32_t)16384) * reg_calib_data->t_lin * 2097152;
    sensitivity = ((reg_calib_data->par_p1 - (int32_t)16384) * 70368744177664) + partial_data2 + partial_data4 + partial_data5;

    I don't know how to solve this issue properly to make the API portable, but I think it should be addressed by the Bosch experts.

    Thanks

     

    4 REPLIES 4

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi,

    Thanks for your feedback. We will look into the API code for 16-bit MCU to see if there is any overflow issue or not.

    Thanks.

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi,

    Just to let you know that this overflow is a known API issue in BMP3 API. It has been fixed on API v2.0.3. Please make sure you use the BMP3 API version >= v2.0.3 on the Github.

    Thanks.

    Thanks for resolving this issue. However, I can't find v2.0.3 on Github. Will it be published soon?

    Thanks!

    FAE_CA1
    Community Moderator
    Community Moderator

    Right, the new BMP3 API  v2.0.3 will be published soon on the Github. Thanks.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist