Changing the clock speed?

I need to edit the arduino bootloader so that my ATmega168 will run at 20Mhz instead of 16. Which file do I need to edit in the bootloader folder in the Arduino directory? There’s one called “ATmegaBOOT_168” (C file), one called “ATmegaBOOT_168_diecimila.hex” (HEX file), once called “ATmegaBOOT_168_ng.hex” (HEX file also), and one called “Makefile” (from what I’ve learned that’s for Unix/Linux users. Now, I am using a Diecimila, so obviously I’ll be ignoring the “ATmegaBOOT_168_diecimila.hex” file. Do I need to just edit the Makefile and then compile it into a HEX file? If so, using what program?

Is anyone going to help me on this? This is one of those things where I can’t try to ‘experiment’ to solve the problem; I don’t want to be experimenting with a bootloader; it’s kinda like messing with a BIOS. I only have one ATmega168 on hand, so I can’t afford to skrew up.

I don’t know what’s involved in changing the bootloader clock speed, so can’t help you there.

I think that no fuses would need to be changed to go from 16MHz to 20MHz, so if the experiment goes bad you can simply put the standard 16MHz bootloader back on.

If you have the capability to burn a new bootloader (i.e., a programmer) you can burn sketches directly to the ATmega.

I think with Arduino 0011 the easiest way to change the clock speed in the code is to create a new board type (in boards.txt) and the appropriate parameters should propagate to the code.

-j

"If you have the capability to burn a new bootloader (i.e., a programmer) you can burn sketches directly to the ATmega.

I think with Arduino 0011 the easiest way to change the clock speed in the code is to create a new board type (in boards.txt) and the appropriate parameters should propagate to the code."

Hmmm. That’s a good idea, buuuttt…I don’t have a parallel port on my laptop, and I don’t have access to our desktop that DOES have one, only when I absolutely need to burn a new bootloader, and I’m going to want to be able to upload new sketches all the time. How can I get the bootloader on the actual microcontroller to accept a 20Mhz crystal to I can upload sketches through my USB port as I used to?

How can I get the bootloader on the actual microcontroller to accept a 20Mhz crystal to I can upload sketches through my USB port as I used to?

The bootloader has no control over clock speed. Just swap out the 16MHz crystal for the 20MHz, and the ATmega will run at 20MHz. The bootloader has no way of telling what speed it is running at so you don’t need to worry about what speeds it will “accept”.
One thing you will have to watch out for is that the different clock speed will mess with delay, delayMicroseconds and millis.

“The bootloader has no control over clock speed.”

Then why is there a value labeled “FREQUENCY” in the Makefile in the directory for the bootloaders in the Arduino directory?

Just swap out the 16MHz crystal for the 20MHz, and the ATmega will run at 20MHz.

Yes, it seems THAT works, but when I go to upload a sketch to the ATmega168 with the 20Mhz xtal connected, the sketch won’t upload, and Arduino says:

“avrdude.exe: stk500_getsync(): not in sync: resp=0x72
avrdude.exe: stk500_disable(): protocol error, expect=0x14, resp=0x72”

What’s wrong with that? I don’t want to have to jumper the old 16mhz xtal from the Arduino board to the ATmega168 everytime I have to upload, then pop the 20Mhz xtal back into my breadboard after it’s finished, just so I can get it to work; that’s tedious to say the least! And I can’t burn a sketch because I don’t have access to a dektop with a parallel port I can use all the time (and I don’t have one of those devices that does it for you through USB from ATMEL). Although if I need to, I can use the desktop in my house to burn a new bootloader (that PC is used my another member of my household; I can’t use it very often, and I’m using a laptop).

The bootloader has no control over clock speed.

Control, no. But it does need some awareness, for timing reasons. At a glance, the USART Baud Rate Register (UBRRn) needs to know about the clock frequency.

-j

You should be able to modify the clock speed specified in the Makefile and rebuild the bootloader using make (you’ll need to have avr-gcc, etc. in your path).

Ok. That’s the answer I was looking for! But…please explain ‘make’ to me? Is that a program that compiles ‘Makefiles’, because I googled ‘Makefile’, ‘makefile compiler’, ‘makefile program’, and much more, and found nothing.

A) How do I compile this Makefile?
B) What is the end result and how do I use it/manipulate it to change the ATmega168 to accept sketches via USB through the Arduino carrier board when using a 20Mhz xtal, and use proper timing for running programs?\

Thanks for the help.

What operating system are you on? If Linux or Mac, I’m guessing make is already installed. Try searching for “gnu make”. The Makefile is a text file, you can edit it to change the clock speed. When you run “make”, it will generate the .hex file that you need to burn to the board.

Why do you need to run at 20 MHz, btw?

make is a utility designed for compiling executables from source (especially large projects with multiple source files, etc). A makefile describes the source files, intermediate files, dependencies, and steps required to generate the targets from their sources. make looks at file modification times to determine what has changed and runs the minimum number of steps indicated in the makefile to build a new executable.

-j

I am running Windows, so I don’t have Make.

I need to run @ 20Mhz because I am prototyping something, and since I don’t have a Boarduino (or what ever you call it), and I only have an Arduino, it is easier for me to just pop the ATmega168 on a breadboard, but I only have a 20Mhz xtal on hand.