atmega32 clock speed

I am having some trouble changing the clock speed on atmega32 from the default 1mhz. I have messed with the fuse but having been able to get it right. Can anyone help me out? I have used the sparkfun tutorial for guide but it doesnt really go into enough detail to help me with the atmega32.

The fuse bits only set the initial clock multiplier. You can change the clock multiplier during the initialization of your program to whatever you want it to be. I usually do this instead of messing with the clkdiv8 fuse because I then don’t have to worry about creating a situation where I can’t program the chip.

If this is an arduino, I’m not sure how to do it in that environment. If it’s just a bare ATMega32, it’s pretty easy in either assembly or C.

How would you do it during initialization, is that the #define F_CPU? If so, is there a simple way to test what speed it is running at? btw I use avr_gcc compiler with a bare atmega32 and I program it with a Direct AVR Parallel Access cable. (DAPA)

Thanks,

Shane

It appears I’m wrong on this. I just looked at the data sheet and I can’t find the section on the clock prescaler. I must admit this is the first time I’ve seen an AVR without it. Normally, it would be used to reduce power consumption by allowing you to dynamically change the speed of the core. Seems strange they didn’t include it.

Anyway, it looks like you have no choice but to program the cksel fuses. Page 29 lists the values you would need. If you have already read that page and it’s still not working, it’s most likely an issue with the capabilities of the programmer you’re using. Unfortunately, I’m not familiar with the specific programmer you have.

#define F_CPU is only used in the AVR libraries - it doesn’t actually set the clock speed at all. There are places in the code where the compiler will dynamically calculate how to perform certain time sensitive functions. It uses the value of F_CPU to make those calculations.

The Mega32 is an older device and does not have the System Clock Prescaler which is the easiest way to adjust the speed dynamically.

For the the mega32, your choices are 1, 2, 4 or 8 Mhz via the internal RC oscillator (default is 1) or you need an external timing source (resonator being my favorite). Regardless, you need to set the fuse bits to select whichever you want.

Look in section 8 of the datasheet for full details on selecting the different modes.