This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

rtc nrf51 SDK example matches COMPARE0 only once

In order to learn how to use the RTC0 to handle an event every second, I am debugging the rtc SDK example.

Expectation: The rtc example sets the time to check the counter time at 3 seconds. I expect every 3 seconds. the int_type in rtc_handler() will equal NRF_DRV_RTC_INT_COMPARE0.

What I am seeing: the int_type in rtc_handler() equals NRF_DRV_RTC_INT_COMPARE0 after the first three seconds. Then int_type equals only NRF_DRV_RTC_INT_TICK.

Question: is my assumption correct the COMPARE0 should keep repeating such that there is a match every 3 seconds (in this example)

Question: If not, what is the example missing to do so?

thank you.

Parents
  • Are you resetting the timer when you get the compare? If not it will just count all the way to the maximum count, then wrap around and start at zero and only when it gets to the same count again will you get the next COMPARE0. If you have the timer running fast that's 512 seconds, if you have it running as slowly as possible, that's 24 days before you'll see the next interrupt.

  • Thank you for your answer. I think I do... it seems i reset the count, but the compare0 event doesn't recur?

    /** @brief: Function for handling the RTC0 interrupts.
     * Triggered on TICK and COMPARE0 match.
     */
    static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
    {
        if (int_type == NRF_DRV_RTC_INT_COMPARE0)
        {
            nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
            nrf_drv_rtc_counter_clear(&rtc);
        }
        else if (int_type == NRF_DRV_RTC_INT_TICK)
        {
            nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
        }
    }
    
Reply
  • Thank you for your answer. I think I do... it seems i reset the count, but the compare0 event doesn't recur?

    /** @brief: Function for handling the RTC0 interrupts.
     * Triggered on TICK and COMPARE0 match.
     */
    static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
    {
        if (int_type == NRF_DRV_RTC_INT_COMPARE0)
        {
            nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
            nrf_drv_rtc_counter_clear(&rtc);
        }
        else if (int_type == NRF_DRV_RTC_INT_TICK)
        {
            nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
        }
    }
    
Children
No Data
Related