AVR Clock Source & Fuse Bits – Tutorial #5

You know the basics about how the chip is clocked. Every microcontroller chip uses a clock, which keeps track of time for the chip, in general one assembly code instruction is run every clock cycle.

The Clock Source can be either of the following:

  • Internal Clock
  • External Clock

Internal Clock‘ means the little oscillator inside the chip. This clock is good for most basic projects, but its not very precise. Having an internal oscillator means we don’t need to wire up an external crystal and hence we can use the clock pins for other tasks. Literally, ‘ External Clock‘ means that a square wave is being input into the ‘CLOCK-IN’ pin, but this option is rarely used. If we need a special clock rate (for example 12MHz) we can use an external crystal or oscillator.

Crystals come in different pacakges, with the speed printed on the body, usually in MHz. Ceramic resonator is an alternative to the common crystal. Crystal is a 2-pin component, but ceramic resonator have 3 pins.

ceramic resonators

In practice, it is required to add two ceramic capacitors (usually 22pF value) with the crystal as shown in the next figure. However, this is not required incase of a ceramic resonator because it is a combination of the crystal and capacitors, built into one compact package. Note that the internal ATMega8 clock can be set up to a maximum frequency of 8 MHz, and beyond that you need an external clock source. How can we set a clock speed? As said, we have two options; use the internal one, or use an external source. If we are writing code for a basic job, the internal clock should suffice. On the other hand, when precision timing is crucial, we need an alternate method like using suitable crystals, or ceramic resonators.

AVR 5-F2


Fuses are important when it comes to uC programming, that is why fuses are well-documented in manufactures’ datasheets. The fuses determine how the chip will act, whether it has a bootloader, what speed and voltage it likes to run at, etc.
You only need to set them once, but if you don’t do this right, get ready to expect a costly disaster!

Typically, there are only two fuse bytes: a high one, and a low one. As you may well know, one byte contains 8 bits. So we have just 16 bits to set to on or off. Each of those bits, depending on whether they are on or off, impacts the critical operations of the microcontroller. For all fuses, ‘1’ means unprogrammed, and ‘0’ means programmed. As found in the datasheet, ATMega8 has the following clock source options, selectable by Flash Fuse Bits as shown in the table below.
The clock from the selected source is input to the AVR clock generator, and routed to the appropriate

device clocking

In this part, we just learned that we have to set some fuse bits to indicate we are using an external crystal. Frankly speaking, learning more about fuse bits at this early stage is somewhat difficult for many beginners. So just consider this as a foundation (will treat this in near-future), and allow me to shift to next phase of this tutorial.

Fuse Bits – Short Reference

  • Four bits controlling Atmega8 clock sources: CKSEL0, CKSEL1, CKSEL2, CKSEL3.
    • Different clock sources of Atmega8:
    • External Crystal or Resonator
    • External Low Frequency Crystal
    • External RC Oscillator
    • Calibrated Internal RC Oscillator
    • External Clock
  • External Crystal (or Ceramic Resonator) may be set from 1010 to 1111. These ranges are left for user to select microcontroller startup times to stabilize oscillator performance before first instruction.
  • If we connect external Crystal oscillator or cdramic resonator, there comes another Fuse bit CKOPT. This bit selects two different modes of oscillator amplifier. If CKOPT is programmed then Oscillator oscillates a full rail-to-rail output.If CKOPT is unprogrammed,the swing is smaller.
  • The Oscillator can operate in three different modes, each optimized for a specific frequency range. The operating mode is selected by the fuses CKSEL3..1
  • CKSEL0, SUT0 and SUT1 bits in this case are used to select startup times of microcontroller. These settings are necessary to ensure stability of ceramic resonators and crystals.

startup times

(1) These are fast startup times – not suitable for crystals
(2) Intended to use with ceramic resonators to ensure stable startup

→ Part 6: Atmega8 – Basic Input/Output Interfacing
← Part 4: Flash Burning Process & Program Explanation


Join the conversation!

Error! Please fill all fields.
Looking for the latest from TI?