We are trying to develop the nano seconds delay but ended up with 1 us delay minimum.
init_timer()
{
LPC_SC->PCONP |= (1<<SBIT_TIMER0) | (1<<SBIT_TIMER1); /* Power ON Timer0,1 */
LPC_TIM0->MCR = (1<<SBIT_MR0I) | (1<<SBIT_MR0R); /* Clear TC on MR0 match and Generate Interrupt*/
LPC_TIM0->PR = 0;//
LPC_TIM0->MR0 = 10;//
LPC_TIM0->TCR = (1 <<SBIT_CNTEN); /* Start timer by setting the Counter Enable*/
NVIC_EnableIRQ(TIMER0_IRQn);
}
void TIMER0_IRQHandler(void)
{
unsigned int isrMask;
isrMask = LPC_TIM0->IR;
LPC_TIM0->IR = isrMask; /* Clear the Interrupt Bit */
LPC_GPIO0->FIOPIN ^= (1<<LED1); /* Toggle the LED1 (P2_0) */
}
How many nanoseconds? If you are running at 100Mhz, each instruction will take at least 10nS (you also have to factor in flash waits states etc). A very very tight loop with a counter is going to take 50-100nS. Then factor in function calls and bit manipulation (if you want to set GPIOs), then I doubt you could get better than 250nS minimum (I’ve not done exact calculation, so this is ballpark)