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

Not sure if understand APP_TIMER_TICKS macro.

Hi,

I know that there is documentation, and that there are some answered questions abaut this, but still i dont think i understood how macro APP_TIMER_TICKS works. I need to read adc with frequency 500hz, and i2c with frequency 20hz. i am using NRF51DK with s110 soft device on it.

This is my code:

#define APP_TIMER_PRESCALER              0     
#define ADC_SAMPLING_INTERVAL                APP_TIMER_TICKS(2, APP_TIMER_PRESCALER)
#define I2C_SAMPLING_INTERVAL                APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)

Is this configuration proper for my needs? If not, could someone simply explain how to use this macro?

Regards, Ina

Parents
  • APP_TIMER is running with frequency 32768 Hz.

    This means that with prescaler 0, it will generate 32768 ticks per second.

    Since the app_timer_start function arguments needs the time in ticks and not in millisecond, we need to convert the interval in ms after which you need your timer_callback to be called into app_timer ticks.

    This can be done using APP_TIMER_TICKS(X,Y)

    500Hz sampling means that you you need one sample every 1/500 = 2ms, so to convert this sampling interval into app_timer ticks you need

    APP_TIMER_TICKS(2, APP_TIMER_PRESCALER)
    

    20Hz sampling means that you you need one sample every 1/20= 50ms, so to convert this sampling interval into app_timer into ticks you need

    APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
    

    So yes, you got it right :)

Reply
  • APP_TIMER is running with frequency 32768 Hz.

    This means that with prescaler 0, it will generate 32768 ticks per second.

    Since the app_timer_start function arguments needs the time in ticks and not in millisecond, we need to convert the interval in ms after which you need your timer_callback to be called into app_timer ticks.

    This can be done using APP_TIMER_TICKS(X,Y)

    500Hz sampling means that you you need one sample every 1/500 = 2ms, so to convert this sampling interval into app_timer ticks you need

    APP_TIMER_TICKS(2, APP_TIMER_PRESCALER)
    

    20Hz sampling means that you you need one sample every 1/20= 50ms, so to convert this sampling interval into app_timer into ticks you need

    APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
    

    So yes, you got it right :)

Children
Related