a few questions regarding simulator debugging

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to get to grips with the simulator in atmel studio 6, I have a very simple program and i'm stepping through it line by line. 

 

#include <avr/io.h>

 int main(void)
 {
 	ddrb = 0b00001111; 
     while(1)
     {
         portb = 0xff;
         portb = 0x00;
         portb = 0xff;
         portb = 0x00;
     }
 }

so, as I step through the code I watch portb on the IO view and there are a few things happening which confuse me -

 

1.  after i enter the while loop, the first line never seems to get executed - the program steps through the last three lines and the first is never highlighted or executed

2. the last line in the loop is highlighted but never executed: I watch the IO view and it the portb doesn't change as the highlighted line switches from the last line to the 2nd line

3. the timing on the processor window seems completely different from what i actually see when I program the chip (atmega328) this window indicates that each line gets executed in one clock cycle - is that correct?

4. when the program moves from the last line to the first (second), it takes many clock cycles, why is this?

5. also, is there a way to see the assembly code this gets compiled to, or does it go straight to machine code? It would be useful to be able to see exactly how commands get interpreted..

thanks!

Philip 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can't believe that your program would even compile.

 

PORTB is spelled in capital letters.

 

You have not even declared any variable called portb.

portb does not exist.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

believe it or not it does compile, and it does the same thing if I put it in capital letters - I suppose the program must have corrected it. 

 

can you help answer any of my questions? 

 

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well,   if it does compile,   you must be using a very strange C Compiler.

 

If you use the correct spelling and the avr-gcc Compiler (the default with AS6),   then the Simulator would allow you to step through each line.    Add breakpoints,   inspect the whole set of PORTB special function registers.   (DDRB, PINB, PORTB)

 

David.

 

Edit.   When you have built it properly,    start the Simulator,   View the Disassembly.    Step through the code.   Inspect the Cycle counter.

Last Edited: Thu. Dec 4, 2014 - 08:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes after replacing the correct code the same thing is happening so i have pasted my original comment here for your convenience :) As I step through the code I watch portb on the IO view and there are a few things happening which confuse me -

 

1.  after i enter the while loop, the first line never seems to get executed (actually, it is executed the first time but never after that) the program steps through the last three lines and the first is only executed in the first time round the loop

2. the last line in the loop is highlighted but never executed: I watch the IO view and it the portb doesn't change as the highlighted line switches from the last line to the 2nd line

3. the timing on the processor window seems completely different from what i actually see when I program the chip (atmega328) this window indicates that each line gets executed in one clock cycle - is that correct?

4. when the program moves from the last line to the first (second), it takes many clock cycles, why is this?

5. also, is there a way to see the assembly code this gets compiled to, or does it go straight to machine code? It would be useful to be able to see exactly how commands get interpreted..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is very important to spell PORTB correctly.    Both in your actual code and in your messages here.

 

1.    Build your program.

2.    Select Tool->Simulator

3.    start "Debugging and Break"

4.    the yellow arrow should stop at the main() function.

5.    now select View->Disassembly.

6.    this should display the ASM code and it will 'attempt' to show the corresponding C statement(s)

7.    View the Processor window.

8.    rearrange your windows to show all the things you are interest in.   e.g. Processor, IO View, ASM code,  ...

 

Note that (6) does not always look obvious at first sight.

 

Now do your stepping.   Obverve PORTB,  Cycles, time, ...
 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ahhh, right OK - so the disassembly view shows that for the the last step is one clock cycle, the jump is two, the first step in the loop is also one clock cycle so from the last step to the second step of the loop there are four clock cycles, which is consistent when viewing the C code step through - but why does it only show this in the disassembly view? In the C view (for want of a better name) the program just looks like it's skipping bits in the manner i described..

Last Edited: Fri. Dec 5, 2014 - 06:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quite often, 'C' compilers implement loops with the test at the end - so it will look like execution initially jumps to the end of the loop, before starting at the beginning...