Programming AVR fuse bits – oscillator settings
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 example External 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.

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 stabile startup. This is OK to use with crystals as well, but device is not operating at maximum frequency.
So if you want stabile 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 stabile 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:


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

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 means checked. 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:

-
2MHz ceramic resonator fast raising power:

- 32768kHz resonator stable frequency at startup:
- External RC 4MHz oscillator with internal C enabled fast rising power:

- If you want to drive maximum from your Atmega: then select 16MHz fast rising power:
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.
Blogsphere: TechnoratiFeedsterBloglines
Bookmark: Del.icio.usSpurlFurlSimpyBlinkDigg
RSS feed for comments on this post | TrackBack URI for this post
New on WinAVR Tutorial
Running TX433 and RX433 RF modules with AVR microcontrollers,Sometimes in embedded design you may want to go wireless. Might be you will want to log various readi …Programming AVR ADC module with WinAVR,Most of AVR microcontrollers have Analog to Digital Converter (ADC) integrated in to chip. Such solut … |
New on WinARM Tutorial
What are differences between WinARM and WinAVR,Everyone who is working with AVR microcontrollers knows this powerful tool – WinAVR (http://win …LPC2000 watchdog timer,As in all microcontrollers watchdog timers purpose isto reset microcontroller after reasonable amount … |

November 25th, 2006 at 1:16 pm
Please explain to me about setting ATMega16 internal oscillator fuse bit. I found a problem with my Mega16, i try to the ADC in Mega16 using 12 MHz Crystal(i do nothing on fuse bit) and that works (no problem), that means my M16 works (not dead). But when i test the m16 serial usart connect to my comm port pc (i observe the data from M16 usart with hyper terminal), that is not works, i try using cystal 12 Mhz, 4 MHz, 8 Mhz and also change the baud rate from 19200, 9600, 2400, and that is still remain NOT WROKS, why ..??
please help me..
November 27th, 2006 at 12:53 pm
If you didn’t touch fuse bits your ATmega16 works with internal 1MHz frequency. ADC works with this too, just sampling freq is lower.
What about USART if you just exchange crystals, but fuses indicates that AVR works with internal freq generator, then it shouldn’t work.
If you want Atmega work with external crystal, in PonyProg uncheck all CKSEL3..0 bits.
December 6th, 2006 at 1:45 pm
i unintentionally programmed the fuses on an ATtiny2313 to work on External clock, and off course not working, and i am confused, i can find any article on how to recover the first setting, or change it to anything else, plz help
December 6th, 2006 at 2:45 pm
I suggest reading life-giving-to-atmega8 article, where I was trying to do the same with Atmega8’s. Just fact is that they were really burned ;)
December 29th, 2006 at 7:14 am
I have read about fuse bits in the datasheet for the ATMega8, and have read this article as well, but I use avrdude (on Linux) and I am still confused.
It seems that there are hfuse and lfuse (something to do with high byte and low byte of fuses), but I can’t figure out where the different bits are placed in these bytes?
And how am I going to set the bits using a 12 MHz crystal? The sheet I have been reading only specifies up to 8MHz?
Kindest reagrds
December 29th, 2006 at 1:58 pm
I would suggest reading this forum post.
AVR Fuse Bits
Might this will clear things out.
December 29th, 2006 at 5:37 pm
Brilliant - thank you!
Kindest regards
January 28th, 2007 at 6:35 pm
Hello everyone!
I am trying to hook my Mega8515 to run from external 4Mhz crystal, with 2×27 pF capacitors.
Even if i set the fuses to run from internal 4Mhz, or external crystal, when I try to read program memory, PonyProg reads the first ~400-500 bytes O.K., but after that it gets garbage (I’m not talking about 0xFFs, i am talking about random data).
If I remove the capacitors and the crystal it works O.K…. what could be wrong? Is my crystal blown?
February 14th, 2007 at 7:49 am
I programmed one Atmega8 with AVR ISP programmer ( bulit without any buffer ) and it worked fine with right fuse bits configs.
later I had to program another one and I set fuse bits wrong and now second atmega8 is unreadable and nor write-erase operation can be prepared…
according to the article “life-giving-to-atmega8 ” do you mean I have to put it to trash ? or is there any way to reprogram fuse bits with some “stand-alone AVR (non ISP) programmer” ?
there is some avr programmer in markets that they are expensive and stand-alone which I guess they might be able to reprogram fuse bits and eeprom area.
I hope you guide me
February 14th, 2007 at 9:40 am
I guess you unprogrammed all CKSEL fuse bits, what means clocked by external clock source. One way to restore Atmega is to connect a clock generator to your Atmega and try to reprogram fuses with ISP. As generator can be used another AVR with simple program like this:
int main(void)
TCCR0B = (1<
OCR0A=0;
{
DDRB = 0b11111111;
DDRD= 0b1111111;
TCCR0A = (1<
while(1) {}
}
If this doesn’t work - I suggest not to waste time and get new one ;)
February 15th, 2007 at 9:30 am
thanks a lot but I asked about stand alone parallel avr programmers which seems to be able to reprogram fuse bits and more vs serial device programmers …
I can’t find any schematic for parallel programmers.
can you tell me is there any programmer to do that job? and how to make my own etc… ?
I know so many COM or LPT programmer and softwares like ponyprog which they are NOT able to work with fuse bits well but I still don’t know which are able to do it.
February 15th, 2007 at 12:37 pm
You may try AVR serial and parallel High-Voltage programmer. I didn’t try this one, so I cannot help much on that for now.
February 25th, 2007 at 7:50 pm
what about fuses for 11,0592MHz crystal oscillator (mega32)?
i can’t find them in datasheet :( up to 8MHz only)
February 27th, 2007 at 9:54 pm
Nik, You are asking about fuse settings for 11,0592MHz for Atmega32?
March 1st, 2007 at 12:42 am
After I programmed my first mega16’s bits to 0 (ALL of them) I blamed the home-made programmer for not being able to access the chip in PonyProg. So I bought another chip and again, not minding the documentation, I unchecked all the possible bits in the window. What should I attach to the XTAL1 and XTAL2 pins to get my chips back running?
Best regards
March 1st, 2007 at 9:26 pm
Hi scienceprog,
I don’t understand;
“1″ means unprogrammed(checked) and “0″ means programmed(unchecked)?
I think that “1″ means unprogrammed (unchecked, not checked!).
Regards.
March 2nd, 2007 at 6:28 am
Help needed… I made the biggest nOOb mistake ever, great! I fused the Atmega16 for running on external clock and not external crystal. My question, can I just add a clock signal to the XTAL1 without removing the crystal (all SMD components)? Maybe I can ground the XTAL2 and then add the clock to XTAL1? My circuit looks like this: http://www.idt.mdh.se/rc/sumo/pcb/Schema.pdf
Which frequency should I add to the XTAL1?
March 2nd, 2007 at 11:27 am
This explanation is according to ponyprog. Check-box checked means programmed(bit=0). Unchecked box means unprogrammed(bit=1). AVR fuses are programmed when bits have values = 0. Look at first picture of article where fuse setting window is. I understand this causes some confusion - sometimes for me two :)
March 2nd, 2007 at 11:35 am
To Real nOOb,
So you checked in ponyprog all CKSEL fuse bits set to 0? I think this should be enough to apply like 1MHz to XTAL1 lead. Frequency can be generated by another AVR or another function generator. I think lower and of course higher frequencies should work well. First thing you will have to do uncheck these CKSEL check-boxes.
March 2nd, 2007 at 2:44 pm
Ok, that did it! I just added a 1Mhz square wave to the XTAL1 and then unchecked the CKSEL boxes, thx for the help.
March 27th, 2007 at 5:55 pm
Hi scienceprog,
My name is Gerardo and I’m using de PonyProg2000 v2.06f BETA version to program ATmega16 Atmel family microcontrollers. I have a problem when I try to change
the Security and Configuration Bits default value. When I change a bit value of this register (to change the frequency oscillation for example) the programmer doesn’t work any more. It’s always giving me de following error message “Device missing or unknown device -24″ after
the action, and the programmer doesn’t recognised the microcontroller any more. I tried to solve the problem following the FAQ in the help topics but it doesn’t work.
What can I do to solve this ugly problem?
Thanks for your reply
March 28th, 2007 at 11:06 am
How did you change oscillation settings? Maybe you selected external clock source - common problem.
May 7th, 2007 at 3:23 am
For people who bricked there Atmega, here a little tuto: “How to recover the fuses bits”
http://www.larsen-b.com/Article/260.html
October 20th, 2007 at 2:55 am
From the above article you state that a fuse bit is programmed when unchecked. Looking at the picture from PonyProg that is wrong. It sure confuses me.
Cut from the article:
… If CKOPT is programmed (unchecked), then Oscillator oscillates a full rail-to-rail output. …
December 17th, 2007 at 2:44 pm
i tried to use atmega16, external clock 11.059MHz
all fuse bits are unchecked
ponyprog can read/ write my device
..but, when i try to do something like PORTC=0xFF
i only measure something like 0.5V
can’t figure out what i did wrong
March 8th, 2008 at 4:01 am
Hi, after set fuse bits, my atmega16 still working but i cant write nor read its fuse/code. Was an mistake of my or another thing? tnx.
March 11th, 2008 at 9:02 pm
Hi,
I want to drive an external sensor using the clock from AVR 32 .But the output I am getting from the clock buffer is a sine wave :( I have programmed the fuse bits as 1111 and CKOPT=0 .My freq is 13.56 M.
Any help will be really appreciated.
Thanx!
March 11th, 2008 at 9:45 pm
Do you mean some dedicated MCU pin or XTAL1. Maybe you are wrong with measurements - how do you know it is a sine? Fuse settings seems to be ok.
March 12th, 2008 at 9:23 am
Hi
Thanx for replying. I am using 7404 IC (NOT gate) as a buffer. I have attached the XTAL2 to this IC , and the inverted ouput that I am getting is more of a sine wave to me.
I tried using 74C14 CMOS hex inverter but it gives a triangular wave as output :(
I have tried this with both XTAL1 and XTAL2.
Thanx!
Aditi
March 12th, 2008 at 10:02 am
If you measure wave shape with oscilloscope try to change probe attenuation to like x10. I bet signal shape is OK, only you cant see it right because of probe bandwidth limitations.
March 14th, 2008 at 8:16 pm
Hi ,
I am interfacing a CMOS image sensor with a ATmega 32 .I have pulled the lines high. I have also checked the CMOS sensor,It is working fine.I have followed the exact code as given in AVR datasheet.Only he registers in the sensors are not getting updated.Is thr sumthing I am missing ? How can I find out where the mistake lies ?
March 20th, 2008 at 12:34 pm
Hello!
I need to know if I am interfacing a 5 V Atmega 32 with a peripheral like say an SRAM working at 3.3V , then do I need to scale down all my data lines to 3.3 V as well ? If I do not , the muc will drive high lines to 5V while my SRAM’s rating is only 3.3V , so will that blow it up ?
March 22nd, 2008 at 11:15 am
You should read SRAM datasheet to find out if it tolerates 5V signal. If it tolerates 5V input, then there should not be a problem.
If not, then you should scale dowt the signal from AVR to SRAM. You can use a transistor key powered from 3.3V or 3.3V buffer IC. You can go more rude by using a simple resistor voltage divider.
March 28th, 2008 at 8:31 pm
how to change the baud rate of programming Atmega16 using ponyprog. I am using SPI dongle. But I want to change baud rate to a value less than 100bits/sec.
Is it possible? how? what is the minimum baud rate that can be achieved?
March 30th, 2008 at 11:30 pm
Got an Atmega32 and programed it with ispprog.
I unchecked all Cksel boxes.
I understand this is opposite to ponyprog?
The case is i get now unknown device, i suppose in this config i have set to ext clock source?
April 11th, 2008 at 10:54 am
i want to configure atmega32 for 4MHZ crystal
plz can you help ?
April 15th, 2008 at 7:30 pm
Hi,
I would like the fuse settings for a ATmega32 to be used with a 16MHz crystal. Could you please help me?