Understanding AVR Fusebits (ATMega 16)
The AVR fuse bits settings are a crucial part of getting your AVR microcontroller up and running.
The fuse bits help to set the clock frequency being used, the startup time to be allotted and some more features like enabling programming through SPI, JTAG etc.
Let us look at the different bits one by one.
OCDEN (On chip debug enable)
This fuse bit when programmed keeps the clock source enabled even when the microcontroller is in sleep mode.
We generally keep it unprogrammed.
JTAGEN (JTAG Enable)
This fuse bit when programmed enables the use of JTAG and boundary scan. When you get a new ATMega 16 from the market the JTAG fuse is by default programmed i.e. JTAG is enabled. This causes the JTAG pins on PortC (TDI, TDO, TMS, TCK) to be pulled high and used in the JTAG mode.
So to use PortC for normal operation disable the JTAGEN fuse bit.
SPIEN (SPI Enable)
This bit when programmed enables programming of the AVR through SPI.
CKOPT
With CKOPT unprogrammed the AVR can be used for clock frequencies up to 8MHz. For operations above that keep CKOPT programmed.
EESAVE
When programmed the contents of eeprom are preserved even during chip erase.
BOOTSZ1…0 (Boot Size)
It selects the boot section size (For setting the size refer datasheet)
BOOTRST (Boot Reset)
When programmed, the device will start from the boot loader address at reset.
BODLEVEL (Brown out detection level)
Brown out level is the supply voltage level below which the normal working of microcontroller cannot be guaranteed. A brown out reset occurs whenever the supply voltage falls below a specific voltage level.
When unprogrammed the brown out voltage level is set at 2.7V and when it is programmed it is set at 4V.
BODEN (Brown out detection enabled)
Enables the brown out detection reset when programmed
SUT1…0 (Start up time)
The SUT1…0 along with the CKSEL0 bits aid you to select a particular startup time. The startup time is the time period between switching on of the microcontroller and the start of instruction execution.
A higher startup time is a safer option usually. This gives enough time for the crystal oscillations to stabilize.
CKSEL3…0 (Clock Select)
Using the CKSEL3…1 you can set the frequency that you will be using.
The following are some decent configurations according to the clock frequency to be used.
1MHz (Internal Oscillator)
Higher Byte 11011001
Lower Byte 11100001
8MHz (External crystal oscillator)
Higher Byte 11011001
Lower Byte 11111111
16MHz (External crystal oscillator)
Higher Byte 11001001
Lower Byte 11111111
Note: Here programmed means setting to 0 and unprogrammed means setting to 1