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

Timers for nRF51822 Beacon Kit

Hi,

In my project, I need to periodically perform some jobs on the nRF51822 Beacon kit (sdk 7.1). For that, I think I need to use timers. However, I'm not sure how to do this. I found some sample code online but it wasn't very explanatory.

Could you please give me some pointers to where I should be looking at or some sample code with explanation?

Any help will be much appreciated! Thanks

Parents
  • You Initialize the APP timer, read about APP_TIMER_INIT in app_timer.h, APP_TIMER_MAX_TIMERS should atleast be equal to number of times you use app_timer_create in your whole application

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    

    Then you create a timer by

    app_timer_create(&m_leds_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timeout_handler);
    

    or

    app_timer_create(&m_leds_timer_id, APP_TIMER_MODE_REPEATED, timeout_handler);
    

    Singleshot will make your timeout_handler run once and then disable the timer, repeated on the otherhand will call your timeout_handler repeatedly with interval of configured timeout.

    Now you have initialized the app_timer and also created your timer. Now we configure the timer and start it by

    app_timer_start(m_leds_timer_id, APP_TIMER_TICKS(MS, APP_TIMER_PRESCALER), NULL);
    

    now your timeout_handler will be called after INTERVAL_IN_MS

  • sorry my bad, copy paste mistake, changed my answer, instead of BSP_MS_TO_TICK macro use macro APP_TIMER_TICKS defined in app_timer.h. Its purpose is to convert the milliseconds delay you require to timer tick.

Reply Children
No Data
Related