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

RTC get count, App Timer

Hi, I am trying to understand how can I have a running counter based on the low power 32.768 KHz oscilator that does not trigger any timeout interrupts (I am using the soft device). I am thinking there should be some way by which I can start the counter and then just get count ticks from somewhere else later in the code. I am trying to find a way I can do this using the app timer examples that I have seen in the forums but it seems all of them rely on an interrupt triggered after some timeout. It seems this should be possible as mentioned in the nRF51 reference manual. Any help would be appreciated.

Parents
  • May I ask why you want this?

    However, if you just need a running RTC, without any software on top, I guess the easiest may be to just do everything manually, based on the descriptions in the nRF51 Reference Manual. Given that the LFCLK is already running (see the lfclk_config() function in the rtc_example), you can start the RTC by doing this:

    
    NRF_RTC0->TASKS_START = 1;
    
    

    If you don't enable any events or interrupts (i.e. don't write to INTENSET or EVTENSET), the RTC will just keep going, and you can read the value by checking the NRF_RTC0->COUNTER register. You can refer to the RTC example and chapter 18 of the Reference manual for further details.

    Beware that some of the SDK modules depends on app_timer, so you have to change them if you want to use them. That goes for at least ble_conn_params and app_button.

Reply
  • May I ask why you want this?

    However, if you just need a running RTC, without any software on top, I guess the easiest may be to just do everything manually, based on the descriptions in the nRF51 Reference Manual. Given that the LFCLK is already running (see the lfclk_config() function in the rtc_example), you can start the RTC by doing this:

    
    NRF_RTC0->TASKS_START = 1;
    
    

    If you don't enable any events or interrupts (i.e. don't write to INTENSET or EVTENSET), the RTC will just keep going, and you can read the value by checking the NRF_RTC0->COUNTER register. You can refer to the RTC example and chapter 18 of the Reference manual for further details.

    Beware that some of the SDK modules depends on app_timer, so you have to change them if you want to use them. That goes for at least ble_conn_params and app_button.

Children
  • Hi Ole, Thanks very much for your really prompt reply, My initial thought was to use the RTC get current tick count to measure the execution time of some routines I have in my code. Upon deeper examination my program will also benefit from repeated interrupts at 500 ms for transmission so using a plain simple repeating app_timer based on the LFCLK would work perfect, using this running timer I can also get the tick count so it meets that purpose as well. Thanks Ole.

  • Hi Ole,

    I just seen this post and your comment is useful to me.Can you tell me specifically, how can I read counter register of real time counter without activating any interrupt? can I simply get value from this "tempvar = NRF_RTC0->COUNTER register"?

    I am using these statements, but they didn't help me much.

    nrf_drv_rtc_t const *const    p_instance;
    temp=nrf_drv_rtc_counter_get   (p_instance)    ;
    printf("current value is=%d\r\n",temp);
    

    Please guide me in this regards.

Related