delay function

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

delay function

872 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mc1992 on Wed Jan 27 09:35:44 MST 2016
Hello friends!
I have a lpc4337 , it has a clock of 204Mhz and i'm programming in C language . How I can make a delay function in ms and us for this micro?
Thanks!!
Labels (1)
0 Kudos
3 Replies

783 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sgstreet on Thu Jan 28 16:43:23 MST 2016
try this for gcc where SystemCoreClock is the CMSIS variable as set by the LPC startup code:

#define CPU_NANOSEC(x) (((uint64_t)(x) * SystemCoreClock) / 1000000000)

static __attribute__((optimize("0"))) inline void wait_usecs(uint32_t usecs)
{
    volatile register uint32_t cycles = (usecs * CPU_NANOSEC(1000)) >> 2;
    while (cycles--);
}

0 Kudos

783 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketdawg on Wed Jan 27 12:12:10 MST 2016
you are going to spin-in-place a 204Mhz processor?
Why not use a state machine and have a timer ISR call a CallBack function to change the state of the state machine.
0 Kudos

783 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vtw.433e on Wed Jan 27 10:31:13 MST 2016
Search the forum - there are plenty of examples. Hint - use a timer.
0 Kudos