Atmeg8 clock check on Simulator

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

i newbie in avr programming and i faced strange behavior to me during  i made very simple program to check the cycle of  program execution 

 

As you can see from the snap shot of Code during execution then paused when reached the Braking point  that the Cycle Counter is "458789" in processor status  but as per code "while loop" will be exist when "CyclesNo" variable will "65535" so i expect that when Cycle Counter in processor status reached  to "65535" should also "CyclesNo" variable  reached to "65535"

 

but what happen when "CyclesNo" = 65535  the Cycle Counter is "458789" in processor status

 

 

Please advise 

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

The 'Cycle Counter' shown in the 'Processor Status' window at the left of your screen is CPU cycles - it has nothing to do with your 'C' variable called 'CyclesNo'

 

Each turn of your high-level 'while' loop will take more than one CPU cycle!

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

As Andy says there isn't a one to one relationship between C statements and machine cycles. Your using a 16 bit counter which occupies two AVR registers so both the increment and the check in the while loop will take multiple instructions and multiple CPU cycles. This is a RISC CPU so something that looks simple in C could take loads of the simple opcodes.

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

You should single-step through your loop a few times to get an idea of the relationship between CPU cycles and your variable's changing values.

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

and look at the disassembly ... 

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

 really  thanks so much  i got a lot of information from your posts 

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

You're welcome.

 

So, when you said, "i newbie in avr programming" - I take it that means you're a newbie with programming in general?

 

The difference between the statements in a high-level language (such as 'C') and the low-level machine/CPU instructions is entirely general - not specific to AVR.

 

The higher the level of the source language - and 'C' is relatively "low-level" compared to many (most?) these days - the greater the disconnect from the underlying machine level.