Sobakava
Full Member level 6
delay_ms
Hi
I needed to create a simple delay subroutine by using dummy loops. I found some calculations and tested/working codes for LPC2148 on the net. Three of them are:
OR
OR
Well, these supposed to be work but they do not.
I do something like this:
I already made port direction settings etc.before this piece of code. It is working correctly. But delay_ms() seems not become compiled because I see very short (around 300-500 ns) pulses using an oscilloscope.
I tried to use delay_ms( 10000) insead of delay_ms(10)... Nothing changed.
Then I tried to increase i and j end values in delay_ms() function. Nothing changed.
for instance
Instead of for(i=0;i for(j=0;j<6553;j++);
I tried for(i=0;i for(j=0;j<16553;j++);
pulse durations did not changed. The stranger thing is, I compared two hex files byte by byte and they are identical! so 6553 to 16553 does not change anything in code.
Then I thought may be the compiler does not compile dummy loops because of optimization, I added some arithmetic calculations in loop:
nothing changed. It seems loops are not compiled. ?
I thought may be there is another delay_ms function in the search path include files. I changed the name to my_delay_ms... Nothing changed.
Finally I did something like this:
after this delay_ms has effect (delay). Why It does not work and it has no effect if I do not place a port operation inside the loop?
Hi
I needed to create a simple delay subroutine by using dummy loops. I found some calculations and tested/working codes for LPC2148 on the net. Three of them are:
Code:
void delay_ms(long int ms)
{
long int i, j;
for(i=0;i for(j=0;j<6553;j++);
}
OR
Code:
void delay_ms(unsigned long int count1)
{
unsigned int i,k;
k=count1*2600;
for(i=0;i<k;i++); // Loop Decrease Counter
}
OR
Code:
void delay_ms(int x) //this isn't accurate right now{ //it's just a rough delay int a,b; for(a=0;a<x;a++){ for(b=0;b<3000;b++); }}
Well, these supposed to be work but they do not.
I do something like this:
Code:
while (1) {
IOSET1 = 0x01000000; // turn off LED
delay_ms(10);
IOCLR1 = 0x01000000; // turn off LED
delay_ms(10);
}
I already made port direction settings etc.before this piece of code. It is working correctly. But delay_ms() seems not become compiled because I see very short (around 300-500 ns) pulses using an oscilloscope.
I tried to use delay_ms( 10000) insead of delay_ms(10)... Nothing changed.
Then I tried to increase i and j end values in delay_ms() function. Nothing changed.
for instance
Instead of for(i=0;i for(j=0;j<6553;j++);
I tried for(i=0;i for(j=0;j<16553;j++);
pulse durations did not changed. The stranger thing is, I compared two hex files byte by byte and they are identical! so 6553 to 16553 does not change anything in code.
Then I thought may be the compiler does not compile dummy loops because of optimization, I added some arithmetic calculations in loop:
Code:
for(i=0;i for(j=0;j<6553;j++) a++;
nothing changed. It seems loops are not compiled. ?
I thought may be there is another delay_ms function in the search path include files. I changed the name to my_delay_ms... Nothing changed.
Finally I did something like this:
Code:
void delay_ms(long int ms)
{
long int i, j;
for(i=0;i for(j=0;j<6553;j++) {
IOSET1 = 0x00000001; // set P1.1... it is an unused pin. just for testing
}
}
after this delay_ms has effect (delay). Why It does not work and it has no effect if I do not place a port operation inside the loop?