Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    NRF52840 with BME680

    NRF52840 with BME680

    pallyapd
    Established Member

    hello
    I am using nrf52840 with a segger embedded system I want to calculate IAQ using app timer which is generated interrupt every 3-second(LP mode) to call bsec_ iot_loop(), that's working for me .but when I call this loop every 5 minutes (300-sec ULP mode ) not able to get calculate IAQ .i develop get_timerstamp_us as below .please help me 

    static void my_timer_start(void) {
    // Reset the second variable
    my_timer_seconds = 0;

    // Ensure the timer uses 24-bit bitmode or higher
    MY_TIMER->BITMODE = TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos;

    // Set the prescaler to 4, for a timer interval of 1 us (16M / 2^4)
    MY_TIMER->PRESCALER = 4;

    // Set the CC[0] register to hit after 1 second
    MY_TIMER->CC[0] = 1000000;

    // Make sure the timer clears after reaching CC[0]
    MY_TIMER->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk;

    // Trigger the interrupt when reaching CC[0]
    MY_TIMER->INTENSET = TIMER_INTENSET_COMPARE0_Msk;

    // Set a low IRQ priority and enable interrupts for the timer module
    NVIC_SetPriority(MY_TIMER_IRQn, 7);
    NVIC_EnableIRQ(MY_TIMER_IRQn);

    // Clear and start the timer
    MY_TIMER->TASKS_CLEAR = 1;
    MY_TIMER->TASKS_START = 1;
    }

    static uint32_t my_timer_get_ms(void) {
    // Store the current value of the timer in the CC[1] register, by triggering the capture task
    MY_TIMER->TASKS_CAPTURE[1] = 1;

    // Combine the state of the second variable with the current timer state, and return the result
    return (my_timer_seconds * 1000) + (MY_TIMER->CC[1] / 1000);
    }

    /*!
    * @brief Capture the system time in microseconds
    *
    * @return system_current_time current system timestamp in microseconds
    */

    static int64_t get_timestamp_us() {
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "in get us loop timestamp : %d\n\n",((int64_t)my_timer_get_ms() * 1000));

    return ((int64_t)my_timer_get_ms() * 1000);
    }


    // Timer interrupt handler
    void MY_TIMER_IRQHandler(void) {
    if (MY_TIMER->EVENTS_COMPARE[0]) {
    MY_TIMER->EVENTS_COMPARE[0] = 0;

    // Increment the second variable
    my_timer_seconds++;
    }
    }

    1)is it compulsory to use sample rate  LP or ULP mode for calculating IAQ.
    2)my system is battery-operated so want to increase this sample rate for example every 15 minutes how to achieve this.


    7 REPLIES 7

    BSTRobin
    Community Moderator
    Community Moderator

    Hello pallyapd,

    You could see IAQ was output from BSEC.
    void output_ready(int64_t timestamp, float iaq, uint8_t iaq_accuracy, float temperature, float humidity,
    float pressure, float raw_temperature, float raw_humidity, float gas, bsec_library_return_t bsec_status,
    float static_iaq, float co2_equivalent, float breath_voc_equivalent)
    {
    PDEBUG("timestamp=%lld, iaq=%f, iaq_accuracy=%d, temperature=%f, humity=%f, pressure=%f, \
    raw_temperature=%f, raw_humity=%f, gas=%f, bsec_status=%d, static_iaq=%f, co2_equivalent=%f, \
    breath_voc_equivalent=%f\r\n", timestamp, iaq, iaq_accuracy, temperature, humidity, pressure, \
    raw_temperature, raw_humidity, gas, bsec_status, static_iaq, co2_equivalent, breath_voc_equivalent);
    }

    By default, example code used BSEC_SAMPLE_RATE_LP sample rate. YOu could select sample rate from BSEC integration guide.

    BSEC sample rate.png

    pallyapd
    Established Member

    in bsec only 2 configurations are available. I create a timer which is called bsec_loop every 3 seconds (lp mode) it works fine .but whenever I configure ULP mode 300 seconds IAQ is not calculated.IAQ_accurancy remains zero.

    BSTRobin
    Community Moderator
    Community Moderator

    Hello pallyapd,

    For ULP mode software, you could refer attachment source code.

    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