Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Strange Behaviour or WinARM with LPC2148 (delay_ms function)

Status
Not open for further replies.

Sobakava

Full Member level 6
Joined
Mar 27, 2002
Messages
350
Helped
8
Reputation
16
Reaction score
8
Trophy points
1,298
Activity points
3,342
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:

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?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top