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

nrf52832 app_timer bug?

SDK version :15.2

question; when i use app_timer , i got interrupt which is not i wanted.

i creat and start  timer :

app_timer_create(&m_timer,APP_TIMER_MODE_REPEATED,sec_timer_hook);:  

m_sec_context = 0xa5;
app_timer_start(m_timer,APP_TIMER_TICKS(20),&m_sec_context);  

and hook like:

void sec_timer_hook(void *p_context)
{
if(*(uint32_t*)p_context != 0xa5)
{
     led_toggle();
}
}

many times led toggled, is that means some interrupt is not i wanted ,is that a app timer bug?

Parents Reply Children
  • If you look inside app_timer.h, you can see that the input of APP_TIMER_TICKS(..) is milliseconds. 

    /**@brief Convert milliseconds to timer ticks.
     *
     * This macro uses 64-bit integer arithmetic, but as long as the macro parameters are
     *       constants (i.e. defines), the computation will be done by the preprocessor.
     *
     * @param[in]  MS          Milliseconds.
     *
     * @return     Number of timer ticks.
     */
    #ifndef FREERTOS
    #define APP_TIMER_TICKS(MS)                                \
                ((uint32_t)ROUNDED_DIV(                        \
                (MS) * (uint64_t)APP_TIMER_CLOCK_FREQ,         \
                1000 * (APP_TIMER_CONFIG_RTC_FREQUENCY + 1)))
    .
    .
    .

    You have input 20, which will make the function sec_timer_hook() run every 0,02 second, which is quite often. Is this your intention?

    Best regards,

    Simon

Related