Pages

Fuse Setting for the Clock

Using External Clock or Internal Clock ?


If you use WinAVR to program the AVR microcontroller and you want to use internal clock or external clock, You should changes the fuse of microcontroller. Before learn about this, you should know about how to use WinAVR and Makefile. You can see my early article here.

When you has installed WinAVR, you had also installed avrdude in you computer. Avrdude is used to program the AVR.

Now, if you want to check fuse setting on your AVR:
-          you should connect your AVR to your computer using ponyser programmer (RS232 to AVR ISP), or stk500 (usb to AVR ISP), or other kinds of programmer.
-          run command prompt as administrator.
-          type: avrdude –c stk500 –p atmega16 –P com4 –v (in this sample, I use atmega16 and stk500 prgrammer, if you use ponyser, change stk500 to ponyser, the com port is found by trying the command. If com4 don’t work, change to com1, com2, or com3)
-          If it is right, you will see the picture below. 

-          The value of lfuse = 0xE1. By the fuse table from datasheet atmega below, we know that it’s the setting for using internal clock. 

-          If you want to use external clock, set the lfuse to 0xEF by type : avrdude –c stk500 –p atmega16 –P com4 –U hfuse:w:0xD9:m –U lfuse:w:0xEF:m
-          The result is on picture below. 


If you use high frequency, of course the program in your chip is running faster. So, the fuse setting is very important if you want to change the speed of program processing. Another thing, don’t forget to change F_CPU in your source code and Makefile file because the _delay_ms(long int x) function from WinAVR library, using F_CPU variable to calculate the duration of delay and has been adjusted to clock of the chip. F_CPU should be the same as clock of the chip.

For experiment, I make a program:
#include <avr/io.h>
#include <util/delay.h>
#define F_CPU 1000000UL
void main(void)
{
       DDRA=0xff;
       DDRC=0xff; //PA and PC as output
       PORTC=0x00; //PC always low voltage
       while (1) //looping forever
       {
              PORTA=0xf0; //PA7-4 high, PA3-0 low
              _delay_ms(500);
              PORTA=0x0f; //PA7-4 low, PA3-0 high
              _delay_ms(500);
       }
}

I try it on my board for:
internalclock 1 Mhz and F_CPU 1 Mhz, internalclock 1 Mhz and F_CPU 16 Mhz, externalclock 16 Mhz and F_CPU 16 Mhz, and externalclock 16 Mhz and F_CPU 1 Mhz. The result is in video below.


 The normal delay is 500 ms, as that have been declared in program.


http://electricalgaze.com

6 comments:

  1. Truckingcube provides Bulk Transports Services at very affordable price. To know more just visit www.truckingcube.com

    ReplyDelete
  2. Are you shifting from your current home in to another home in another locality of Pune? Then visit our website dishapackersandmovers.com and Get all information such as rate and review etc and delivered your goods within a given period of time.

    For more info :- Packers and Movers in Pune

    ReplyDelete
  3. If you are looking for Art festivals in delhi? Then Visit our website artdirectoryindia.in and Get all information regarding your query and Art Festival Creates And Promotes India?n? Art Fair And Events And Exhibitions In India.


    art festivals in delhi
    Dance festivals in india
    fine art jobs in delhi
    film festivals in india
    Threatre festivals in delhi
    Dance festivals in delhi

    ReplyDelete