AVR Tutorials
The Best AVR Microcontroller Tutorials on the Web

Verifying the Calculated Execution Time


This AVR tutorial will explain how to use the simulation capability of AVR Studio 4 to verify the calculated execution time.

For this AVR tutorial we will be using the AVR assembly code from the Calculating Execution Time for Code with Double Loops tutorial.

Steps to verify your calculation with AVR Studio

  1. Open AVR Studio 4 and create a new AVR assembly project.
  2. Type the code in the editor and add the following line at the end of the code:
    End:             RJMP    End

    The entire code in the AVR Studio editor should be similar to that below:

                     LDI   R16, 5 
    Again:           LDI   R17, 4
    Here:            DEC   R17
                     BRNE  Here
                     DEC   R16
                     BRNE  Again
    End:             RJMP    End
  3. Go to the Build menu in the AVR Studio 4 and select Build and Run. You should get a screen looking like the one below:

    AVR Studio is now in simulation mode notice the yellow arrow, which indicates the microcontroller is about to execute this line of code.

    Also notice the 'Processor' window pane to the left, which indicates the value of the Cycle Counter, Frequency, Stop Watch, etc. At this point the Cycle Counter and Stop Watch is at 0, indicating that no instruction as been executed. The Frequency for this simulation is set to 4MHz.

  4. Position the cursor at the beginning of the line "End: RJMP End". Then go to the Debug menu and select Run to Cursor.

    The simulator will now execute all the instruction up to where the cursor is located. You should now see an update 'Processor' window pane showing the number of cycles that has passed to execute up to this point in the code, given by Cycle Counter.

    We are interested in the Stop Watch value which gives the time taken to execute the instructions up to this point in the code. That is the Execution Time for our code.