Author Topic: ATmega8 setting the CPU clock  (Read 12132 times)

0 Members and 1 Guest are viewing this topic.

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
ATmega8 setting the CPU clock
« on: June 20, 2011, 03:21:19 pm »
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!
« Last Edit: June 20, 2011, 03:44:12 pm by jproject »
 

alm

  • Guest
Re: ATmega8 setting the CPU clock
« Reply #1 on: June 20, 2011, 06:27:47 pm »
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.
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: ATmega8 setting the CPU clock
« Reply #2 on: June 20, 2011, 08:51:39 pm »
Damn, I have no idea what that is but at least I have some sense what to search for.

Thanks!
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4277
  • Country: us
Re: ATmega8 setting the CPU clock
« Reply #3 on: June 20, 2011, 11:42:36 pm »
Quote
I thought the clock for the CPU is 16 Mhz
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

  • Guest
Re: ATmega8 setting the CPU clock
« Reply #4 on: June 21, 2011, 08:14:58 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.
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.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4277
  • Country: us
Re: ATmega8 setting the CPU clock
« Reply #5 on: June 21, 2011, 11:50:40 pm »
@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!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf