Electronics > Microcontrollers

ATmega8 setting the CPU clock

(1/2) > >>

jproject:
Hello everyone,

I've been trying to learn the ATmega8 coding for a day or two and I'm confused about the ADC clock and the default clock for the CPU.

So, from my understanding, you set the ADC clock using the ADCSRA register and its division factors to set the ADC clock between 50Khz to 200Khz. Now, I thought the clock for the CPU is 16 Mhz but its default is 1Mhz. So, you use a division factor of 8 (since 1000Khz/8 = 125Khz). But, if the CPU clock can go up to 16Mhz, how do you set it to 16Mhz? I've been trying to google "ATmega8 setting clock" or something similar but no luck. Like for MSP430 LaunchPad, you would use BCSCTL1 and DCOCTL registers to control the frequency of the digital clock oscillator for the CPU but I can't seem to find the registers to set the CPU clock for the ATmega8.


Thanks a lot!

alm:
To change clock settings, you need to change some fuses. Use a fuse calculator to save you the hassle of going through the data sheet each time, although you should first understand the meaning of the fuses before changing them. Beginners often have trouble with the clock fuses, setting the clock fuses wrong (eg. external clock instead of external crystal) will result in a 'bricked' MCU (until you provide an external clock signal, that is). Note that fuse bits are different for different parts, be sure to select the correct one.

The internal RC oscillator can run at max 8MHz, you can set the frequency with the various CKSEL fuses. If you want a faster or more stable clock (eg. for RS-232), you need an external crystal or oscillator.

jproject:
Damn, I have no idea what that is but at least I have some sense what to search for.

Thanks!

westfw:

--- Quote ---I thought the clock for the CPU is 16 Mhz
--- End quote ---
Well, no.
There is an internal 8MHz oscillator, and a fuse to set if you do/don't want the primary oscillator divided by 8 before becoming the main system clock.  There is no way to "set the clock" to 16MHz.   You have to set (other) fuse bits to tell the clock generator to use an external oscillator, crystal, or resonator, and provide a 16MHz version of one of those, in order o run the CPU at 16MHz.

This is described in the datasheet in the section titled "System Clock and Clock Options"

alm:

--- Quote from: westfw on June 20, 2011, 11:42:36 pm ---There is an internal 8MHz oscillator, and a fuse to set if you do/don't want the primary oscillator divided by 8 before becoming the main system clock.

--- End quote ---
Does the ATmega8 have a CLKDIV/8 fuse? I seem to remember it doesn't, although it does allow you to specify the clock frequency (somewhere between 1MHz and 8MHz I think) with the CLKSEL fuses.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod