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

Timer Prescaler

I have a nRF51 DK board and its flashed with the SD 110

I want to have a timer which will interrupt every 50us.

This is how I set up the timer:

#define APP_TIMER_PRESCALER             4                                           
#define APP_TIMER_MAX_TIMERS            (3 + BSP_APP_TIMERS_NUMBER)                
#define APP_TIMER_OP_QUEUE_SIZE         4                                          
#define MEIN_50us_INTERVAL		        APP_TIMER_TICKS(50,APP_TIMER_PRESCALER)

With this set up I will have an interrupt every 50ms. Now if I change the prescaler nothing will change. I will still get interrupts every 50ms.

But if I change the prescaler, the time for interrupts should also change....

Or what I have to change when I need faster interrupts?

This is how the protocol looks like:

image description

I need to be able, to set every single bit. Is this possible with the new nRF52 preview board?

Parents
  • Yes that's correct.

    Edit:

    Why do you think changing the prescalar would change the time when the APP_TIMER_TICKS() macro is documented thusly (the headers contain so much information they are always worth looking at)

    /**@brief Convert milliseconds to timer ticks.
     *
     * @note This macro uses 64 bit integer arithmetic, but as long as the macro parameters are
     *       constants (i.e. defines), the computation will be done by the preprocessor.
     *
     * @param[in]  MS          Milliseconds.
     * @param[in]  PRESCALER   Value of the RTC1 PRESCALER register (must be the same value that was
     *                         passed to APP_TIMER_INIT()). 
    

    The entire POINT of that macro is to generate the correct number of ticks for a number of milliseconds. If you change the PRESCALAR, the macro generates a different number of ticks in order to do what you've asked for, give you 50ms.

    You can't use the app timer to generate 50us ticks anyway. Again looking at the documentation of the functions in the header file

    /**@brief Function for starting a timer.
     *
     * @param[in]  timer_id        Id of timer to start.
     * @param[in]  timeout_ticks   Number of ticks (of RTC1, including prescaling) to timeout event
     *                             (minimum 5 ticks).
    

    5 ticks of a 32768Hz clock is 153us with the prescalar at 0, that's the minimum you can get with app timers. If you want something faster you'll have to go use the other sort of timer.

  • Inspectron, could you please update this thread with latest info, if any answer helped you then please click the ✓ to the left of the answer so that others can come and look here.

Reply Children
No Data
Related