Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    why BMI270 accel sensor data output rate not accuracy with settings

    why BMI270 accel sensor data output rate not accuracy with settings

    Silva_L
    New Poster

    My target is to get bmi270 accel raw data output@100Hz( the code as the picture below following official BMI270 driver soure code), but the time interval between two sample time points is not so accuracy(10ms is normal), sometime is 11ms, 15ms, 20 ms for instance, not all 10ms. How could i configure the  accel sensor to achieve standard 100Hz output rate?

     

    • the accel sensor configuration:
    static int8_t set_accel_config(struct bmi2_dev *bmi2_dev)
    {
        /* Status of api are returned to this variable. */
        int8_t rslt;

        /* Structure to define accelerometer configuration. */
        struct bmi2_sens_config config;
        /* Configure the type of feature. */
        config.type = BMI2_ACCEL;
        /* Get default configurations for the type of feature selected. */
        rslt = bmi270_get_sensor_config(&config, 1, bmi2_dev);
        bmi2_error_codes_print_result(rslt);
        if (rslt == BMI2_OK)
        {
            /* NOTE: The user can change the following configuration parameters according to their requirement. */
            /* Set Output Data Rate */
            config.cfg.acc.odr = BMI2_ACC_ODR_100HZ;
            /* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
            config.cfg.acc.range = BMI2_ACC_RANGE_2G;

            /* The bandwidth parameter is used to configure the number of sensor samples that are averaged
             * if it is set to 2, then 2^(bandwidth parameter) samples
             * are averaged, resulting in 4 averaged samples.
             * Note1 : For more information, refer the datasheet.
             * Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
             * this has an adverse effect on the power consumed.
             */
            config.cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;

            /* Enable the filter performance mode where averaging of samples
             * will be done based on above set bandwidth and ODR.
             * There are two modes
             *  0 -> Ultra low power mode
             *  1 -> High performance mode(Default)
             * For more info refer datasheet.
             */
            config.cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;

            /* Set the accel configurations. */
            rslt = bmi270_set_sensor_config(&config, 1, bmi2_dev);
            bmi2_error_codes_print_result(rslt);

            /* Map data ready interrupt to interrupt pin. */
            rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
            bmi2_error_codes_print_result(rslt);
        }

        return rslt;
    }

     

    • the accel sensor reading loop:
               while(1)
                {
                    /* To get the status of accel data ready interrupt. */
                    rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
                    bmi2_error_codes_print_result(rslt);

                    /* To check the accel data ready interrupt status and print the status for 10 samples. */
                    if (int_status & BMI2_ACC_DRDY_INT_MASK)
                    {
                        /* Get accelerometer data for x, y and z axis. */
                        rslt = bmi270_get_sensor_data(&sensor_data, 1, &bmi2_dev);
       
                        bmi2_error_codes_print_result(rslt);
                       
                        /* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
                        x = lsb_to_mps2(sensor_data.sens_data.acc.x, 2, bmi2_dev.resolution);
                        y = lsb_to_mps2(sensor_data.sens_data.acc.y, 2, bmi2_dev.resolution);
                        z = lsb_to_mps2(sensor_data.sens_data.acc.z, 2, bmi2_dev.resolution);

                        /* Print the data in m/s2. */
                        printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
                       
                        printf(" [sensor_debug] get the acc status value = 0x%x , timestamp = %ld \n", data_out, current_timestamp);
                    }
                }

     

     

     

    5 REPLIES 5

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Silva_L,

    You could directly read sensor data by interrupt, not poll data.
    Refer attachment example code, enable this macro definition:
    #define RDRY_INT

    Hi Robin, 

    Thanks for your info, will try it.

    BTW, what is the root cause in my 100Hz accel data polling read demo?  I just copy the accel read process from https://github.com/BoschSensortec/BMI270-Sensor-API/blob/master/bmi270_examples/accel/accel.c

    and implement in linux platfrom.

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Silva_L,

    The reference code uses the poll method to check the status bit and read the data. The interrupt method has better real-time performance, so I suggest using the interrupt method. Once the data is ready, the interrupt can respond quickly.

    Hi Robin,

    because my PCB design, i have not connect the BMI270 interrupt pin with MCU, thus could not use hardware interrupt.

    I have to use poll method to check the status bit and read the data following the reference code. The reference code have bugs? or i can try the data ready latch mode. any suggestion?

    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