Attiny2313 clock runs too slow

Hey, I've managed to upload the blink example to attiny2313 @ 8Mhz. However, the timers work 16 times slower ( it takes 16 sec to execute delay(1000)) I pretty sure that's because it runs at 1Mhz and not at 16Mhz( as the ArduinIDE calibrated to).

I have looked at the datasheet and I found that I have to set CKSEL to 0100 to use the internal 8Mhz. but I couldn't find how to change it.

there is my board.txt

attiny2313at8.name=ATtiny2313 @ 8 MHz



# The following do NOT work...

# attiny2313at8.upload.using=avrispv2

# attiny2313at8.upload.using=Pololu USB AVR Programmer



# The following DO work (pick one)...

# attiny2313at8.upload.protocol=avrispv2

attiny2313at8.upload.using=arduino:arduinoisp

# attiny2313at8.upload.using=pololu



attiny2313at8.upload.maximum_size=2048



# Default clock (slowly rising power; long delay to clock; 8 MHz internal)

# Int. RC Osc. 8 MHz; Start-up time: 14 CK + 65 ms; [CKSEL=0100 SUT=10]; default value 

# Brown-out detection disabled; [BODLEVEL=111]

# Serial program downloading (SPI) enabled; [SPIEN=0]

# Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]



attiny2313at8.bootloader.low_fuses=0xE4

attiny2313at8.bootloader.high_fuses=0x9F

attiny2313at8.bootloader.extended_fuses=0xFF

attiny2313at8.bootloader.path=empty

attiny2313at8.bootloader.file=empty2313at8.hex



attiny2313at8.bootloader.unlock_bits=0x3F

attiny2313at8.bootloader.lock_bits=0x3F



attiny2313at8.build.mcu=attiny2313

attiny2313at8.build.f_cpu=8000000L

attiny2313at8.build.core=tiny

Well, did you actually change the fuse settings of the chip by means of avrdude, or read them back to verify they are what 'boards.txt' says?

F_CPU seems to be defined as 8000000L in your post, so the code should know about the actual clock frequency.

You probably have CLKDIV enabled, that divides the clock by 8. Its on by default in a new chip.

madworm: Well, did you actually change the fuse settings of the chip by means of avrdude, or read them back to verify they are what 'boards.txt' says?

F_CPU seems to be defined as 8000000L in your post, so the code should know about the actual clock frequency.

No, I don't how to change or verfie the fuse setting(basically, that is the reason why I post it)

Senso: You probably have CLKDIV enabled, that divides the clock by 8. Its on by default in a new chip.

Maybe, is there anyway to disable it?

BTW I'm using arduino IDE

Are you using this core? http://code.google.com/p/arduino-tiny/

[quote author=Coding Badly link=topic=67607.msg497441#msg497441 date=1311706192]

Are you using this core? http://code.google.com/p/arduino-tiny/

[/quote]

yes

With everything wired and ready to upload a sketch...

• Select the board "ATtiny2313 @ 8 MHz"

• Click Tools / Burn Bootloader / Arduino as ISP

The processor is erased and the fuses are changed to those in boards.txt. The processor should now be running at 8 MHz using the internal oscillator.

Wich bootboader?

Coding Badly, thanks that worked

BrainBooster:
Wich bootboader?

There are no bootloaders. The ATtiny2313 just does not have enough room (Flash). The ATtiny84 and ATtiny85 do not have enough hardware support.

I was changing the fuse settings frequently. I wanted a convenient way to change the fuse settings. It seemed likely that other people would want the same thing. I decided to make that available through the Arduino IDE. The only place such an action fits (without modifying the IDE) is “Burn Bootloader”. So, with the Tiny Core, “Burn Bootloader” erases the processor and sets the fuses but a bootloader is not uploaded (nor is one available).

kirill578: Coding Badly, thanks that worked

Excellent. I'm glad it worked. Good luck with your project.

@CodingBadly: One of the most informative threads I've read all week. Thanks for your contributions!

You are welcome. Are you using any of the ATtiny processors?

Yes, usually the 85 or 2313 depending on how many I/O pins I need. I just discovered your project, added it to my list of things to check out.

My ATTiny projects are usually so simple that I just code them up in AVR Assembler or C. Arduino is overkill for a throwaway blinky :P