This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

variables problem (maybe optimalization?), LaunchPad

Other Parts Discussed in Thread: MSP430F5438, MSP430G2553, MSP430G2231

Hi,

I have some problem with my program. Im getting started with launchpad, so I am trying some really basic codes. I have some experiences with MSP430F5438 so I thought, that will not be problem. But I have problem that I dont understand.

When I run this code, everything goes OK.

#include  "msp430x20x2.h"

unsigned int pom=0;


void delay(void);

int main(void)
{
 pom = 0;
 while(pom < 100)
 {
  pom = pom + 10;


  delay();
  //some code...

  delay();
 }
 
 while(1); //end while

}

void delay(void)
{
 unsigned char k;
 
 for( k=0 ; k<50 ; k++ );
}
-----------------------------------

But when I change

 for( k=0 ; k<50 ; k++ );

to

for( k=0 ; k<250; k++ );

in delay function everything goes wrong. Variable "pom" does never reach value of 100 in the main while. It always resets to 0 after some while cycles. Reset occurs after calling second delay(). This code is not my comlete test code, but it extrtacts problem. I guess there could besome kind of optimalization?

I experince this problem on MSP430G2231 and also on MSP430G2553.

Thank you very much for answer!

EDIT:

The same effect has _delay_cycles(); macro.

This code:

 #include  "msp430x20x2.h"

unsigned int pom=0;


void delay(void);

int main(void)
{
 P1DIR |= BIT6;
 P1OUT &= ~BIT6;
 
 pom = 0;
 while(pom < 100)
 {
  pom = pom + 10;


  _delay_cycles(1000);
  P1OUT |= BIT6;

  _delay_cycles(1000);
  P1OUT &= ~BIT6;
 }
 
 while(1); //end while

}

works but this code

#include  "msp430x20x2.h"

unsigned int pom=0;


void delay(void);

int main(void)
{
 P1DIR |= BIT6;
 P1OUT &= ~BIT6;
 
 pom = 0;
 while(pom < 100)
 {
  pom = pom + 10;


  _delay_cycles(10000);
  P1OUT |= BIT6;

  _delay_cycles(10000);
  P1OUT &= ~BIT6;
 }
 
 while(1); //end while

}

has the same problem.

 

**Attention** This is a public forum