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

  • Thanks very much Aryan, it works now. I have another question. I would like to use the single shot timer and when the timeout handler is called, I would like to set up the same timer again with different interval this time. Do I have to use both of the app_timer_create and app_timer_start functions, or would just using app_timer_start suffice? (In other words, I'm not sure whether the timer needs to be recreated or not). Thank you!

Reply
  • Thanks very much Aryan, it works now. I have another question. I would like to use the single shot timer and when the timeout handler is called, I would like to set up the same timer again with different interval this time. Do I have to use both of the app_timer_create and app_timer_start functions, or would just using app_timer_start suffice? (In other words, I'm not sure whether the timer needs to be recreated or not). Thank you!

Children
No Data
Related