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

RTC_COMPARE_OFFSET_MIN value

Hi,

If we set the prescalar for RTC1 to 0xFFF (i.e. max value allowed), tick event is getting generated every 125msec. Using the below configuration i started a timer to trigger every 125msec

#define TICK_TIMER_TICKS APP_TIMER_TICKS(125, APP_TIMER_PRESCALER) app_timer_start(tick_timer_id, TICK_TIMER_TICKS, NULL);

Instead of getting triggered every 125msec (1 tick), it is getting triggered every 375msec (3 ticks).

Figured that the macro RTC_COMPARE_OFFSET_MIN is set to 3 and is the reason for not triggering on every tick

In the reference manual v3.0, page 106, has a timing diagram Figure 39 and note "If the COUNTER is N, writing N or N+1 to a CC register may not trigger a COMPARE event." The diagram is for prescalar set to 0.

Since the prescalar is not 0, can we change the macro definition to 1. Will it have any effect on app_scheduler or any other modules.

Thank you, Manju.

Parents
  • Hi Manju

    I recommend to set the app_timer prescaler with the following #define, as done in the examples in the SDK

    #define APP_TIMER_PRESCALER
    

    Setting RTC_COMPARE_OFFSET_MIN to 1 will contain the risk of app_timer not triggering, so that is not recommended.

    There seem to be two limiting factors to the setting of the prescaler:

    #define RTC_COMPARE_OFFSET_MIN  3                 //in app_timer.c
    #define APP_TIMER_MIN_TIMEOUT_TICKS  5            //in app_timer.h
    
    • The RTC_COMPARE_OFFSET_MIN is set to ensure that the RTC CC register is not set too close to the current RTC1 counter value, which will risk that no interrupt will be triggered on CC compare match.

    • The APP_TIMER_MIN_TIMEOUT_TICKS which is set to ensure adequate timing accuracy of the app_timer.

    So if you set the prescaler to 0x2FF. With that, the tick frequency is 15.625ms and you can set the RTC CC register to N+8 with

    APP_TIMER_TICKS(125, APP_TIMER_PRESCALER)
    

    That should be both safe and accurate

Reply
  • Hi Manju

    I recommend to set the app_timer prescaler with the following #define, as done in the examples in the SDK

    #define APP_TIMER_PRESCALER
    

    Setting RTC_COMPARE_OFFSET_MIN to 1 will contain the risk of app_timer not triggering, so that is not recommended.

    There seem to be two limiting factors to the setting of the prescaler:

    #define RTC_COMPARE_OFFSET_MIN  3                 //in app_timer.c
    #define APP_TIMER_MIN_TIMEOUT_TICKS  5            //in app_timer.h
    
    • The RTC_COMPARE_OFFSET_MIN is set to ensure that the RTC CC register is not set too close to the current RTC1 counter value, which will risk that no interrupt will be triggered on CC compare match.

    • The APP_TIMER_MIN_TIMEOUT_TICKS which is set to ensure adequate timing accuracy of the app_timer.

    So if you set the prescaler to 0x2FF. With that, the tick frequency is 15.625ms and you can set the RTC CC register to N+8 with

    APP_TIMER_TICKS(125, APP_TIMER_PRESCALER)
    

    That should be both safe and accurate

Children
No Data
Related