AVR Microcontroller Default Clock

One feature of AVR devices that can baffle new users is the default clock setting on new AVR microcontrollers. They are set to run from their internal RC oscillator, usually 1 MHz, which throws out the timing on code samples, such as UART.

If the code is configured for an 8MHz clock and there is a 8MHz clock on the target board, you expect it to work but instead you get nothing or garbled characters. This is due to the default Internal RC. How do you change it?

All AVR programmers have a Fuse screen somewhere, that lists the configuration fuses for the AVR. These set how the device runs, including things like brown-out, reset vector, debug enables and clock.

The settings we are interested in are CLKSEL and CLKDIV8. The 4 CLKSEL bits (Clock Select) define the type of clock. If you read the fuses on a new AVR, they appear as an Internal RC Oscillator. The default speed depends on the particular AVR. Change this to an External Crystal/Ceramic Oscillitor for most circuits. If the CLKSEL fuses are displayed in binary, this is 1110 or 1111 for most target circuits. Do NOT choose External Clock (0000) unless you have a specialised clock circuit (not just crystal) on your board or you will lock yourself out of the AVR microcontroller.

Most devices default to 1MHz Internal RC but some, like ATtiny2313, default to 8MHz, but don’t be fooled as they also have a CLKDIV8 fuse that divides the clock by 8. This also needs to be unchecked if it is present on the device.

Program the new fuse settings and your AVR will now run at the speed you expect.

6 thoughts on “AVR Microcontroller Default Clock”

  1. Hi,
    I download the avrisp from this page. The programmer works ok , but the programmed chip run very slowly. I apply 16Mhz external crystal with target chip , but chip run very slow.
    How to setting in programmer software the 16Mhz crystal (the chip is mega328p-pu)

    Thank You
    Ernoe

    1. Look on Fuse and Lock bits tab. Change CLKSEL (Clock Selection) fuses from default 1MHz Internal RC to High Speed crystal (value CLKSEL= 1111). Then go to Device menu -> Program ->Program Fuses.

      Your AVR microcontroller will now use the 16MHz system clock.

  2. Hello,

    I am using ATtiny44a and I want to set 128 kHz low power internal oscillator. I went through the device programming window and set the fuse bits SUT_CKSEL to WDOSC_128KHZ_6CK_14CK_64MS. In other words, I have set the system clock to be at 128kHz, 6 cycles start up time from power-down and 14 cycles + 64 ms additional delay from reset. I have unprogrammed the CKDIV8 as well as id doesn’t make any sense. I set the ISP clock frequency to 32 kHz which is 1/4 of the system frequency but it fails to enter to programming mode. I then use little lower at 25 kHz and is able to read the device signature but still is unable to be programmed returning a message that reads 0xcc instead of 0x00.

    Any help will be appreciated
    Thank you

    1. CKDIV8 does exactly what is says. If you select, for example, a 1MHz Internal clock, then if CKDIV8 is set you will get 1MHz / 8 = 128KHz.
      So you could select a 128KHz clock ythat way.

      Most programmers struggle at this frequency but you don’t say which one you are using. I would guess AVRISP-MKII but not sure. Set the ISP clock as low as it will go and try again. It is often better to try reprogramming fuse back to a faster speed before trying other programming operations.

    2. CKDIV8 does exactly what is says. If you select, for example, a 1MHz Internal clock, then if CKDIV8 is set you will get 1MHz / 8 = 128KHz.
      So you could select a 128KHz clock that way.

      Most programmers struggle at this frequency but you don’t say which one you are using. I would guess AVRISP-MKII but not sure. Set the ISP clock as low as it will go and try again. It is often better to try reprogramming fuse back to a faster speed before trying other programming operations.

Leave a Reply

Your email address will not be published. Required fields are marked *