Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MSP430 Delay Fnct Erasing Variables

Status
Not open for further replies.

wuchy143

Member
Hi All,

I'm witnessing something odd and was wondering if I'm doing something incorrectly. I'm just trying to blink an LED at some rate for debug on my board. I'm new to MSP430's compiler. So in debug mode I step through this snippet of code:

Code:
while(j <= 250)
	{
		__delay_cycles(thousand);
		j++;
		P1OUT ^= P1OUT;
		__delay_cycles(thousand);
	}

It runs and counts up j until it gets to 15. Then it clears itself after one of the delay cycles. I'm stumped. In the datasheet for the compiler:

https://www.ti.com.cn/cn/lit/ug/slau132c/slau132c.pdf

on page 109 it says that this delay does not effect anything. Though it is....

Any thoughts?
 
Really? I use that intrinsic function a lot. The "thousand" value is a constant, right?

Let me simulate it and I'll get back...

<added>

Wow! That's wierd. I get the same thing. If I change the variable name to "x" it works. Also, using variable "j", if I "single step" through the assembler code it increments correctly from 0x0F to 0x10. This might be worth reporting to TI...

<added>

Wait! Just changed the variable name back to "j" and now it's working. I'm using CCS (Code Composer Studio) v4.2.4.00033 and now I'm wondering if it isn't a bug in the simulator???
 
Last edited:
yes thousand is actually = 1,000

thanks for simulating. I may do a system reboot. Not really sure what's going on.
 
Assuming you are initializing j to 0 or 1 before this loop.

Full Code? Did you disable the watchdog timer? You'll see on all MSP430 code a small bit of code to either turn off or properly setup the watchdog timer.
 
:) ugh. somehow I put the disable WDT in one of my functions instead of ontop of main. I feel like a box of hammers. :) thx for the help though I should have figured that out myself.....works great now hahah. Makes me want to kick the dog....
 
Last edited:
I did want to note I have the wrong syntax in my code. To toggle the LED I had:

P1OUT ^= P1OUT;

Should be:

P1OUT = ~P1OUT;

Just wanted to clear that up to not confuse people who might use this.
 
:) ugh. somehow I put the disable WDT in one of my functions instead of ontop of main. I feel like a box of hammers. :) thx for the help though I should have figured that out myself.....works great now hahah. Makes me want to kick the dog....
Darn, I'm embarrassed too. I had simply added your code into an existing program, compiled, then moved the program counter to a "j = 0" instruction. So I pretty much skipped the instructions to disable the WDT too. Sorry!!!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top