ATmega8 setting the CPU clock - Page 1
Forum section: electronics / general

author: jproject
author_rank: Contributor
timestamp: June 20, 2011, 03:21:19 pm
content: 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!

author: Unknown
author_rank: Unknown
timestamp: June 20, 2011, 06:27:47 pm
content: To change clock settings, you need to change some fuses. Use afuse calculatorto 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.

author: jproject
author_rank: Contributor
timestamp: June 20, 2011, 08:51:39 pm
content: Damn, I have no idea what that is but at least I have some sense what to search for.Thanks!

author: westfw
author_rank: Super Contributor
timestamp: June 20, 2011, 11:42:36 pm
content: QuoteWell, 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"

author: Unknown
author_rank: Unknown
timestamp: June 21, 2011, 08:14:58 pm
content: Quote from: westfw on June 20, 2011, 11:42:36 pmDoes 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.

author: westfw
author_rank: Super Contributor
timestamp: June 21, 2011, 11:50:40 pm
content: @alm: you're correct! I was assuming more commonality between mega8 and mega48/88/168/328 than actually exists. Sorry for providing incorrect info. We're both right that 16MHz isn't one of the choices, though!