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

Timer 2 not working with Softdevice

Hello,

I have written a timer driver with timer 0 without SD and used 24 bit mode and it is working.

But when I used the same driver with softdevice and Timer 2 and 16 bit and changed the prescaler for one second interval, it is not working.

Here is the code snippet:

NRF_TIMER2->TASKS_STOP = 1;   // Stop timer
NRF_TIMER2->MODE 			= TIMER_MODE_MODE_Timer;  // Set the timer in Normal Mode
NRF_TIMER2->BITMODE 		= TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
NRF_TIMER2->PRESCALER 	= 11;
NRF_TIMER2->TASKS_CLEAR = 1;               // clear the task first to be usable for later
NRF_TIMER2->CC[1] 		= 7813;				// set for 1 sec 
// Enable interrupt on Timer 2
NRF_TIMER2->INTENSET = (TIMER_INTENSET_COMPARE1_Enabled
								<< TIMER_INTENSET_COMPARE1_Pos);
NRF_TIMER2->SHORTS 		= (TIMER_SHORTS_COMPARE1_CLEAR_Enabled
								<< TIMER_SHORTS_COMPARE1_CLEAR_Pos);
NVIC_EnableIRQ(TIMER2_IRQn);
NRF_TIMER2->TASKS_START = 1;

I am getting the interrupts but not for one seconds.

Regards, Sowmya

Parents
  • The prescaler only accepts the values 0-9. 16000000/2^9=31250 Hz. With a cc value of 7813 it will result in ~250ms interrupts

  • Now I changed the timer interrupt to 100 ms and initialised application timer to 10ms i.e., using

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS,
    					APP_TIMER_OP_QUEUE_SIZE, false);
    

    where,

    #define APP_TIMER_PRESCALER             327
    #define APP_TIMER_MAX_TIMERS            4
    #define APP_TIMER_OP_QUEUE_SIZE         5
    

    Now I created one timer instance and set the time for every 10 ms using,

    app_timer_start(ulTestTimer, 1, NULL);
    

    This case I am getting the interrupt . I have put BP inside callback function and it is in repeated mode.

    But the same configuration is working when I star the timer with value 5 i.e., for 50ms. What can be the cause ?

Reply
  • Now I changed the timer interrupt to 100 ms and initialised application timer to 10ms i.e., using

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS,
    					APP_TIMER_OP_QUEUE_SIZE, false);
    

    where,

    #define APP_TIMER_PRESCALER             327
    #define APP_TIMER_MAX_TIMERS            4
    #define APP_TIMER_OP_QUEUE_SIZE         5
    

    Now I created one timer instance and set the time for every 10 ms using,

    app_timer_start(ulTestTimer, 1, NULL);
    

    This case I am getting the interrupt . I have put BP inside callback function and it is in repeated mode.

    But the same configuration is working when I star the timer with value 5 i.e., for 50ms. What can be the cause ?

Children
No Data
Related