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

App Timer Start

Hi,

at the description of the function :  app_timer_start

/**@brief Function for starting a timer.
 *
 * @param[in]       timer_id      Timer identifier.
 * @param[in]       timeout_ticks Number of ticks (of RTC1, including prescaling) to time-out event
 *                                (minimum 5 ticks).
 * @param[in]       p_context     General purpose pointer. Will be passed to the time-out handler when
 *                                the timer expires.
 *
 * @retval     NRF_SUCCESS               If the timer was successfully started.
 * @retval     NRF_ERROR_INVALID_PARAM   If a parameter was invalid.
 * @retval     NRF_ERROR_INVALID_STATE   If the application timer module has not been initialized or the timer
 *                                       has not been created.
 * @retval     NRF_ERROR_NO_MEM          If the timer operations queue was full.
 *
 * @note The minimum timeout_ticks value is 5.
 * @note For multiple active timers, time-outs occurring in close proximity to each other (in the
 *       range of 1 to 3 ticks) will have a positive jitter of maximum 3 ticks.
 * @note When calling this method on a timer that is already running, the second start operation
 *       is ignored.
 */
ret_code_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context);

The parameter "timeout_ticks" has a minimum value, what about the maximum value? in other words can we use this app_timer_start function to start a timer for hours?

Is the limit is just the type of timeout_ticks ? ( in this case is 32 bits long )

According to my calculation, if the RTC frequency is 32768 Hz, then this timer can work for ((2^32) - 1)/32768 = 131071.9999 seconds = 2184.5 minutes = 36.4 hours.

Please let me know If my calculation is right\wrong.

Best Regards

JK

  • Hi,

    The parameter "timeout_ticks" has a minimum value, what about the maximum value?

    The maximum value for the original app_timer implementation (app_timer.c) is MAX_RTC_COUNTER_VAL, which is (2^24)-1 = 16777215. There was an issue in some SDK versions where half of this was the actual maximum due to a bug. And for app_timer2 if you are using that, the maximum value is 2^32-1 as the internal implementation has changed.

    Please let me know If my calculation is right\wrong.

    It depends. The original app_timer.c internally is 24 bit because of the RTC being 24 bit. So the correct would be ((2^24) - 1)/32768 = 512 seconds. You can increase this by lowering the RTC frequency by using a prescaler though, which you do by modifying APP_TIMER_CONFIG_RTC_FREQUENCY in sdk_config.h.

Related