MSP430 LauncPad: ignores wait for button line of code - Page 1
Forum section: electronics / general

author: jproject
author_rank: Contributor
timestamp: June 16, 2011, 04:39:12 am
content: Hello everyone,I'm in this weird situation and google won't give me the right answers. So... I made a robot that moves in a square area and it works perfectly except for one damn thing! The robot isn't suppose to move until I press the button.It works perfectly fine when it's powered by the usb and the computer but when I plug in a 3V battery as its power source, the code for the "wait until the fricken button is pressed" is ignored. This is the line of code for wait until button is pushed:while((P1IN & 0x08) == 0x08); //Wait until button is pushedAnother program that I use, which uses the exact line of code, does not show any problems when I run it using the 3V battery source. But, the hold button line works if it has some coding in front of it like flash some pretty LEDs, etc. My guess is the initial power up of the LaunchPad makes the line skip for some reason.Helppppppppppppp pleaseeeeeeeeeThank you.

author: joelby
author_rank: Frequent Contributor
timestamp: June 16, 2011, 05:04:23 am
content: I haven't seen anything like this, but could it be some sort of power settling/glitching thing?You could try the following:Add a start-up delay before doing anything (tens of milliseconds)Implement debouncing for the button in software. Using a simple state machine, detect a button press, wait for a few milliseconds, check if the button is still depressed, and only proceed if it is.

author: TheDirty
author_rank: Frequent Contributor
timestamp: June 16, 2011, 02:21:54 pm
content: You're looking for a high value for the push button? Don't you have it pulled up and push to ground? It's not floating, is it?

author: baljemmett
author_rank: Unknown
timestamp: June 16, 2011, 02:35:07 pm
content: Quote from: TheDirty on June 16, 2011, 02:21:54 pmUnless the MSP430 inverts the input bits or something, that's waiting for a low, isn't it?

author: jproject
author_rank: Contributor
timestamp: June 16, 2011, 03:56:19 pm
content: The switch button uses the pin P1.3 and I have not modified it in any way. The only time the 0x08 is used is in the line for the one I showed it.

author: TheDirty
author_rank: Frequent Contributor
timestamp: June 16, 2011, 05:36:54 pm
content: Quote from: baljemmett on June 16, 2011, 02:35:07 pmFor some reason I assumed it was an 'if', rather than a while. I just scanned the condition. My fail at reading.

author: tsmz
author_rank: Contributor
timestamp: June 18, 2011, 08:06:14 pm
content: Please describe the circuit you're using and the port setup in your program.Programs will seldom mysteriously stop working, so there has to be a problem somewhere. My first guess would be incorrect signal levels, i.e. configured pull-up instead of pull-down, floating switch etc. You could also use the debugger to check the registers while the program is running to see if it's a signal level problem or a code problem.

author: jproject
author_rank: Contributor
timestamp: June 19, 2011, 03:09:18 am
content: I made a hotfix by flashing some pretty LEDs first before the while statement for the button. Also, in debugging mode, the program works perfectly.

author: Unknown
author_rank: Unknown
timestamp: June 19, 2011, 06:38:59 pm
content: Maybe the compiler optimizes the while loop away since it not actually doing anything, just like the famous for (i=0; i<1000;i++); loops for delay, which won't work either with any optimizing C compiler.

author: insurgent
author_rank: Regular Contributor
timestamp: June 19, 2011, 06:57:52 pm
content: Quote from: alm on June 19, 2011, 06:38:59 pmThis could be a possibility, though if he's using TI's header files, P1IN is defined as volatile and the compiler will not optimize out the loop. If, however, he has it defined himself for some reason the it would definitely be optimized out if lacking the volatile indicator.

author: jproject
author_rank: Contributor
timestamp: June 20, 2011, 03:23:32 pm
content: I put this into a possibility as well but Code Composer Studio usually tells me if that happens. For example, certain int variables will give me warning signs after I build and compile because it is not volatile.

author: tsmz
author_rank: Contributor
timestamp: June 20, 2011, 08:06:48 pm
content: Have you looked at the generated assembler code? It's a bit messy, but you can probably tell if something goes horribly wrong. Another way is to actually look at the assembler instructions on the device, which I find much more useful because you can actually single-step through the program.

author: TheDirty
author_rank: Frequent Contributor
timestamp: June 22, 2011, 12:54:35 am
content: Quote from: tsmz on June 18, 2011, 08:06:14 pmYou never answered any of this. If it's not a programming thing, it has to be a hardware issue. You've checked the voltage on the input line when running from 3V?