Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RTC overflw handler

Hello ,
I am working on the development kit nrf52, i want to know how  i canget  the value of the RTC overflw and then how i can reset the RTC to zero.

thank you in advance
Best regards

Parents
  • You cannot get the overflow value but you can get an overflow event in EVENTS_OVERFLW register. For this you have to enable this event in RTC->EVTEN register.

    You then need to enable interrupt for this in the INTENSET and increment a static variable everytime you get the overflow event. After incrementing the variable, you clear the overflow event.

    for example in the RTC interrupt handler you can do something like this

        static uint8_t tick_overflow_count = 0;
        /* check for overflow in RTC counter */
        if(nrf_rtc_event_pending(portNRF_RTC_REG, NRF_RTC_EVENT_OVERFLOW))
        {
            nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_OVERFLOW);
            tick_overflow_count++;
        }
        
        // then you get the full value
        uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
        full_value = ((tick_overflow_count << portNRF_RTC_BITWIDTH) + systick_counter);

  • Hello Aryan ,

    Thank you for respond.

    I want to reset the rtc  by  a extern interruption (accelerometer), i want to know which function can i use?

    Thank you in advance.

  •  

    • you need to convert the accelerometer interrupt to event by connecting it to GPIOTE in event mode
    • Connect the output of this event to PPI and convert it to a TASK
    • Connect this TASK to RTC->TASKS_CLEAR 

    This will reset the RTC counter to zero everytime you have any interrupt from accelerometer.

    To know more about how to configure GPIOTE and PPI for this, you need to look at their SDK examples in SDK\examples\peripheral and read the docs about them.

     

Reply
  •  

    • you need to convert the accelerometer interrupt to event by connecting it to GPIOTE in event mode
    • Connect the output of this event to PPI and convert it to a TASK
    • Connect this TASK to RTC->TASKS_CLEAR 

    This will reset the RTC counter to zero everytime you have any interrupt from accelerometer.

    To know more about how to configure GPIOTE and PPI for this, you need to look at their SDK examples in SDK\examples\peripheral and read the docs about them.

     

Children
Related