Knowledge Base‎ > ‎General Gyaan‎ > ‎Tutorials‎ > ‎

Fuse Bits : Changing your MCU speed and JTAG

posted Sep 17, 2016, 7:07 AM by Rohit Bhaskar
When you begin with micro-controllers, and you are reading the datasheets or tutorials, you are very likely to have come across the term "Fuse Bits" which relate to the MCU speed and JTAG. Being beginners and not having the slightest idea about both, it is generally left for "later, when I get more experienced" . The fact that even the tutorials promise to come to it later adds to this lack of confidence. 

When I was trying to interface my LCD with my ATMEGA16, I found that the display was being printed too slow for my liking , and so I resolved to increase the MCU speed. (though that was not the real problem, as I later found) 

So here I am, with no knowledge about fuse bits or JTAG or anything. So what I do ? Read the datasheet, of course !! 

Here's what the datasheet says : 

There are two fuse bytes : lfuse (lower fuse byte) and hfuse (higher fuse byte). These represent atributes of the MCU, and can be programmed to change the attributes. See the table below for the attributes : 

 

 
(Source : ATMEGA16 Datasheet)

For our purpose, in the hfuse byte we need to reset the JTAGEN to disable JTAG, and reset CKOPT to enable us to select a different internal clock. CKOPT, you can understand, but why change the JTAG part ? That's because four pins of PORTC are JTAG enabled and sometimes give weird unexpected output if not disabled. The other bits can be left unchanged. 

Now, we need to change the 4 bits of CKSEL in the lfuse byte to select the internal clock speed. Here's the table for different clock speeds.

  
(Source : ATMEGA16 Datasheet) 

Now, how do I program it ? AVRDude or ICCAVR. 

Its very easy to do so in ICCAVR and you don't even need to know about the above fuse bits, but I don't use ICCAVR and find AVRDude better. So here's how to go about it in AVRDude. 

First make the makefile that you generally make for your programs. Then burn a program into your mcu. Keep the MCU and programmer connected during the whole process and never apply a reset until the whole thing is over. Note the first line of the output window below. 

It looks something like this : 

avrdude -p m32 -c -bsd -u programname.hex 

Now go over to DOS mode and follow the steps in the picture below. 
 

 
(Image courtesy : Bibin John's Ebooks) 

Remember though : The above settings were an example. The bits might be different for your device. Just change the ones that you need after consulting the table above, leave the remaining ones unchanged, calculate the resulting hex number and replace it in the appropriate places. 

I hope you all find it quite simple, just as I did. 

Oh and ya, congratulation !! Your MCU has now become 8 times faster !!! 

Caution : Once you change your fuse bits to use an EXTERNAL clock, remember that you won't be able to even program your MCU without using that clock. You will just get an "AVR Device not responding" error, so be careful with what you do !
Also make sure you calculate the fuse bits for the specific micro-controller(this tutorial deals with ATMega16) because each one will have its own byte structure!



Contributed by :
Ankit Daftery
ankitdaf [at] gmail [dot] com

Comments