Why delay loops are not working in mspgcc?

Status
Not open for further replies.

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
751
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,054
Why delay loops are not working in mspgcc ?
I tried to put a delay loop using while loop, for loop etc...But I couldn't observe the delay...
Is the compiler optimizing the code? If so, how could I introduce a delay in mspgcc?
below code is not working
Code:
for(i=0;i<10000;i++){}
 

Re: MSPGCC delay problem

I tried to put a delay loop using while loop, for loop etc...But I couldn't observe the delay...
Is the compiler optimizing the code? If so, how could I introduce a delay in mspgcc?
below code is not working

Yes, most likely this is the problem. You could turn all compiler optimization off and this may left the delay loop intact. However, producing delays with loops is poor programming style and quite frankly inaccurate. It is also a major pitfall beginning programmer fall into, most likely due to the fact many of the free version of commercial compilers have the optimization either turn off or very limited. Unless you want to spend hours of trial and error in an attempt to write a delay in C, the most accurate and straight forward way is to write it in the assembly language device. Also with careful planning you can then use these delay routines in a portable module with all the members of that MCU family.


Tips and trick for efficient programming using MSPGCC - Reference item 16

static void __inline__ brief_pause(register unsigned int n)
{
__asm__ __volatile__ (
"1: \n"
" dec %[n] \n"
" jne 1b \n"
: [n] "+r");
}


I believe MSPGCC may also have the intrinsic function:

__delay_cycles(unsigned long numOfCycles);

Although, I do not know this with certainty, this maybe another option.

However, the routine contained in displayed above would be the preferable method of producing a delay. Or a similar custom assembly routine written by yourself.


BigDog
 
Re: MSPGCC delay problem

I have downloaded the datasheet of MSP430G2231 from ti.com. But I couldn't find details about the timer module registers etc...Earlier I used PIC but there I could find every details in the datasheet.. From where I could get these details?
 

Re: MSPGCC delay problem

Unfortunately, TI divides their datasheets up between device specific and common family. You probably downloaded the device specific datasheet and now need the common family datasheet.

Which MSP430 are you using?

BigDog
 
Re: MSPGCC delay problem

Here's the common family datasheet:

**broken link removed**

And the product page with erratas and appnotes:

MSP430G2231 Product Page

There are quite a few relevant appnotes, including one on Mixed C and Assembly.

BigDog
 
Re: MSPGCC delay problem

Sir,
Thanks a lot for the information...Now I could find everything in the family users guide....

---------- Post added at 09:47 ---------- Previous post was at 08:15 ----------

my first mentioned delay problem is now solved...
My mistake was, I just ignored the watchdog timer!



this is the link from which I got the tip:
kb8ojh.net - MSP430 - MSP430 Programming: Tips and Tricks
(may be helpful to some one having the similar problem in future)
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…