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.

  • You can use the Timer peripheral (again see the Reference Manual for more info). This runs off the 16MHz clock. Problem with this is that it requires a lot of current compared to the RTC which the app_timer uses. The Timer will use between 250 and 750 uA depending on which source and which frequency is used. Accurate numbers are in the Product Specification part 8.1. The RTC in comparison uses about 1uA when run off the 32kHz RC oscillator or crystal.

Reply Children
No Data
Related