Bosch Sensortec Community

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

    BME680 timestamps

    t_engel
    Member

    BME680 timestamps

    Hi,

    I've been trying to get the BME680 to work with BSEC for a while now on a TI CC1352R device (M4F, gcc). I seem to struggle with the timings. The timestamp I am feeding to bsec_sensor_control is e.g. 406000000. The sensor_settings.next_call is returned as 406003000. As the timestamp is in ns as indicated in the docs, the delta seems to be 3µs compared to the 3secs I would expect. Obviously I am getting BSEC_W_SC_CALL_TIMING_VIOLATION with my timings being off.

    Any help where I might be misunderstanding something? Any additional information that might help helping me?

    The config I use is coming from generic_33v_3s_4d, code is based on BSEC_1.4.8.0_Generic_Release,  the driver is v3.5.10 as indicated.

    Thanks.

    Tobi

     

    5 REPLIES 5
    Minhwan
    Community Moderator

    Re: BME680 timestamps

    Hello, 

     

    If you check sensor_settings.next_call directly, it should be approximately 3,000,000,000 gap for 3 sec. 

    I suggest to start your project from bsec_iot_example with our application board with BME680. 

    \bsec_1-4-8-0_generic_release\BSEC_1.4.8.0_Generic_Release\examples\bsec_iot_example.c

    Then, you can see sensor data every 3 sec. 

    In bsec_iot_example code, you can also check time conversion from nano to sec or mili. 

    Thank you. 

    t_engel
    Member

    Re: BME680 timestamps

    Hi Minhwan,

    thanks for your reply and for confirming that the sensor_settings.next_call should be about 3,000,000,000 for 3 seconds. It returns a delta of 3,000 for me.

    I do base my code on the bsec_iot_example.c content.  Besides moving it into one function (initialization and loop) I believe I only added printf's for debugging.

    Below the code and the log output. As you can see, the next_call is incremented by 3000, bsec_sensor_control is returning BSEC_W_SC_CALL_TIMING_VIOLATION.

    Thanks & regards,

    Tobi

     

    #include "sensor.h"
    #include "i2c.h"
    #include "bsec_integration.h"
    
    void sensorLoop()
    {
    
        /* Timestamp variables */
        int64_t time_stamp_start = 0;
        int64_t time_stamp_end = 0;
        int64_t time_stamp_interval_ms = 0;
    
        /* Allocate enough memory for up to BSEC_MAX_PHYSICAL_SENSOR physical inputs*/
        bsec_input_t bsec_inputs[BSEC_MAX_PHYSICAL_SENSOR];
    
        /* Number of inputs to BSEC */
        uint8_t num_bsec_inputs = 0;
    
        /* BSEC sensor settings struct */
        bsec_bme_settings_t sensor_settings;
    
        /* Save state variables */
        uint8_t bsec_state[BSEC_MAX_STATE_BLOB_SIZE];
        uint8_t work_buffer[BSEC_MAX_WORKBUFFER_SIZE];
        uint32_t bsec_state_len = 0;
        uint32_t n_samples = 0;
    
        bsec_library_return_t bsec_status = BSEC_OK;
        return_values_init ret;
    
        uint32_t save_intvl = 10000;
    
        initI2C();
    
        /* Call to the function which initializes the BSEC library
         * Switch on low-power mode and provide no temperature offset */
        ret = bsec_iot_init(BSEC_SAMPLE_RATE_LP, 0.0f, bus_write, bus_read, sensor_sleep, state_load, config_load);
    
        if (ret.bme680_status)  {
          /* Could not intialize BME680 */
          printf("Failed to initialize sensor\r\n");
        } else if (ret.bsec_status) {
          /* Could not intialize BSEC library */
          printf("Failed to initialize BSEC\r\n");
        }
    
        /* Main loop */
        while(1) {
    
            /* get the timestamp in nanoseconds before calling bsec_sensor_control() */
            time_stamp_start = get_timestamp_us() * 1000;
    
            /* Retrieve sensor settings to be used in this time instant by calling bsec_sensor_control */
            ret.bsec_status = bsec_sensor_control(time_stamp_start, &sensor_settings);
            if(ret.bsec_status != BSEC_OK) {
                printf("bsec_sensor_control: %d\r", ret.bsec_status);
            }
    
            /* Trigger a measurement if necessary */
            bme680_bsec_trigger_measurement(&sensor_settings, sensor_sleep);
    
            /* Read data from last measurement */
            num_bsec_inputs = 0;
            bme680_bsec_read_data(time_stamp_start, bsec_inputs, &num_bsec_inputs, sensor_settings.process_data);
    
            /* Time to invoke BSEC to perform the actual processing */
            bme680_bsec_process_data(bsec_inputs, num_bsec_inputs, output_ready);
    
            /* Increment sample counter */
            n_samples++;
    
            /* Retrieve and store state if the passed save_intvl */
            if (n_samples >= save_intvl) {
                bsec_status = bsec_get_state(0, bsec_state, sizeof(bsec_state), work_buffer, sizeof(work_buffer), &bsec_state_len);
                if (bsec_status == BSEC_OK) {
                    state_save(bsec_state, bsec_state_len);
                }
                n_samples = 0;
            }
    
    
            /* Compute how long we can sleep until we need to call bsec_sensor_control() next */
            /* Time_stamp is converted from microseconds to nanoseconds first and then the difference to milliseconds */
    
            time_stamp_end = get_timestamp_us() * 1000;
            time_stamp_interval_ms = (sensor_settings.next_call - time_stamp_end) / 1000000;
            if (time_stamp_interval_ms > 0) {
                sensor_sleep((uint32_t)time_stamp_interval_ms);
            }
    
            printf("Start: %lld, End: %lld, next_call: %lld\r", time_stamp_start, time_stamp_end,  sensor_settings.next_call);
        }
    }

     

     

    ts: 749000000d; acc: 0; iaq: 25.00; temp: 24.87; hum: 37.49; press: 98433.00; c02: 400.00; bvoc: 1000.00 ret: 0; stab: 1
    Start: 749000000, End: 1069000000, next_call: 749003000
    bsec_sensor_control: 100
    ts: 1100000000d; acc: 0; iaq: 25.00; temp: 25.59; hum: 33.35; press: 98435.00; c02: 400.00; bvoc: 1000.00 ret: 0; stab: 1
    Start: 1100000000, End: 1428000000, next_call: 1100003000
    bsec_sensor_control: 100
    ts: 1459000000d; acc: 0; iaq: 25.00; temp: 25.94; hum: 31.38; press: 98437.00; c02: 400.00; bvoc: 1000.00 ret: 0; stab: 1
    Start: 1459000000, End: 1779000000, next_call: 1459003000
    bsec_sensor_control: 100
    ts: 1810000000d; acc: 0; iaq: 25.01; temp: 26.10; hum: 30.49; press: 98439.00; c02: 400.00; bvoc: 1000.00 ret: 0; stab: 1
    Start: 1810000000, End: 2138000000, next_call: 1810003000
    bsec_sensor_control: 100
    ts: 2169000000d; acc: 0; iaq: 25.01; temp: 26.24; hum: 29.68; press: 98441.00; c02: 400.00; bvoc: 1000.00 ret: 0; stab: 1
    Start: 2169000000, End: 2489000000, next_call: 2169003000
    t_engel
    Member

    Re: BME680 timestamps

    Any suggestion what I do wrong here?

    t_engel
    Member

    Re: BME680 timestamps

    I noticed that the next_call value I get does not vary with the configuration. So no matter whether I load a 3s or a 300s config, the addition to the timestamp I hand to the API is always 3000. Could a faulty loading of the config be the reason for seemingly wrong next_call offset?

    bsec_set_configuration returns BSEC_OK though.

    Any input is really appreciated!

    Thanks.
    Tobi

     

     

    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