I want to generate delay in generalized manner i.e void delay(uint8_t delay_ms). The delay passed in ms.
. So I am using LPC1317-64P, 72MhZ clock.
So to generate delay I have used function, SYSTEM_FREQ = 72000KHZ
void delay(uint8_t delay_ms) { uint32_t cnt,temp; cnt = delay_ms*SYSTEM_FREQ for(temp = cnt;temp>0;temp--) //i.e calling NOP the number of times { __NOP(); } }
Problem is in disammembly the for loops break down into MOV,NOP,SUBS,BNE instruction. So total delay is not the same. Its takes 10 times more time. As might be in assembly it has 10 cycles .
If I divide by cnt by 10, then delay is fine. Small inaccuracy is acceptable.
Also I have used Hi Tech C compiler, there when I use __delay_ms(2), it generate exact 2ms delay. How to do that in C.
View all questions in Keil forum