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

1 micro second interrupt using timer1? Softdevice is enabled.

Is it possible to have 1micro second interrupt using timer 1?

I am unable to achieve it.

If I try for 4micro second, I observe toggling of pin at 8 micro seconds?

Why so?

init:

TIMER1->TASKS_STOP = 1;   /* Stop timer */ 

TIMER1->MODE = TIMER_MODE_MODE_Timer;  /* taken from Nordic dev zone */

TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit;

TIMER1->PRESCALER = TIMER_PRESCALER;

TIMER1->CC[0] = 64;  /*for 4 micro second*/

TIMER1->TASKS_CLEAR = 1; /* Clear timer */	

TIMER1->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;

TIMER1->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);		
				
NVIC_SetPriority(TIMER1_IRQn, 1);

NVIC_EnableIRQ(TIMER1_IRQn);				

TIMER1->TASKS_START = 1;

inside irq routine:

if(TIMER1->EVENTS_COMPARE[0])
{
    
    TIMER1->EVENTS_COMPARE[0] = 0;
			
    nrf_gpio_pin_toggle(17);
			
    TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk;
}
  • I'm not sure that I understand what you're trying to do with the TIMER1->SHORTS in the IRQ. But anyway, I would gues that the interrupt service routine takes longer than 4uS, so you're only catching every other IRQ. Have you tried for an 8uS IRQ, for example, just to check that your understanding of the various values and setting is correct?

  • You haven't got even a faint hope of getting that to work using a TIMER interrupt.

    For a start 1us is 16 clock cycles, the cortex M0 has a 16 cycle interrupt latency. So it takes all of 1us just to get the interrupt service routine entered and exited. That's before any of your code is run.

    Secondly you say you have the softdevice enabled. That adds yet more overhead to the interrupt processing as it bounces through the bootloader and the softdevice and then to your code (the actual timings are in the softdevice spec) and when the softdevice needs to do some work, your interrupts are going to be blocked for milliseconds at at time whilst it's doing stuff.

    Edit: I had the S110 product sheet open and looked up the extra latency caused by just having the softdevice trampoline the interrupts

    Interrupt                        CPU cycles    Latency at 16 MHz
    Open peripheral interrupt             49                 3.1 μs
    
Related