# Electronic Circuits and Projects Forum

1. ## AVR Info

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?

2. 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.

3. oh i even forgot about that lol thanks a ton Nigel!

4. 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/av.../src_coder.php

 Tags
 Similar Threads Thread Starter Forum Replies Last Post IR Info... surjo_dm General Electronics Chat 12 11th July 2011, 05:56 PM Info about KEC 168 ??? arustu General Electronics Chat 2 3rd August 2006, 06:55 PM Need info shermaine General Electronics Chat 3 13th May 2004, 04:31 AM PLC info? cool-agent General Electronics Chat 1 12th December 2003, 03:39 PM Where can I get more info on.. kevinloh General Electronics Chat 0 31st October 2003, 12:02 PM
Electronic Circuits  |  Learning Electronics

Join our community with over 100,000 Members! It's free, easy and when you're logged in you have many more features! Click to register.
Page Time: 0.06536 seconds      Memory: 7,316 KB      Queries: 17      Templates: 0