Position: Index > Unclassified >

Programming AVR fuse bits

2017-12-23 08:16  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

I guess many of you were confused when programming AVR fuse bits. I get many newbie questions like “I programmed Atmega8 but it doesn’t work”?. Then my standard answer is: “Did you touch configuration bits?”? and if yes, then I am almost 90% sure that he did it wrong. Most of them understands wrongly that programmed fuse bit in configuration should be left unchecked and opposite. Let’s take a look at widely used programming software – PonyProg.

First thing you do before programming chip is set configuration bits (Atmega8 in picture):


The first attention should be paid to clock sources. There are Four bits controlling Atmega8 clock sources: CKSEL0, CKSEL1, CKSEL2, CKSEL3.

As you may already know, Atmega8 can have 4 different clock sources:

  • External Crystal or Resonator;
  • External Low Frequency Crystal;
  • External RC Oscillator or Calibrated Internal RC Oscillator;
  • External Clock source.

    In the table you see adequate CKSEL0..3 settings


    As you may noticed, for most of them there are ranges of settings left. For exampleExternal Crystal or Resonator

    External Crystal or Resonator may be set from 1010 to 1111 (Note that ’0′? programmed while ’1′ means unprogrammed). These ranges are left for user to select microcontroller startup times to stabilize oscillator performance before first instruction.

    If you connect external Crystal oscillator or resonator to XTAL1 and XTAL2


    There comes another Fuse bit CKOPT. This bit selects two different modes of oscillator amplifier. If CKOPT is programmed (unchecked), then Oscillator oscillates a full rail-to-rail output. This is handy when environment is noisy or you use XTAL2 to drive another microcontroller or buffer. But in other hand this takes more power. If CKOPT is unprogrammed (checked), than the swing is smaller and power consumption is less as well. Typically if resonator is up to 8MHz then leave CKOPT (checked=unprogrammed) and programmed (unchecked) above 8MHz.

    In table you see selectable crystal oscillator modes:image007.jpg

    CKSEL0, SUT0 and SUT1 bits in this case are used to select startup times of microcontroller – how many clock cycles to wait before execution first command. These settings are necessary to ensure stability of ceramic resonators and crystals.


    Note 1 .? These are fast startup times – not suitable for crystals;

    Note 2.? Most used with ceramic resonators to ensure stable startup. This is OK to use with crystals as well, but device is not operating at maximum frequency.

    So if you want stable system startup, it is better to leave CKSEL0, SUT0 and SUT1 programmed (unchecked) what means about 65ms startup time.

    Low frequency oscillator

    There is only one bit set for CKSEL0, CKSEL1, CKSEL2, CKSEL3 – 1001 (unchecked, checked, checked, unchecked) For Low frequency oscillator. Low frequency crystal is typical clock crystal where frequency is 32768kHz. The main options for this mode are setting crystal startup times with SUT0 and SUT1 fuse bits.


    Note 1. Less stable startup.

    External RC oscillator

    The frequency in this mode is calculated by formula f=1/(3RC) while C should be at least 22pF. If CKOPT is programmed (unchecked), then Internal capacitor 36pF between XTAL1 and GND is enabled, then there is only resistor needed.


    And again the table of operating modes:

    image017.jpgAnd startup times:image019.jpg

    Note 1. don’t use this setting when close to the maximum frequencies.

    Calibrated internal RC oscillator

    Calibrated internal RC oscillator is pretty often used, because there is no need any external components and it can provide fixed 1, 2, 4 and 8 MHz clock. This mode is selected by programming fuse bits in range 0001 to 0100.Leave CKOPT bit unprogrammed for this mode (checked).

    Operating modes:


    Note 1. by default this option is selected for all Atmega8

    And start up option table:image023.jpg

    Note 1.? by default this option is selected for all Atmega8

    About internal RC oscillator calibration read in device datasheet.

    External Clock


    External clock – this is the main mistake the newbie’s are making when starting their projects. To enable external clock source you have to leave CKSEL0, CKSEL1, CKSEL2, CKSEL3 bits unprogrammed – this meanschecked. People make mistake checking them and thinking that they are enabling external crystal resonator and then they are wondering why it is not working.

    And again there is a external clock source startup table controlled by SUT0 and SUT1:


    If you uncheck CKOPT then you will enable the capacitor between XTAL1 and GND.

    Examples on how to program Atmega8 clock sources correctly

    8MHz Crystal with slowly rising power:image029.jpg2MHz ceramic resonator fast raising power:


    32768kHz resonator stable frequency at startup:image033.jpgExternal RC 4MHz oscillator with internal C enabled fast rising power:image035.jpgIf you want to drive maximum from your Atmega: then select 16MHz fast rising power:image037.jpg

    You may find all this information in datasheets. But like always – people forget to read them.

    If there is any questions or concerns don’t hesitate to ask.

    Reprinted Url Of This Article: