Bosch Sensortec Community

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

    BHI160 sensor library usage

    BHI160 sensor library usage

    owain-incus
    Established Member

    Hi,

    we are usign BHI160 and  bhy sensor library.

    I am trying to understand the configuration we are using on the physical and virtual sensor; hence I have patched in some routines to dump what i think is correct info. I find data sheets and documentation a little confusing about what these config numbers mean.

    void start_bhy_accelerometer_sensor(int8_t sampling_rate_accelerometer)
    {
    BHY_RETURN_FUNCTION_TYPE result = BHY_ERROR;
    u16 sr, mrl, cs, dr;
    if( BHY_SUCCESS == bhy_get_wakeup_sensor_configuration( VS_TYPE_ACCELEROMETER, &sr, &mrl, &cs, &dr ) ){
    NRF_LOG_INFO("IAC:SR:%d,MRL:%d,CS:%d, DR:%d", sr, mrl, cs, dr);
    }else{
    NRF_LOG_INFO("IAC:???");
    }
    bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sampling_rate_accelerometer, 0, VS_FLUSH_NONE, 0, 0);
    if( BHY_SUCCESS == bhy_get_wakeup_sensor_configuration( VS_TYPE_ACCELEROMETER, &sr, &mrl, &cs, &dr ) ){
    NRF_LOG_INFO("CAC:SR:%d,MRL:%d,CS:%d, DR:%d", sr, mrl, cs, dr);
    }else{
    NRF_LOG_INFO("CAC:???");
    }
    result = bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sensors_callback_common);
    APP_ERROR_CHECK(result);

    }

    <info> app: IAC:SR:12289,MRL:257,CS:16, DR:16
    <info> app: CAC:SR:12289,MRL:257,CS:16, DR:16

    So what do these numbers represent 12289 ( Rate in Hz; 12KHz? or what?)

    Change sensitivity 16? What does this represent?

    Dynamic Range 16; what does this represent 16g? Why does phys sensor say 4g (see later).?

     


    <info> app: IGY:SR:12548,MRL:2049,CS:1000, DR:16
    <info> app: CGY:SR:12548,MRL:2049,CS:1000, DR:16

     

    Similar questions for gyro? What do figures represent?


    <info> app: IMG:SR:2818,MRL:3845,CS:2000, DR:15
    <info> app: CMG:SR:2818,MRL:3845,CS:2000, DR:15
    <info> app:

     

    Similar questions for magnetometer? What do figures represent?

    void dumpPhysicalSensorStatus( void )
    {
    struct accel_physical_status_t as;
    struct gyro_physical_status_t gs;
    struct mag_physical_status_t ms;

    if( BHY_SUCCESS == bhy_get_physical_sensor_status( &as, &gs, &ms )){
    NRF_LOG_INFO("");
    NRF_LOG_INFO("Accel Phys:SR:%d,DR:%d,Flag:%d", as.accel_sample_rate, as.accel_dynamic_range, as.accel_flag );
    NRF_LOG_INFO("Gyro Phys:SR:%d,DR:%d,Flag:%d", gs.gyro_sample_rate, gs.gyro_dynamic_range, gs.gyro_flag );
    NRF_LOG_INFO("Mag Phys:SR:%d,DR:%d,Flag:%d", ms.mag_sample_rate, ms.mag_dynamic_range, ms.mag_flag );
    NRF_LOG_INFO("");
    }
    }


    <info> app: Accel Phys:SR:100,DR:4,Flag:225

    So sample rate 100Hz, dynamic range 4g; so what does this mean?

    Wikipedia says dynamic range is ratio between smallest and largest value; surely this is not just 4.
    I assume for a signed short this means -32,768 to 32,767 where low limit is -2g and high limit is 2g.


    <info> app: Gyro Phys:SR:100,DR:2000,Flag:225

    Again sample rate 100Hz, Dynamic range 2000;  2000 what (not g as sensor hub document says) and what does this represent.
    Is this 2000 degrees/second?


    <info> app: Mag Phys:SR:25,DR:2000,Flag:225

     

    So sample rate 25Hz, Dynamic Range 2000;  Again 2000 what?

     

    Regards,

    Owain

    7 REPLIES 7

    o_o
    Contributor

    I will break your question into parts.

    1. How to interpret the bhy_get_wakeup_sensor_configuration return values ?

      The thing to note here, is that BHI and BHA have 2 layers of software. the bhy.c and bhy.h files are a basic API that puts names on register values. The bhy_uc_driver* files are a simple driver that can be ported to any platform, including the smallest microcontrollers. the file bhy_uc_driver.h should contain all the functions that are required for the vast majority of use-cases.

      The function bhy_get_wakeup_sensor_configuration is part of the API for does not use the same enums as the driver, therefore the argument VS_TYPE_ACCELEROMETER is invalid. See code excerpt from bhy.h :

      /*!
       *  @brief API used to get the sensor wakeup configuration
       *  Sensor page-3 parameter 65 to 89
       *
       *  @param v_sample_rate_u16 : contains the  wakeup sample rate data
       *  @param v_max_report_latency_u16: contains the  wakeup max report latency
       *  @param v_change_sensitivity_u16: contains the  wakeup sensitivity
       *  @param v_dynamic_range_u16: contains the  wakeup dynamic range
       *
       *  @param v_parameter_request_u8: value of selected parameter request
       *   param_request                    | value | Virtual sensor
       * -----------------------------------|-------|----------------
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_97   | 0xE1  | Accelerometer
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_98   | 0xE2  | Magnetometer
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_99   | 0xE3  | Orientation
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_100  | 0xE4  | Gyroscope
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_101  | 0xE5  | Light
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_102  | 0xE6  | Barometer
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_103  | 0xE7  | Temperature
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_104  | 0xE8  | Proximity
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_105  | 0xE9  | Gravity
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_106  | 0xEA  | Liner accel
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_107  | 0xEB  | Rotation vector
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_108  | 0xEC  | Humidity
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_109  | 0xED  | Ambient Temperature
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_110  | 0xEE  | Uncalibrated Mag
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_111  | 0xEF  | Game rotation Vector
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_112  | 0xF0  | Uncalibrated Gyro
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_113  | 0xF1  | Signification Motion
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_114  | 0xF2  | Step detector
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_115  | 0xF3  | Step Counter
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_116  | 0xF4  | Geomagnetic
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_117  | 0xF5  | Heart Rate
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_118  | 0xF6  | Tilt Detector
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_119  | 0xF7  | Wakeup Gesture
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_120  | 0xF8  | Glance Gesture
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_121  | 0xF9  | Pickup Gesture
       *  BHY_PARAMETER_REQUEST_READ_PARAMETER_127  | 0xFF  | Activity
       *
       *
       *  @return results of bus communication function
       *  @retval 0 -> Success
       *  @retval -1 -> Error
       *
       *
       *
      */
      BHY_RETURN_FUNCTION_TYPE bhy_get_wakeup_sensor_configuration(
      u8 v_parameter_request_u8, u16 *v_sample_rate_u16,
      u16 *v_max_report_latency_u16,
      u16 *v_change_sensitivity_u16, u16 *v_dynamic_range_u16);
    2. What does the dynamic range field mean ?

    @owain-incus wrote:

    Wikipedia says dynamic range is ratio between smallest and largest value; surely this is not just 4.
    I assume for a signed short this means -32,768 to 32,767 where low limit is -2g and high limit is 2g.


    I believe that you are confusing range and resolution. In the case of the acceleromter, it has possible ranges of +-2G, +-4G, +-8G or +-16. Since the range can vary it is dynamic.

    Resolution on the other hand is fixed, always 16 bits. There are a total of 65536 values that are mapped to the entire range (positive and negative).  For the default +-4G range, that means 65536/8 = 8196 LSB/g

     


    @owain-incus wrote:

    Again sample rate 100Hz, Dynamic range 2000;  2000 what (not g as sensor hub document says) and what does this represent.
    Is this 2000 degrees/second?



    Thank you for finding this typo. Indeed the data for the gyroscope is in degrees/second. For the magnetometer, it is in uT.

     

    I highly recommend that you start your development with one of our examples. The BHI160 is a sensor Hub, and unlike dumb sensors, there is a communication protocol for the data readout that must be followed.

    o_o
    Contributor
    datasheet updated today with correct units for dynamic range.

    owain-incus
    Established Member

    I still don't have this working. Don't know if this is due to me not using API's correctly; or incorrect documentation.
    Some basic misunderstandings here.

    Here configuration routine; together with debug prints.

    void start_bhy_accelerometer_sensor(int8_t sampling_rate_accelerometer)
    {
    BHY_RETURN_FUNCTION_TYPE result = BHY_ERROR;
    u16 sr, mrl, cs, dr;
    struct sensor_configuration_wakeup_t sensorConf;

    sensorConf.wakeup_sample_rate = 0;
    sensorConf.wakeup_max_report_latency = 0;
    sensorConf.wakeup_change_sensitivity = 0;
    sensorConf.wakeup_dynamic_range = 16;

    if( BHY_SUCCESS == bhy_set_wakeup_sensor_configuration( &sensorConf, 0x0e1 ) ){
    NRF_LOG_INFO( "Accel changed range OK" );
    }else{
    NRF_LOG_INFO( "Accel changed range FAIL" );
    }

    if( BHY_SUCCESS == bhy_get_wakeup_sensor_configuration( 0x0e1, &sr, &mrl, &cs, &dr ) ){
    NRF_LOG_INFO("IAC:SR:%d,MRL:%d,CS:%d, DR:%d", sr, mrl, cs, dr);
    }else{
    NRF_LOG_INFO("IAC:???");
    }

    bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sampling_rate_accelerometer, 0, VS_FLUSH_NONE, 0, 0);

    if( BHY_SUCCESS == bhy_get_wakeup_sensor_configuration( 0x0e1, &sr, &mrl, &cs, &dr ) ){
    NRF_LOG_INFO("CAC:SR:%d,MRL:%d,CS:%d, DR:%d", sr, mrl, cs, dr);
    }else{
    NRF_LOG_INFO("CAC:???");
    }
    result = bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sensors_callback_common);
    APP_ERROR_CHECK(result);

    }

    bhi160 initialize success!
    <info> app: Accel changed range OK
    <info> app: IAC:SR:0,MRL:0,CS:0, DR:0
    <info> app: CAC:SR:0,MRL:0,CS:0, DR:0
    <info> app: IGY:SR:0,MRL:0,CS:0, DR:0
    <info> app: CGY:SR:0,MRL:0,CS:0, DR:0
    <info> app: IMG:SR:0,MRL:0,CS:0, DR:0
    <info> app: CMG:SR:0,MRL:0,CS:0, DR:0
    <info> app:
    <info> app: Accel Phys:SR:100,DR:4,Flag:225
    <info> app: Gyro Phys:SR:100,DR:2000,Flag:225
    <info> app: Mag Phys:SR:25,DR:2000,Flag:225
    <info> app:

     

    Could you please advise?

    Playing around I now have something that works; but still unclear on the bhy_get_wakeup_sensor_configuration() as this still appear to return 0's.

     

    bhi160 initialize success!
    <info> app: Accel changed range OK
    <info> app: IAC:SR:0,MRL:0,CS:0, DR:0
    <info> app: CAC:SR:0,MRL:0,CS:0, DR:0
    <info> app: Gyro changed range OK
    <info> app: IGY:SR:0,MRL:0,CS:0, DR:0
    <info> app: CGY:SR:0,MRL:0,CS:0, DR:0
    <info> app: IMG:SR:0,MRL:0,CS:0, DR:0
    <info> app: CMG:SR:0,MRL:0,CS:0, DR:0
    <info> app:
    <info> app: Accel Phys:SR:100,DR:16,Flag:225
    <info> app: Gyro Phys:SR:100,DR:2000,Flag:225
    <info> app: Mag Phys:SR:25,DR:2000,Flag:225
    <info> app:
    <info> app: >Meta event type 16,

     

    So DR for physical sensor is changed for the accel and gyro.

    But why do the bhy_get_wakeup_sensor_configuration() not reflect the changes made?

    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