# AVR Info

Status
Not open for further replies.

#### AtomSoft

##### Well-Known Member
hey guys im playing with some avr code and am really confused about the MIPS thing.

I found out that the TINY13 can do 9.6 MHZ easy. Now in a PDF from ATMEL they claim there 9.6 MHZ is 9.8 MIPS which i dont care.

Now if its 9.8MIPS if i divide it by 1000 (1 second) that makes it

9800 Instructions for 1 millisecond correct?
So 200 Milliseconds should be 9800 * 200 = 1,960,000 Instructions

So 200mS = 1,960,000 instructions right?

How come in AVR Studio im doing a loop for 200mS using the below code

Code:
Delay200mS:                ;delay 202mS at 9.6mhz
ldi  d2, 0x13
repeatd2:
dec  d2
ldi  d1, 0xFC
delay200ms_1:
dec  d1
cpi  d1,0x00
brne delay200ms_1
cpi  d2,0x00
brne repeatd2
ret
This should only delay about 4788 Instructions. This seems to give me about 202mS of delay time which is ok but why is the above math wrong?

in the Cycle Counter it says the delay took 19253 Cycles to complete.

Is the clock split in anyway? or what am i missing here?

#### Nigel Goodwin

##### Super Moderator
You're possibly assuming an AVR is like a PIC, where almost all instructions take one cycle, on most other processors instructions mostly take multiple cycles, and the number of cycles varies from one instruction to another.

The datasheet should tell you how long each instruction takes - I've no idea on an AVR.

You might also see if you can download a delay code program, that generates the code for you - like you can for PIC's.

#### AtomSoft

##### Well-Known Member
oh i even forgot about that lol thanks a ton Nigel!

#### AtomSoft

##### Well-Known Member
Nigel dont laugh lol i was thinking wrong also lol i wanted a 200us delay not ms and kept confusing them lol

New code:
(i had to alter it a bit it was ugly lol also i had to change the 5B to 5A and 06 to 07 to give me closer result.)
Code:
Delay200uS:                ;delay 199.27uS at 9.6mhz
ldi     d1, $07 L2: ldi d2,$5A
L3:
dec     d2
brne    L3
dec     d1
brne    L2
nop
nop
ret
I used this generator:
http://www.home.unix-ag.org/tjabo/avr/dlg_02/dlg02.php

They have the source here(i think):
http://www.home.unix-ag.org/tjabo/avr/dlg_02/src_coder.php

Last edited:
Status
Not open for further replies.