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

SDK 6.0.0 timer

hi,

can i use timer interrupt has more than 1ms period??

#define APP_TIMER_TICKS(MS, PRESCALER)
((uint32_t)ROUNDED_DIV((MS) * (uint64_t)APP_TIMER_CLOCK_FREQ, ((PRESCALER) + 1) * 1000))

APP_TIMER_TICKS offers just ms units but i need more faster timer interrupt

the initializing code in below

app_timer_start(m_pwm_b_timer_id, APP_TIMER_TICKS(1, APP_TIMER_PRESCALER), NULL);

thanks.

Parents
  • APP_TIMER_TICKS(..) will only convert ms to the number of ticks it takes for the RTC to count to the same number of ms. With prescaler 0 one tick is 30.517us (or 1/32768 second), so this is the maximum resolution. See the Reference Manual for more info. You can make your own APP_TIMER_TICKS function which takes in us instead of ms:

    #define APP_TIMER_TICKS_US(US, PRESCALER)\
                ((uint32_t)ROUNDED_DIV((US) * (uint64_t)APP_TIMER_CLOCK_FREQ, ((PRESCALER) + 1) * 1000000))
    

    ROUNDED_DIV(A, B) will do the same as: A/B + 1/2. APP_TIMER_CLOCK_FREQ is 32768.

Reply
  • APP_TIMER_TICKS(..) will only convert ms to the number of ticks it takes for the RTC to count to the same number of ms. With prescaler 0 one tick is 30.517us (or 1/32768 second), so this is the maximum resolution. See the Reference Manual for more info. You can make your own APP_TIMER_TICKS function which takes in us instead of ms:

    #define APP_TIMER_TICKS_US(US, PRESCALER)\
                ((uint32_t)ROUNDED_DIV((US) * (uint64_t)APP_TIMER_CLOCK_FREQ, ((PRESCALER) + 1) * 1000000))
    

    ROUNDED_DIV(A, B) will do the same as: A/B + 1/2. APP_TIMER_CLOCK_FREQ is 32768.

Children
Related