# timing question on ATTiny13 / ATTiny2313

**URL:** <https://community.sparkfun.com/t/timing-question-on-attiny13-attiny2313/10164>\
**Category:** MicroMod\
**Tags:** avr-atmel\
**Created:** [February 22, 2009, 6:19am UTC](https://community.sparkfun.com/t/timing-question-on-attiny13-attiny2313/10164 "2009-02-22T06:19:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thartley](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@thartley](https://community.sparkfun.com/u/thartley)\
**Post date:** [February 22, 2009, 6:19am UTC](https://community.sparkfun.com/t/timing-question-on-attiny13-attiny2313/10164/1 "2009-02-22T06:19:17Z")

</div>

Newbie here. I have been playing with the ATTiny13 and ATTiny2313 and have some questions and comments on using the \_delay\_ms function.

I am using the code from the Ghetto Programming posting on the Instructables web site. The “Hello World” program contains this line:

#define F\_CPU 100000UL // Sets up the default speed for delay.h

I’ve looked around a bit but I haven’t found a good explanation of why this is one-hundred-thousand and not one-million. I’m using the internal oscillator.

Using the code from the Instructables site, I tried to change the ‘led off’ portion to three seconds by changing the \_delay\_ms() value to 3000, but the led turned back on faster than it should have. This behavior made me wonder if the value was too high based on something I had read that the \_delay\_ms code would act funny if the value used was too high

“The maximal possible delay is 262.14 ms / F\_CPU in MHz.”

If I change the F\_CPU value to one million, then I can use \_delay\_MS(3000) and it seems to stay off for 3 seconds. This is just a casual observation - no test equipment was used to confirm the actual length of time.

In fact, if I use the original \_delay\_ms() values with the F\_CPU value of one million, both ‘led on’ and ‘led off’ occur for much longer times.

Is the F\_CPU value supposed to represent the speed of the AVR chip or is it the oscillator frequency?

I’m editing the code and programming the chips with Programmer’s Notepad and I don’t get any errors.

Thank you.

---

<div class="post-metadata">

**Author:** ![signal7](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@signal7](https://community.sparkfun.com/u/signal7)\
**Post date:** [February 23, 2009, 12:06pm UTC](https://community.sparkfun.com/t/timing-question-on-attiny13-attiny2313/10164/2 "2009-02-23T12:06:46Z")

</div>

As you have discovered, F\_CPU doesn’t change the actual oscillator speed. The chip, by default, uses the 8MHz internal oscillator with the prescaler set to divide that by 8.

F\_CPU only tells the libraries and various functions in your code how to calculate the proper delay time based on the physical clock frequency. The physical clock frequency can be changed by reprogramming the fuses. Be aware though - setting the fuses incorrectly can leave your chip in a non-running state.

---

<div class="post-metadata">

**Author:** ![thartley](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@thartley](https://community.sparkfun.com/u/thartley)\
**Post date:** [February 24, 2009, 5:25am UTC](https://community.sparkfun.com/t/timing-question-on-attiny13-attiny2313/10164/3 "2009-02-24T05:25:50Z")

</div>

Thank you for the reply.

I checked the data sheets for both the ATTiny2313 and the ATTiny13. The 2313’s internal oscillator defaults to 8 MHz and the ATTiny13’s internal oscillator defaults to 9.6 MHz. Both chips default to the prescaler set to divide by 8. So I guess if I want to keep things simple and just use the internal oscillator and leave the fuses alone, So for the ATTiny13, I should change F\_CPU value to 1,200,000 to get the \_delay\_ms() as close as I can.
