Intro to Microcontroller Debugging (and a Pomodoro Timer)

 by kphlight
Featured
DSC00423.jpg

Hello Hack-A-Day and Dangerous Prototypes readers!  Please vote for me in the Sparkfun uC Contest!  (If you vote for me you can still vote for other projects as well)  The vote button is just up and left of here... there you go... closer... closer...  I know you can do it...




1.) I do, in fact, own an Arduino and despite this being a microcontroller project on Instructables, an Arduino is NOT a part of this guide. An Arduino has it's specific uses and fills a niche in my toolkit very well but Arduino is usually not my first choice when deciding which platform I'll prototype my latest idea with. One of the best parts of the Arduino platform is that it is streamlined to the point that anyone can use it without being an engineer. However, someone serious about the code they are writing for their project, will before long, need an essential feature: in-circuit debugging. We'll go over why ICD is so great and discuss how to use it as we build this simple project.

2.) What the heck is a Pomodoro timer, you ask? The Pomodoro technique is a means of time management created by Francesco Cirillo. You can find lots more information here: http://www.pomodorotechnique.com/ Personally, I love the Pomodoro technique but didn't want to run yet another application on my computer. Thus, I needed a simple timer. If you don't need or want a Pomodoro timer, the end result of this Instructable isn't as important as the means of getting to it and learning how to debug. What I really want to teach is some simple debugging concepts your average Arduino user may not know they are missing out on.

3.) This project is based around the Texas Instruments LaunchPad development board, an MSP430G2211 and five LEDs. If you don't have a Launchpad and have any interest in embedded programming at all, please just order one now. You can thank me later.

Take a look at the final step for the components needed for the pomodoro timer, if you're interested in making one.

4.) IAR Embedded Workbench Kickstart for MSP430 is the development environment we'll be using. Download it from here: http://www.ti.com/iarkickstart This is unfortunately a Windows-only IDE, but it runs in various virtual machines on both Linux and OS X. For this Instructable, I'm using Parallels on OS X. If there is sufficient interest, I'll write a guide for MSP430 development using FOSS tools on OS X.

 

 
Remove these adsRemove these ads by Signing Up

Step 1: Putting the prototype board together

Got all of the parts? Good. Let's throw this thing together real fast. First, DISCONNECT the Launchpad from your computer if it is connected. The Launchpad should NOT have power.

Remove the TXD, RXD, and P1.6 jumpers from the board. Put the microcontroller in the Launchpad if you haven't already. The groove in the microcontroller goes towards the USB connector.

LEDs don't work if put in backwards so pay attention to their polarity. Here is a quick primer if needed: http://www.sparkfun.com/tutorials/222. Thanks Sparkfun!

For all five LEDs, bend the cathode straight out. (That's the short leg). Put the LEDs, 100ohm resistor, and paperclip together like they are in the picture. I'd prefer a bit solder to the paperclip, but we're keeping things as simple as possible.

The LEDs, one each, are in ports P1.1 – P1.5.  The paperclip prototyping method seen below works in lieu of solder.  The 100 ohm resister completes the LED's path to GND.

My piezo speaker was a lucky find as it already had a .1” pitch header on it. It that is the case, you can remove the P1.6 jumper and attach the speaker directly to the board. Otherwise, you need to make a connection from P1.6 through the speaker to GND.

For those that want to make this a stand-alone device, the final schematic is included in this guide on the last page. 
0x4C4A says: Jan 20, 2013. 1:00 PM
I'd like to thank you for this example code - had a hard time understanding how to use timers and this definitely helped a lot (don't care a bit for the pomodoro, just the example of how to make a proper Timer interrupt). :)
NewB007 says: Feb 19, 2011. 5:08 PM
After I learned my C bitwise operators and figured out that you were using the Hex numbers to filter bits, I found the error before I read about it in step 5! Thanks for the great intro to debugging, and for making it just complex enough that I had to learn something new!

It's probably absurd that I understand all that without knowing any programing languages. Time to learn C! :)
NewB007 says: Feb 15, 2011. 7:38 PM
In Step 2, the line "WDTCTL = WDTPW + WDTHOLD;" is in your comment.
Looking at the screenshot in Step 3, you did not intend this.
I though it was an intentional bug at first, until I kept reading.

In the meantime, I am still trying your example. I am not familiar with C, MSP430s, IAR, or really any of it. I understand the basics of programing and circuits, but despite having compiled and downloaded the code, all I have managed to do is get the P1.3 LED to glow dimly and continuously. The other LEDs and buzzer show no signs of anything. I have tested the LEDs through the paperclip junction (alligator clip on mine) for continuity, and the joint is good. I have rearranged the LEDs and moved the buzzer between the two acceptable location to no avail. I haven't noticed any magic smoke. Do you have any ideas for what I could be doing wrong and/or how to correct it?
kphlight (author) in reply to NewB007Feb 16, 2011. 4:18 PM
Excellent! I believe mouritsen is having the same problem. If you go to "Download and Debug" and it finished instantly, you're probably still using the simulator. It takes a few seconds to program the actual microcontroller.
mouritsen in reply to NewB007Feb 16, 2011. 12:29 AM
I get the exact same result as NewB0007. P1.3 LED glows dimly and no other LEDs ever light up. I noticed if I press S2 then P1.3 LED turns off until I release S2. Also LED1 and LED2 continuously flip on and off back and forth as in red-green-red-green, etc. If I unplug the USB cable and disconnect the LEDs and 100 Ohm resistor the default temperature program still works. I don't think my code is being written to the chip. Any suggestions? This is my first project since my 430 came in the mail today, so maybe there is some kind of initial setup I need to do either in IAR or something else? Any help would be great. Thanks for the tutorial. I'm looking forward to learning how to use this thing.
kphlight (author) in reply to NewB007Feb 15, 2011. 7:51 PM
Thanks for the heads up about the bug on page 2. You definitely need to include the WDTCTL line. Should be fixed now.

