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) */}
Similar discussion:
community.arm.com/.../50ns-delay-generation-on-lpc2129
Keil CMSIS-RTOS docu confirming "millisec" time delay value:
www.keil.com/.../group__CMSIS__RTOS__Wait.html
So what clock frequency are you using?
Note that the operation of the timers & clock system is entirely specific to the chip manufacturer - NXP, in this case - and nothing to do with Keil or ARM:
https://community.arm.com/developer/tools-software/tools/f/keil-forum/43684/lpc2148-timer0-not-working-as-expected/158950#158950
So you need to be talking to NXP about how to correctly configure their chip to your purpose.
Also remember that code takes a finite time to execute, and it takes a finite time from the occurrence of the hardware event before execution reaches the ISR for that event ...
That bit is defined by ARM:
https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/beginner-guide-on-interrupt-latency-and-interrupt-latency-of-the-arm-cortex-m-processors
www2.keil.com/.../01_shore_arm.pdf
https://www.nxp.com/docs/en/application-note/AN12078.pdf
There will also be a finite delay between modifying a bit in a GPIO control register, and the state of the pin actually changing - again, this is chip-specific.