Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMA456 offset compensation

    BMA456 offset compensation

    Andy_253
    New Poster

    Hi,

    I use the BMA456 sensor.

    I would like to use the API bma4_perform_accel_foc, for calculating the foc for all 3 axis - x,y,z.

    (I got a code from git hub)

    The API recieves the struct : bma4_accel_foc_g_value.

    I thought to declare - const struct bma4_accel_foc_g_value accel_g_value = {1, 1, 1, 0},  so all three axis will be calculated, but in the API code I see the following condition :

    if (((ABS(accel_g_value->x) + ABS(accel_g_value->y) + ABS(accel_g_value->z)) == 1) &&
    ((accel_g_value->sign == 1) || (accel_g_value->sign == 0)))

    which makes me think I should call one axis at a time (also in related APIs  it seems like that).

    but if so - will it be saved corrctly at the NVM? won't each call run over the previous values? 

    I don't understand what is the proper input to the accel_g_value

    Thanks in advance,

    14 REPLIES 14

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Andy_253,

    It is impossible to get average data -4147 of x axis, because of default sensor range is 4G, typical maxmum LSB data is 8192.

    output signal.png

    Please refer the code and compare it with yours. Ensure your board is positive placement and keep horizontal.

    main()

    {

    ...

    /* Function to select interface between SPI and I2C, according to that the device structure gets updated */
    rslt = bma4_interface_selection(&dev);
    bma4_error_codes_print_result("bma4_interface_selection status", rslt);

    /* Initialize BMA456 */
    rslt = bma456_init(&dev);
    bma4_error_codes_print_result("bma456_init status", rslt);

    #if defined(FOC)
    BMA456_Do_FOC(&dev);
    #endif

    ...

    }

    int8_t BMA456_Do_FOC(struct bma4_dev *dev)
    {
    struct bma4_accel_foc_g_value accel_g_value = {0, 0, 1, 0};

    /*Do FOC for X,Y,Z axis*/
    PDEBUG("Start to do FOC...\r\n");
    if(bma4_perform_accel_foc(&accel_g_value, dev) == BMA4_OK)
    {
    PDEBUG("Do FOC success\r\n");
    }
    else
    {
    PDEBUG("Do FOC failed\r\n");
    }
    PDEBUG("End to do FOC\r\n");
    }

    And you could print offset value before writing to offset register.

    static int8_t perform_accel_foc(const struct bma4_accel_foc_g_value *accel_g_value,
    const struct bma4_accel_config *acc_cfg,
    struct bma4_dev *dev)

    {

    ...

    PDEBUG("offset x=%d, y= %d, z=%d\r\n", offset.x, offset.y, offset.z);

    /* Write offset data in the offset compensation register */
    rslt = write_bma4_accel_offset(&offset, dev);

    ...

    }

     

    Hi BSTRobin,

    I set the range to 8G. In this case, Is it possible to have a -4147 average?( I don't think that)

    and I understood that If the range is 8G, each of axis value range is -4096 ~ + 4096. Is it wrong?

    I don't understand well, What mg range each axis can have according to the setting(4G,8G 16G etc)

    Thanks for your support

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Andy_253,

    In the code of bma4_perform_accel_foc(), it uses 4G range to do FOC test, what is the purpose you set sensor range to 8G?

    Hi BSTRobin,

    Thank you for your reply.

    I didn't think bma4_perform_accel_foc() function is for only 4G. Because There is code to get exactly Acc range.

    And I applied the 8G for self-test too.

    plus, I had applied the 8G range for getting acc data on BMA253 sensor(My company decided to change the sensor BMA253 to BMA455 & BMA456)

    So I try to apply the same implementation to BMA456.

    Anyway, I will change the range to 4G and test it again  next year(I will holiday from today)

    Thank you for your support and Let you know result after testing

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Andy_253,

    bma4_perform_accel_foc() do FOC test with default 4g range. Of course, you could modify the code in bma4_perform_accel_foc() to other range for FOC test.

    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