I want to write code for another atmega8 running at 1MHz internal RC oscillator using the Arduino IDE and its libraries. I have an ISP programmer to burn the code. What are the things that I should care about? How can I compile the code for 1MHz instead of 16MHz?


2 Answers 2


You would need to add a new hardware configuration. Here the procedure is explained for an ATMega328: http://arduino.cc/en/Tutorial/ArduinoToBreadboard but you would need to adjust the example hardware config or maybe you'll find a working one.


It depends specifically on what compiler/library you're using to write the AVR code, but in general, so long as you compile the code with the proper preprocessor macros #define'd for the CPU speed, you should be good to go.

For example, in the avr-libc documentation, the delay functions and UART baud rates rely on the definition of the F_CPU macro. The proper way to set the CPU speed in such a case is:

#define F_CPU 1000000UL     // 1 MHz, 16MHz is 16000000UL
#include <util/delay.h>     // Delay functions library, delay values based on F_CPU.
#include <util/setbaud.h>   // Automatically sets UART baud rate registers based on F_CPU.

I have also noted the use of #define FOSC to set the CPU speed in some architectures/libraries (in the same way as above, so you could also follow with #define FOSC F_CPU). For this reason, note that the particular macro you need to define/re-define may differ.

If you're using an integrated development environment, setting the clock frequency in your project settings may automatically define the above variables during compile-time. In that case, no settings should need to be made to the code, unless your code is using the wrong preprocessor macro (or hard-coded value) for the processor frequency. To be sure, I would double-check what macro is being set by the IDE, and ensure your code uses the correct values.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.