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.