As for getting the LEDs to turn on, try stopping execution after this line:

P1OUT |= (LED0 + LED1 + LED2 + LED3 + LED4 + BUZZER);

At that point, you should have 5v coming from P1.1-5. It may be best to test each point individually with a multimeter or move the LED->alligator/paperclip->resistor bridge to each point. There isn't really any need to test the buzzer at that point.
NewB007 in reply to kphlightFeb 15, 2011. 8:07 PM
You're welcome. It is correct above, now.

I tried your suggestion, and I am getting 1.6V on P1.3, independently of wherever I stop it. No other pin is supplying voltage. I think I must have a download error, or a dead chip. I'll have to find a way to test that, I guess.
kphlight (author) in reply to NewB007Feb 15, 2011. 8:14 PM
While the code is running, the LED ports will be cycled on and off very quickly. So quickly in fact that a multimeter will show half of the "on" voltage (3.3v * 0.5 = 1.6V). [*** Note my above comment says 5v where it should be 3.3v. ***]

NewB007 in reply to kphlightFeb 15, 2011. 8:28 PM
I meant to say "I noticed that you have not soldered the included crystal to the pads, whereas I have."
kphlight (author) in reply to NewB007Feb 15, 2011. 9:04 PM
My project relies on the internal oscillator. Using the external osc would likely make for a bit more accurate timer, if you intend to take the project that far, but simply soldering it to the board isn't enough to cause the microcontroller to use it. There are fuse bits that need to be set. Don't worry about that for now. Trying running this:

#include "msp430g2211.h"
#define LED4 BIT1
#define LED3 BIT2
#define LED2 BIT3
#define LED1 BIT4
#define LED0 BIT5
#define BUZZER BIT6

void main( void ) {

// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
// Set DCO to 1MHz factory calibration value
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;

//all LED pins and buzzer as output
P1DIR |= (LED0 + LED1 + LED2 + LED3 + LED4 + BUZZER);

P1OUT |= LED0;
P1OUT &= ~LED0;
P1OUT |= LED1;
P1OUT &= ~LED1;
P1OUT |= LED2;
P1OUT &= ~LED2;
P1OUT |= LED3;
P1OUT &= ~LED3;
P1OUT |= LED4;
P1OUT &= ~LED4;

while(1){} //do nothing forever...

Step through all the P1OUT lines individually to make sure they are turning the correct pin on and off.
NewB007 in reply to kphlightFeb 16, 2011. 3:43 PM
Problem solved!

I noticed my error while setting up a Workspace for your test code. It turns out that my problem was scrolling my mouse wheel after selecting "FET Debugger" under "Driver," so that I had inadvertently been working under "Simulator." I ran your "helloworld" to confirm that my hardware worked, and then re-ran your Step 2 code.
NewB007 in reply to kphlightFeb 15, 2011. 8:26 PM
Thanks, that explains the voltage difference! I guess the issue now is why P1.1, P1.2, P1.4, and P1.5 don't want to cooperate... I noticed that you have not soldered the included crystal to the pads. Could that explain my discrepancy?

I guess I will just have to try a hello world to each of the pins tomorrow to see if I can isolate the problem.
csammis says: Feb 15, 2011. 11:52 AM
"If there is sufficient interest, I'll write a guide for MSP430 development using FOSS tools on OS X."

+1 for interest on this topic! I just got a couple Launchpads for my first ever foray into uC programming and I'll soon be getting an OS X machine. Being able to use those together would be awesome.
kphlight (author) in reply to csammisFeb 15, 2011. 9:09 PM
Vote for me in the Sparkfun Microcontroller contest and the odds of me writing a MSP430 in OS X guide will grow exponentially :)

Seriously, though, I think that'll be my next Instructable.

PS... seriously, though, vote for me!
frank26080115 says: Feb 13, 2011. 9:54 PM
I just want to point out that you shouldn't connect a lot of LEDs with only one resistor. Although you might think that the current flow is evenly distributed through all the LEDs, they are not, one might have more current flowing through it than the others due to very slight differences in conductance. For the purposes here, it's not a big deal, just a bad habit.

Also just a reminder for everybody, two diodes rated at 1A each placed in parallel does NOT mean you can let 2A through, unless the diodes are absolutely identical, which is almost impossible in the real world. One will let more current flow through than the other, and that one gets warmer, and actually increases its conductance.
BadWolf Corp in reply to frank26080115Feb 15, 2011. 10:31 AM
Don't forget that he probably set the resistor like waaaaay above the limit to make sure that erven with 5 leds on,the current won't kill it. I'm pretty sure you didn't think about that ;)
kphlight (author) in reply to BadWolf CorpFeb 15, 2011. 10:46 AM
To be perfectly honest I didn't calculate how much the output pins are sourcing because I didn't recommend a specific LED for the project. While I could calculate what I'm using, it wouldn't be the same for others anyway.

Debugging, not the circuit, is the emphasis of the tutorial. From personal experience, MSP430G2xxx's are able to both sink and source much more than the datasheet specifies so I felt comfortable with extremely easy solution.

That obviously shouldn't be relied on for a critical project but for this purpose, the single GND port can be used for the sake of convenience.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!