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

app_timer_cnt_get() always returns 0x0018000 (SDK12.1.0)

I'm trying to use app_timer_cnt_get() to implement an RTC Calendar system on a Gigawit module (nRF51822).

I have a test app_timer that has presacler=0 and period=3 seconds. The callback works as I toggle a LED, and it toggles every 3 seconds.

The code uint32_t this_count = app_timer_cnt_get(); shows a value of 0x00018000 when I set a breakpoint after the call to app_timer_cnt_get().

Why does it not increment? RTC1 and the timer is obviously working and counting, and app_timer_cnt_get() eventually return NRF_RTC1->COUNTER;

Is the counter automatically reset to zero? I can't imagine so if multiple timers are used with APP_TIMER.

I've tried enabling RTC1 in sdk_config.h, but app_timer was working without that anyway.

I've also tried enabling APP_TIMER_KEEPS_RTC_ACTIVE in sdk_config.h. I think I need this anyway for my Calendar implementation (for log timestamps), however it didn't make any difference.

Any help or suggestions greatly appreciated !!

Brendan.

Parents
  • Maybe it is the way you are checking the value.

    You should be careful when using breakpoints as this will only stop the cpu (the code) from running and not the peripherals like the RTC. This is the reason it is not recommended to use breakpoints and then resume the code execution when doing BLE stuff (advertising/scanning/connection).

    If you get a value of 0x18000 the first time you enter the timer_app callback routine, this is correct (0x18000 is 0x8000 (32768) times 3 -> 3 seconds). When you resume the code execution do you hit the breakpoint again with the same value? If so it might be because the chip is resetting because of an error condition, see here. You can check this by adding a breakpoint at the very start of main().

    You could try to log the value using UART or RTT instead, this can be done with the log module. Enable logging with the NRF_LOG_ENABLED macro in sdk_config.h. Use NRF_LOG_... functions to print data.

Reply
  • Maybe it is the way you are checking the value.

    You should be careful when using breakpoints as this will only stop the cpu (the code) from running and not the peripherals like the RTC. This is the reason it is not recommended to use breakpoints and then resume the code execution when doing BLE stuff (advertising/scanning/connection).

    If you get a value of 0x18000 the first time you enter the timer_app callback routine, this is correct (0x18000 is 0x8000 (32768) times 3 -> 3 seconds). When you resume the code execution do you hit the breakpoint again with the same value? If so it might be because the chip is resetting because of an error condition, see here. You can check this by adding a breakpoint at the very start of main().

    You could try to log the value using UART or RTT instead, this can be done with the log module. Enable logging with the NRF_LOG_ENABLED macro in sdk_config.h. Use NRF_LOG_... functions to print data.

Children
No Data
Related