Before reading this post , be aware that playing with fuse settings may render your AVR chip dead or useless.Take care before setting any of the fuse bits.Fuse programming is most crucial and any mistake might lead to non-functioning AVR controller.

There are 3 bytes of Resettable Fuses that you may change as many times as you’d like.

HFuse ,LFuse & EFuse   (High Byte,Low Byte & Extended Fuses)

Apart from this there are 6  Lock bits in ATMega16/32 which are fuses that can be used to lock down the chip.Memory lock features can be set using these lock bits & also further programming of Flash & EEPROM can be disabled.

By default ATmega16/32 AVR chips are factory set as

Hfuse   0×99  (b 10011001)
Lfuse    0xE1  (b 11100001)

H fuse:  JTAG ( Enabled ), OCD ( Disabled) ,SPI Programming( Enabled),          CKOPT (Unprogrammed ), EEPROM Preserve( Unprogrammed )
BOOT size       : 1024 words &  Reset Vector    : User flash code

L fuse:  Brown-out level : 2.7V  ,Brown-out detect: Disabled
Startup timing  : Default ,Clock Source   : Internal, 1MHz

Setting AVR fuse bits correctly is most important and equally confusing part for many beginners.Remember that if fuse bits are incorrectly programmed it may cause to brick the IC .

Take a look at this table of Fuse Bits of ATMega 16/32fuse3

Low Fuse

Bit 7  BODLEVEL   Brown out detector trigger level (1 unprogrammed)

Bit 6
BODEN  Brown out detector enable 1 (unprogrammed, no BOD)

Bit 5
SUT1   Select start-up time 1 (unprogrammed)

Bit 4   SUT0  Select start-up time 0 (programmed)

Bit 3  CKSEL3  Select Clock source  0 (programmed)

Bit 2  CKSEL2  Select Clock source 0 (programmed)

Bit 1 CKSEL1 Select Clock source 0 (programmed)

Bit 0 CKSEL0  Select Clock source 1 (unprogrammed)

High Fuse

Bit 7  OCDEN On Chip Debugging Enable 1 (unprogrammed)

Bit 6  JTAGEN  Joint Test Action Group Enable 1 (unprogrammed)

Bit 5  SPIEN Enable Serial Program and Data Downloading 0 (programmed)

Bit 4  CKOPT Clock Oscillator options 1 (unprogrammed)

Bit 3 EESAVE  EEPROM memory is preserved through the Chip Erase
                            1 (unprogrammed, EEPROM not preserved)

Bit 2  BOOTSZ1  Select Boot Size 0 (programmed)

Bit 1  BOOTSZ0 Select Boot Size 0 (programmed)

Bit 0 BOOTRST Select Reset Vector 1 (unprogrammed)

 

The datasheet for each microcontroller contains detailed information on the fuse bits available and their function. Setting  a “1” in a bit means it is unprogrammed while having a “0” is considered to be programmed. Do not get confused by the notation used.As per ATMEL design “0” means programmed.

There are different clock source in AVR. You can choose one by setting or clearing any of the LFuse bits CKSEL0 to CKSEL3.

The mostly widely used option is to connect the crystal oscillator. In this mode CKOPT IS programmed (write its bit value 1 to 0).Then OSC generates full rail to rail output swing.If it is left at 1, then it has limited frequency swing.

ATMega 16 by default runs at 1MHz internal oscillator.But generally you use an external crystal of 8MHz across pins 12 & 13 .Note that ATMega 16L can work at a maximum  of 8MHz crystal.So do not use a 16MHz crystal for L series IC. 16MHz crystal works for ATMega 16A or ATMega16 plain.

To set the IC to work with an external crystal you have to set the Low & High Fuses as

HFuse 0xC9    OCDEN disabled,JTAG disabled, CKOPT programmed to high swing osc.

LFuse  0xFF  set all bits as 1 ie., unprogrammed.

If you set the fuse bit for using external clock and forget to use a crystal between pins 12 & 13 ,then AVR IC is not going to oscillate.It behaves as dead till you connect a crystal externally. 

ATMega16 consists one JTAG port which shares 4 pins of PORTC. If you complain that PORTC pins do not work properly then JTAG should be disabled.

JTAG port should be disabled if you want these pins to be used as normal IO pins (PC2,PC3,PC4 &PC5).

To permanently disable JTAG configure the 2 HIGH fuse bits  OCDEN (bit7) & JTAGEN (bit6).These 2 bits are to be set as 1.

So Hfuse will be 0XC9 against the default 0x99.

For setting the fuses ,you can use the free on line Fuse calculator from

http://www.engbedded.com/fusecalc/

engbed

 

We will see how to feed this Fuse settings in the upcoming post of Burner softwares for AVR.

AVRpal.Net ,Extreme burner , Sinaprog are some of the well known burner softwares.

To set the fuses manually you can start the command line program “avrdude” .

Type Run –> cmd.exe to open up the command window.

Your usbasp device should be connected to PC before starting the Avrdude.

Type C:\avrdude –p m16 –c usbasp –t

p is the part name which is Atmega16 in our case. So type “–p m16 “

c is the programmer type which is “usbasp”

is used to enter in AvrDude’s interactive window .

avrdude > d lfuse     –> returns the values of low fuse byte

avrdude > d hfuse    -> returns the value of high fuse byte

avrdude > w hfuse 0xC9  –> to write hex C9 in high fuse byte

Type Quit to terminate window. 

For more details on command line programming see tutorial 4 post.

Watch this video on FUSE settings :

AVR FUSE Setting Guide