ATmega8: clock source and configuring CKSEL

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am very new to AVR (and uControllers in general). I am trying to figure out how to set up ATmega for diferent clock frequencies.

I am working thru this tutorial http://electrons.psychogenic.com/modules/arms/art/14/AVRFusesHOWTOGuide.php.

In part it says:

Quote:
By checking the Clock Sources section of the datasheet, you can see that the clocking options are set using 4 CKSEL bits that specify the type of clock source the chip will use, and the CKOPT bit (which tells the chip to pay attention to our CKSEL bits and influences startup time).

The actual bits you use depend on the hardware you've got. Here we'll say we're using a 2MHz crystal. In this case, we determine that we should set CKSEL3..0 (this notation, used in the datasheets, indicates CKSEL bits 3 to 0, starting at 3) to 1100 and we should also ensure the CKOPT bit is 1.

Now that we know which bits we wish to set we need to know where they fit in, in the grand fuse byte scheme of things. To do this, have a look at the following tables, which indicate the position and function of each bit in the low and high fuse bytes (for the ATmega8).

I am confused as to how the value for CHSEL0 is determined. When I look at the data sheet (pg26 thru 29), table 4 says that CKSEL3..1 should be set to 110. But table 5 is not clear as to how CKSEL0 is determined?

Another question is this: what got me started on this "rabbit trail" was that I wanted to (for leducational purposes) set up a circuit and write a program that read a switch (so I was looking over tis tutorial - http://www.micahcarrick.com/05-15-2006/avr-tutorial-switch-debounce.html. It suggests using an external 8Mhz crystal. Can i just use the 8Mhz internal RC Oscillator?

Thank you for the any help :D

Russ

Russ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which programmer do you have? It can be as easy as selecting "external crystal 8 mhz" with AVRStudio and an Atmel programmer and as difficult as to try and guess the correct CKSEL and kill your chip with a "cheap" programmer.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the quick reply....I have the AVRStudios and an ATAVRISP2 (http://www.digikey.com/scripts/us/dksus.dll?Detail?name=ATAVRISP2-ND).

I think I would like to do it the easy way :D

Out of curiosity - or in that case that my programmer is of the "cheap" variety - how does one conclude from the data sheet the correct setting.

Thanks again!

Russ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I never bother trying to figure out the CKSEL, just choose the correct one from the dropdown menu of Studio.

So provided you have a 8MHz crystal and 2 caps, select the very last setting down the bottom of the list an it will work.

Whatever you do NEVER select "external oscillator" or you will lose the clock to the chip.

Attachment(s): 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you! :D

Russ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What freq would i have set if CKSEL3..0 is 1100?

Update: sorry i got it, its 2mhz oscillator

[do NOT cross post - you already asked about mega 8 with 1100 in your own thread!]