Home / Snippets / Changing Arduino Clock Frequency / Programming ATMEGA 8 directly from Arduino Software using USBasp

Changing Arduino Clock Frequency / Programming ATMEGA 8 directly from Arduino Software using USBasp

Programming ATMEGA 8 is difficult because Arduino by default has a pre-defined clock frequency of 16MHz.

All the delay subroutine, PWM and Baud Rate generations are calculated using this frequency.

Programming ATMEGA 8 is difficult using this configuration, as ATMEGA 8 supports maximum 8 MHz clock frequency, or If you connect crystal other than 16MHz then serial communication will not work, delays and PWM will not be exact because default programming is done on 16 MHz.

If you want to check, what is current clock frequency, you can check it by following steps: –

1. For Arduino versions less than 1.0, press SHIFT key and click on COMPILE/ VERIFY

– For Arduino versions greater than 1.0, FILE > PREFERENCES > select COMPILATION (as shown in Fig)

Arduino IDE Options

– Now when you COMPILE, it will show compilation progress

Showing Log and verbose in Arduino IDE

– Look at the starting few lines of Arduino Compilation, check -DF_CPU=4000000L
– This is the Clock Frequency at which Arduino is compiling (i.e. 4 MHz), which is set by Me (Arduino default was 16000000L)

– The clock instructions like #define F_CPU 4000000 does not work on Arduino
– All you have to do is changing the board configuration.

Changing Frequency for Particular Arduino Board:

– If you are not using original Arduino board, or want to use the programmer to upload the program to a Chip using ISP, then you need to configure Arduino clock frequency for the crystal / clock used with the CHIP.
– To do so, open Arduino directory > Hardware > Arduino > AVR >

– Now create a backup of boards.txt
– Now open Boards.txt
– Find the board for which you want to change programming frequency
– For Example: If we you want to program ATMEGA8 IC using USBasp Programmer, having clock frequency of 4 MHz then find Arduino NG or older change atmegang.build.f_cpu=16000000L to atmegang.build.f_cpu=4000000L and in ATmega8 section find Fuses and change it to your required Fuse values

We have set fuse values to:

menu.cpu.atmegang.atmega8.bootloader.low_fuses=0xe3
menu.cpu.atmegang.atmega8.bootloader.high_fuses=0xc9

– Now save the file

– Now check if the frequency is set or not, by COMPILING the program

Showing Log and verbose in Arduino IDE

Programming ATMEGA8 using USBasp from Arduino directly:

If you want to program ATMEGA 8 IC directly from Arduino via USBasp Programmer, then Open Arduino, write program, select Arduino NG or older

Arduino Board Selection in Arduino IDE

Now Select ATMEGA 8 in Processors:

Selecting Processors in Arduino IDE

Select USBasp in Programmer:

Selecting Programmer in case if user don't want to program Arduino board

Now connect USBasp programmer with PC and click Upload using Programmer:

Program using 3rd party Programmer via Arduino IDE

– That’s All – Enjoy !!!

Check Also

Interfacing ADXL345 Accelerometer with Arduino UNO/ Mega

Interfacing Accelerometer ADXL345 (GY-291) with Arduino UNO/ Mega

Interfacing Accelerometer ADXL345 (GY-291) with Arduino UNO/ Mega Accelerometer ADXL345 is a 3-dimensional accelerometer, that …

2 comments

  1. I had to change here:

    C:\Users\’userName’\AppData\Local\arduino15\packages\arduino\hardware\avr\1.6.21

    Good job.

  2. thanks a lot,very useful

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: