Saturday, October 1, 2011

Tutorial 4 : Connecting External Crystal Oscillator to Atmega (Atmel AVR) series. [Lower FUSE BITs settings for Atmel AVR]

Name : Connecting the crystal oscillator to Atmega (Atmel AVR) series.

Application :
  • This tutorial will illustrate how to connect external crystal oscillator to Atmega16/32, physically and logically.
  • It also explains the concept of fuse bits and how to configure Lower Fuse Bits setting.
Requirements and components :
  • All components required to make the development board (click here)
  • Parallel port programmer (click here)
  • Software : PonyProg2000 (click here)
  • Atmega16 data-sheet.
    (Data-sheet of Mega AVR : Need to refer for Fuse Bits)
Connecting crystal with Atmel AVR is two phase process.
In phase one, we connect the crystal oscillator physically
In phase two, we connect it logically to micro-controller.
(This is done by changing Lower Fuse Bits)

Connecting crystal to megaAVR (Physical connection) :
Following diagram shows how to connect the crystal oscillator to Atmega (Atmel AVR) series.
Note : All connections are shown in this tutorial (click here)

Kindly refer data-sheet of AVR your using, page number 2 will give you all idea about pin configuration.
All MegaAVR data-sheets (click here)

Selecting the values of C1 & C2 :  
Values of capacitors C1 and C2 will change, based on the crystal value
Following table shows the recommended for capacitors C1and C2.

(Available under System Clock and Clock Options header in all MegaAVR data-sheets)
e.g 1.> Crystal oscillator frequency = 11.0592 MHz=>22pF
e.g 2.> Crystal oscillator frequency = 16.0000 MHz=>22pF

Fuse bits :

Fuse bits define the mode of operation for MegaAVR.
Changing the fuse bits changes the internal configuration of micro-controller .
To able to connect the crystal logically, we must change the lower fuse bits.

Note :
Changing fuse bits is like doing open hart surgery on micro-controller.
Any wrong configuration of fuse bits will result in the dead MegaAVR.

Lower Fuse byte :
Lower fuse byte deals with Brown-out Detector, start-up time & Clock source.
In short lower fuse byte is for clock source configuration.
Here is the bit configuration of Lower fuse byte.

Following table shows the description of above bits.
Now default Lower fuse is 

Reading Fuse bits with PonyProg : 
  • Start PonyProg2000
  • Connect the parallel port programmer to parallel port at PC and development board.(Turn on the power of development board)
  • Complete the interface setup, calibration and device selection.
    (For tutorial click here)
  • In menu bar click on Command and then click on Security and configuration bits(Command > security and configuration bits)

  • This reads fuse bits from micro-controller, and displays it in new window.
  • Now above window shows the default fuse bit status.
    Fuse bits marked in red are Lower fuse bits.
  • For PonyProg Check = 0 and Un-check = 1
  • To read the fuse bits again click on read button
Calculating the Lower Fuse bits for 16MHz :
Following table shows the CKSEL3..0 (read as CKSEL 3 down to 0) for device clocking options .

Following table shows the value specific settings for fuse bits 

Note :  CKSEL0 bit is configured for start up time we'll keep it as it is 
(Do not change the CKSEL0 bit)

Hence as above two table shows bit configuration for 16MHz will be
  • CKSEL3 => 1 => Un-check in Ponyprog
  • CKSEL2 => 1 => Un-check in Ponyprog
  • CKSEL1 => 1 => Un-check in Ponyprog
  • CKSEL0 => 1 => Un-check in Ponyprog (By default it is Un-check)  
  • CKOPT  => 0 => Checked in Ponyprog
There for new Lower fuse bit configuration for 16MHz crystal is

Writing Fuse bits with PonyProg :
  • To un-check a bit click on the check box in front of particular bit.
  • To implement change in Ponyprog un-check the CKSEL3..1 (read as CKSEL 3 down to 1) and check the CKOPT as shown in fig below.

  • To write fuse bits click on Write button.
  • This will perform write operation.
This is how to configure and change the fuse bits using PonyProg.

Note :
It my previous experience that any wrong configuration of fuse bits may result in to dead MegaAVR.

Before writing the fuse bits verify the configuration at least twice.

Disclaimer :
All the data or information written above is from data-sheets and other reference documents.
My intention is to share my knowledge and experience with others.
Information or data above is not my innovation at all, its just a collection that works perfectly.


  1. good one... Can't we recover the damaged Mega8 IC which got damaged due to setting wrong fuse bits?

    1. Hi Suket,
      Yes, now there you are …
      We can recover the “Dead ATmegas”. The method of doing so is known as “HVPP”, acronym for “High Voltage Parallel Programming”. Some people call it as “ATmega Fusebit Doctor”.
      If you are having some dead ATmegas you can try it & share your experience on “HVPP” with us.
      Being so busy these days I’ve not tried it myself, but I’ll shortly try it & share the same on blog.

      -- Regarded

    2. Yes, Me and my friend started working on the same HVPP. But before doing that I'll try giving 1MHz clock pulse... May it works..I'll tell about my updates. Thanks.

    3. Hi, yes, i did recover my bad fused atmega128 (bad fuse cause comm error at connect as stk200) changing the default onboard crystal (16Mhz on header board from olimex) to 24 Mhz (or up), depending of you "bad fuse settings". (srry my bad english).

  2. I think you need to check CK0PT

  3. Hi Buddy, thanks for suggesting correction …
    Now it is corrected…


  4. I just came to conclusion after troubleshooting this. These are my outputs.
    This is my programmer's circuit: ... 4,s:0,i:94

    1) For the chips where you get logic 1 at RESET pin.........(Didn't connected Pull-up resistor)

    Steps I followed:
    Give 1MHz to XTAL1 and 'connect common ground'.I used NE555 for it. ... id=3541030

    Then don't remove it. (I just gave it for 1 min and removed , so I couldn't able to recover)

    You may could erase the chip before or not.

    Now, Erase the chip.I used ponyprog. (Retry 2-3 times if it doesn't allow).It works 'Erase Successful'.

    Read 'Security & Configuration bits' (Retry 2-3 times if it doesn't allow).

    Change it to appropriate , I configured as it was in initial condition(1MHz internal osc).

    Hurray... You've done.
    I recovered 2 Atmega8 & one Atmega16.

    Thanks Alex & Cliff(
    & also ctownsend ( 4th post in )

    2)For the chips where you CAN'T get logic 1 at RESET pin.........

    I think one should use fuse bit doctor. I didn't try it yet.

    Thank You,

  5. ... 4,s:0,i:94 ................................ it is:,r:4,s:0,i:94

  6. hey friend am interface rf id with atmega 16A and m used 11.0592 mhz crystal but i faced problem of fuse bits plzzzz help mi i new in avr i lost my 5 atmega 16 chip so plzz once give mi accurate fuse setting for atmega 16 with external crystal and m using pony prog 2000 andstk200

    1. Hi Paresh,

      11.0592 MHz, it sounds like you are trying serial communication ...

      Request you to follow the steps in tutorial and you are done with external XTAL.
      You can follow the step below for trouble shooting ..
      1. Read the fuse bits of new Atmega IC
      2. Connect 11.0592 HMz XTAL as show above.
      3. Change the fuse bits as shows.
      4. Try to read the fuse bits again ..

  7. hey what at highr fuse byt??
    dosnt it need to be set??

    1. Hi Rushi,
      Yes, we need to change the only one bit from “Higher Fuse Byte” i.e. CKOPT, but rest of the bits are set to defaults. Functions of “Higher Fuse Byte” are to enable the following features:
      1. On-chip Debug support.
      2. JTAG.
      3. SPI programming.
      4. Oscillator options. **
      5. EEPROM chip erase.
      6. Select boot size.
      7. Select reset vector.
      ** Oscillator options i.e. CKPOT must be programmed i.e. reset (= 0) to connect external XTAL at 16 MHz, same is mentioned under label “Calculating the Lower Fuse bits for 16MHz”.
      Please note that “Lower Fuse Byte” plays major role in external XTAL connectivity and start-up time.

  8. Thanks for sharing information about connecting external crystal oscillator to Atmega.
    Statek Crystals

  9. hello, if i connect 12 MHZ external crystal to atmega16L
    will it read the whole 12 mhz or just its limit the 8mhz ?

    1. Hi Mohamed,
      Yes ! Provided your fuse bit settings are correct as given in tutorial above.

  10. Hi Mohamed,
    Yes ! Provided your fuse bit settings is correct as given in tutorial above.

    1. thank you Kaustubh,
      what i mean that in the atmega16(L) datasheet
      for "atmega 16L" it only works with a maximum of 8 MHZ external crystal ,but i have just bought a kit where a 12 MHZ crystal connected to the atmega16L
      So i do not know if it will work properly or should i replace it with a 8 MHZ crystal
      thank again :)

    2. Hi Mohamed,
      I got your point now, I'm checking it just give me some time.

    3. Hi Mohamed,
      I was checking for above details for last 2-3 days.
      Here are my the findings.

      As per datasheet ordering options :
      1. Atmega16 L will work in 0 - 8 MHz.
      2. Atmega16 will work with 0 - 16 MHz.

      I've checked with my PCB prototype using Atmega16L/8PU/0938K, it's working with 16 MHz XTAL.

      It would be better if you check with existing 12MHz XTAL connected to your board.

    4. Hi Kaustubh ,
      thanks a lot .
      as you told me i have checked my Atmega16L/8PU/1209G on a PCB with 12MHZ XTAL connected . I used a small program to toggle a led every 1 second but actually it takes like 1.5 second to toggle !!
      I think i should stick to the datasheet and buy a 8MHZ and connect it to PCB to get a precise timing
      thanks again and if you have thoughts or solutions that will be appreciated .

    5. Hi Mohamed,
      By default all the ATmega ICs will are configure to work with Internal Calibrated RC Oscillator at 1MHz, you have to change the fuse bit settings to make it work it with external oscillator.
      Please do the following steps and provide your input to me.
      1. Burn/program hex file to blink LED(s) in Atmega IC.
      2. Turn off the kit/circuit and disconnect programmer.
      3. Remove XTAL from kit/circuit.
      4. Turn on the kit/circuit.
      Does your LED(s) blink?
      If yes, means IC is configured with Internal Calibrated RC Oscillator.
      If no, then I’ll do some more search on this topic.

    6. First am sorry for being so late to reply,
      second i did as you said and yes LED was blinking but the internal wasn't 1 MHZ it was 4
      so i write the values as following
      SUT1 = SUT0= CKSEL3-0 = 1
      i set all the bytes low and high to 1 EXCEPT " SPIEN " it was "0" to enable the programming through the SPI - usb programmer .
      i checked the timing for a blinking led every 1 sec delay using the 12 MHZ crystal on atmega16L and it works fine :)
      i have to thanks you for your replies , thanks KAUSTUBH :)

  11. This comment has been removed by the author.

  12. hi,
    i bought a new atmega32 from market and implemented an led blink circuit.I didn't used an external crystal,and fuse bits remained unaltered.I'm using winavr compiler and usbasp programmer.
    the circuit worked fine, and i got one second delay as per program. (note In the make file F_CPU was set to 1mhz)
    For the second time i thought of adding an external crystal of 16 mhz to it and burned the fuse bytes as mentioned below
    HF:0xc9, LF:0xFF
    now I changed F_CPU value to 16mhz in the make file,and hooked up a 16mhz crystal with two 22pf capacitors.
    when i ran the same program now, i'm getting blink rate much faster than it what it should be,and even adjusting the delay and F_CPU value has no effect on blink rate,i think i'm confused ,
    what could be the problem
    thank u

    1. Hi buddy,
      Sorry for my delayed reply.
      Actually, delay function in util/delay.h are functions for F_CPU.
      If you define F_CPU in your program then it'll override the definition in .h files.
      It's always advised, define F_CPU = external XTAL.
      Kindly note that, when the user request delay which exceed the maximum possible one, _delay_ms() provides a decreased resolution functionality. In this mode _delay_ms() will work with a resolution of 1/10 ms, providing delays up to 6.5535 seconds (independent from CPU frequency). The user will not be informed about decreased resolution.

  13. thanks. very useful information for me.

  14. i use atmega16a
    crystal 11.0592 mhz
    dtmf landrover

    fuse bits please

    i locked two atmega16a

    so please sir

  15. This comment has been removed by the author.