NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » debugging

April 16, 2009
by nofpu
nofpu's Avatar

Hello AVR users... what is the cheapest, best opensource debugging solution? Many thanks

April 18, 2009
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi nofpu,

In my experience, I've found that I'm able to get the debugging information I need through a combination of the LCD screen, serial port, and LEDs / measuring voltages directly. The ATmega168 chip supports something called a "debugWIRE On-chip Debugging System" (see datasheet), but I personally haven't tried using it. Let us know what you find!

Mike

June 19, 2009
by BobaMosfet
BobaMosfet's Avatar

One of the BEST ways to debug a program is, simply, to flow-chart it. It's effecient, it shows professionalism, and it works.

June 20, 2009
by wayward
wayward's Avatar

I agree with BobaMosfet that the best way to "debug" a program is to make sure it was well-written in the first place (a kind of Sun Tzu-ish advice, really). Regardless, sometimes we have to take up arms and wage war against bugs, and for that we need good strategy and good tactics in equal measure.

In the war against bugs, good strategy consists of: - decomposing your program into short, well-rounded functions; - using well-named variables and controlling their scope (only use global variables when you must; use loop-local variables whenever you can); - putting markers along the road (i.e. comments); - etc.

When your strategy is sound, you don't need awesome tactics, even for fairly large-scale assaults. If you localize the things that change, test in advance, and parameterize stuff that lends itself to parameterization instead of duplicating the code, you're climbing the high ground against bugs. Even fairly simple tactics suffice then: - logic probe and voltmeter on pins (as per mrobbins's advice); - LCD/UART for displaying debug info (-||-); - while(1) {} to stop program execution just after the critical part you want to test;

I never tried JTAG either, but I never needed it either.

In conclusion, my experience so far suggests that if you can isolate the "bug" in your code so much that it can be reproduced in a simple (10-20 lines) piece of code, suitable for posting to a mailing list, then you can solve it yourself.

Post a Reply

Please log in to post a reply.

Did you know that two resistors plus a transistor can be used to make a better voltage supply? Learn more...