# Atmega8 debugging on AVR Studio 6.2

Status
Not open for further replies.

#### sunil21

I am working on a project with atmega 8 and doing the code in Avr studio 6.2 and simulation in proteus.

I am trying to debug few float related functions.
i.e., for testing purpose I have created one AVR program with a main function and the function I want to test,
no hardware is needed and so not connected. the function is related to ADC and doing some float maths and all... and returns a value. for accurate testing purpose I wrote the dummy main which calls this particular function and returns a value to the main function.
my question is how can I debug this without connecting to a hardware. I am using usbasp to program this software, I don't think this allows any debugging!

When I wrote this program in to AVR studio 6.2 and try to debug it ask me to connect a hardware.
In Proteus , I tried this and the simulation stopped when the float part comes up.

#### pic.programmer

Do you want to debug in hardware or Proteus ? For proteus you have to use the .cof file for debugging. You have to generate .cof file and load it in Proteus. If you want to debug in hardware you need a debugger like ATMEL ICE or AVR ONE.

It would be good if you zip and attach the complete Atmel Studio project files and Proteus file. I will try to debug in Proteus and see.

#### sunil21

I checked youtube and there were some videos on debugging by atmel.

as specified in the video I used simulator from the options and started to debug.

for test purpose I used the code below

Code:
/*
* FLOAT_TEST_MC_NO.c
*
* Created: 21-08-2015 1.15.03 PM
*  Author: USER
*/

#include <avr/io.h>

unsigned int dummy(unsigned int doo)
{

return 102;
}

int main(void)
{
unsigned int retval=0;

retval= dummy(90);

retval = 90*10;

while(1);

}

when I press the "Start debugging and break " option , a yellow cursor appears at the start of the left curly brace and blinks.
It is supposed to go to next instruction when I press, F10, F11 etc.. no matter what I click, it still blinks and stays there right at the start. when I press F5 , I can see "Running" written at the bottom and the program in not responding.

#### bigdogguru

It sounds as if you have not set a breakpoint, without a breakpoint set, the microcontroller will continually execute the while loop or Super Loop to which it is often referred.

Set a breakpoint on the Super Loop, then when ran the execution flow should break between each execution of the Super Loop.

Or set a breakpoint on the other statements in your code, such as the call to the dummy() routine.

To see more interactive single stepping of the code,

Try replacing:

Code:
while(1);

With:

Code:
int x;

while(1)
{
x++;
}

Or better yet:
Code:
while(1)
{
retval= dummy(90);

retval = 90*10;
}

BigDog

#### alexan_e

In order to be able to watch a variable value (at least in proteus) the variable should be declared as volatile to prevent optimizations.
I think the same stands for AVR studio too.

#### bigdogguru

the variable should be declared as volatile to prevent optimizations.

Good point.

While not always the case as the out come largely depends on the specific compiler and the current optimization setting, some compilers can actually optimize away an empty while loop or a while loop which simply modifies the value of a variable which is not utilized elsewhere in the program.

Therefore it's always best to either insert an inline assembly NOP instruction or insert a token operation on a variable declared as volatile, such as:

Code:
[COLOR="#FF0000"]volatile[/COLOR] int x;

while(1)
{
x++;
}

BigDog

Status
Not open for further replies.