This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTC to get date and time

Good afternoon, I want to get date and time from the RTC1 and working on the S110. As the RTC1 counter is just 24-bit long, final counter value (overflow) has to be taken into account. Regarding the function ' app_timer_cnt_diff_compute': does it take into account the overflow? Does it give correct ticks number if second argument is higher than the first one when calling this function? Are there any examples regardings these aspects? Regards.

Parents
  • Hi,

    If you dive into the inner workings of app_timer_cnt_diff_compute() you will eventually find out that the time difference is computed this way:

    ((ticks_now - ticks_old) & MAX_RTC_COUNTER_VAL); // MAX_RTC_COUNTER_VAL = 0xFFFFFF;
    

    so you will always get a positive integer output, and the function will show the correct value as long as the time difference is no more than MAX_RTC_COUNTER_VAL.

    There is an example called rtc_pca10028 in the nRF51 SDK that demonstrates the RTC. It does not use the app_timer_cnt_diff_compute() function, but it should be easy enough to integrate it and test it.

    See this thread about RTC and calendar functionality.

    Martin

Reply
  • Hi,

    If you dive into the inner workings of app_timer_cnt_diff_compute() you will eventually find out that the time difference is computed this way:

    ((ticks_now - ticks_old) & MAX_RTC_COUNTER_VAL); // MAX_RTC_COUNTER_VAL = 0xFFFFFF;
    

    so you will always get a positive integer output, and the function will show the correct value as long as the time difference is no more than MAX_RTC_COUNTER_VAL.

    There is an example called rtc_pca10028 in the nRF51 SDK that demonstrates the RTC. It does not use the app_timer_cnt_diff_compute() function, but it should be easy enough to integrate it and test it.

    See this thread about RTC and calendar functionality.

    Martin

Children
No Data
Related