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:
#define F_CPU 1000000UL
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
PORTA=0x0f; //PA7-4 low, PA3-0 high
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.