Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Atmega8 debugging on AVR Studio 6.2

Status
Not open for further replies.

sunil21

Advanced Member level 4
Joined
Dec 2, 2010
Messages
108
Helped
4
Reputation
8
Reaction score
5
Trophy points
1,298
Activity points
2,394
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

Advanced Member level 3
Joined
Aug 19, 2015
Messages
773
Helped
141
Reputation
284
Reaction score
140
Trophy points
43
Activity points
7,542
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

Advanced Member level 4
Joined
Dec 2, 2010
Messages
108
Helped
4
Reputation
8
Reaction score
5
Trophy points
1,298
Activity points
2,394
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

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,422
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

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,375
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

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,422
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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top