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

RTC1 counter return to 0

Hi all,

i use softdevice and app timer. I know that the softdevice use a RTC0 and app timer RTC1.

I would use a rtc to have a timestamp. but i see that after 512 second the counter come back to 0. Someon can clarify why?

Thanks, Anna

Parents
  • I implemented a workaround for this by using a Repeated App-Timer, with the timeout handler going off the moment before it overflows.

    To create timer:

     err_code = app_timer_create(&m_millis_id,
      APP_TIMER_MODE_REPEATED,
      timer_a_handler);
    

    To start timer:

    err_code = app_timer_start(m_millis_id, APP_TIMER_TICKS(511999, APP_TIMER_PRESCALER), NULL);
        APP_ERROR_CHECK(err_code);
    

    Timeout handler:

       static void timer_a_handler(void *p_context) {
      overflow++;
    }
    

    You can then retrieve the timestamp from the code below

     void timestampGet(timestamp_t *ts) {
      uint32_t ticks, s, t;
    
      ticks = app_timer_cnt_get();
    
      s = ticks / TIMER_TICKS_PER_SECOND; // becomes >>
      t = ticks % TIMER_TICKS_PER_SECOND; // becomes &
    
      ts->seconds = overflow * ((1 << RTC_TICKS_BITS) / TIMER_TICKS_PER_SECOND) + s;
      ts->milli_seconds = t * (APP_TIMER_PRESCALER + 1) * (1000.0 / APP_TIMER_CLOCK_FREQ);
    }
    

    The code above is adapted from Clem Taylor's answer here (devzone.nordicsemi.com/.../). I had implemented his approach, but found the PPI based counting mechanism increased the current draw from 50ua to 500ua.

    My code above feels like a bit of a hack, so any criticism/suggestions are welcome.

  • Is there a method that allow to know when the rtc1 goes in overflow? Maybe can be most useful instead of create a new timer, What do you think? Anna

Reply Children
No Data
Related