News:

SMF for DIYStompboxes.com!

Main Menu

Debugging AVR code

Started by bioroids, April 30, 2006, 10:45:14 AM

Previous topic - Next topic

bioroids

Hi!

Is there a way, using the STK500 and Studio 4, to debug the actual code programmed in the chip?

Because, the simulation is good, but is not too real sometimes, like when using hardware stuff as the ADC.

Thanks!

Miguel
Eramos tan pobres!

Peter Snowberg

What you want is called ICE, or In Circuit Emulation.

Unfortunately, ICE takes additional hardware. The good news is that ICE boxes used to cost many thousands of dollars and Atmel gives you these capabilities for $300 by using the JTAG ICE. The new version (JTAGICE mk II) adds DebugWire which lets you probe many more chips.

http://atmel.com/dyn/products/tools_card.asp?tool_id=3353
http://www.digikey.com/scripts/DkSearch/dksus.dll?Detail?Ref=21393&Row=301438&Site=US

I bought the original JTAG ICE pod a few years ago and I LOVE it! It's every bit as good as switching from dial-up to broadband and then some.

I know it's expensive, but ICE capability used to cost $15000 for some chips so $300 is an amazing bargain! 8)
Eschew paradigm obfuscation

The Tone God

#2
JTAG is the way you want to go for AVR ICE IMHO but at this level the JTAG would be overkill. For anything being done at the moment one really needs to learn to develop their debugging skills. Knowing how to break code down into functional steps, testing, using the LED output, etc. are what is valuable right now. Even if you had a JTAG and saw everything going on you still have to know why something is happening and how to fix it. There is no hardware you can buy that can teach that.

This is not intended intended to be slight on anyone. I would just like to point out to future designers that more money and more tools won't make up for lack of skills. Mind you I am talking to group that sometimes thinks that effects made the musician not the talent. ;)

Andrew

bioroids

Thanks, you are right about that, is not like I'm programming robots :). Just wondered if the STK500 was capable of that, which would be very nice but I can't justify the money it costs.

And my problem was only lack of understanding of the >> operator  :icon_cool:
It seems that the right shift fills the new bits with ones instead of zeroes, if the MSB is set. That is very counterintuitive if you ask me, but I suppose it has something to do with preserving the sign of the data?

Thanks again

Miguel
Eramos tan pobres!

The Tone God

Quote from: bioroids on April 30, 2006, 02:48:31 PM
Thanks, you are right about that, is not like I'm programming robots :). Just wondered if the STK500 was capable of that, which would be very nice but I can't justify the money it costs.

Nah the STK500 is just a programmer and devlopment board. Basic stuff.

Quote from: bioroids on April 30, 2006, 02:48:31 PM
And my problem was only lack of understanding of the >> operator  :icon_cool:
It seems that the right shift fills the new bits with ones instead of zeroes, if the MSB is set. That is very counterintuitive if you ask me, but I suppose it has something to do with preserving the sign of the data?

Thats interesting. I would have to see the code to understand more but I guess that is another topic. Now you probably not have learned that lesson with a JTAG doing the thinking for you. :)

Andrew

Peter Snowberg

JTAG is another set of eyes, but with telescopes attached. It doesn't do any thinking. It does however allow you to test a hypothesis with the CPU hooked to target hardware.

I've never liked software emulation. :icon_biggrin:
Eschew paradigm obfuscation

bioroids

Quote from: The Tone God on April 30, 2006, 03:10:41 PM
Thats interesting. I would have to see the code to understand more but I guess that is another topic. Now you probably not have learned that lesson with a JTAG doing the thinking for you. :)

It was in fact about the sign. I first worked it around by forcing all unwanted bits to 0 after the right shift.

data1 = data2 >> 7;
data1 &= 0x01;


Now I found a better solution, to declare the variables as unsigned char data1, data2; and the extra AND is not needed anymore.
I guess the lesson is "always use the right type for your variables"  :icon_cool:

Luck

Miguel

Eramos tan pobres!

The Tone God

Quote from: bioroids on April 30, 2006, 04:41:27 PM
Now I found a better solution, to declare the variables as unsigned char data1, data2; and the extra AND is not needed anymore.
I guess the lesson is "always use the right type for your variables"  :icon_cool:

You should use unsigned when possible. Notice I used that even in the "Hi There!" program. You will get the full positive range of the variable mean 0-255 instead of +/- 127. The compiler will also use more efficient optimization for math when you use unsigned. Of course you won't get odd behaviour when doing various math operations either like you had with the shifting.



Andrew