NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » External Crystal Clock with Atmega168 PWM

July 21, 2011
by lavared
lavared's Avatar


I have a few basic questions regarding the external crystal clock for PWM implementation. I'm using a nerdkit Atmega168 chip with the supplied 14.7MHz external crystal for PWM implementation. I have read that the Atmega168 chip also has internal RC clock of 8MHz(with a divider of 8, essentially 1MHz output). My questions are:

  1. How do I make sure that external clock 14.7Mhz is being used for PWM implementation and not the internal clock ?

  2. Would defining in the code like "#define F_CPU 14745600" suffice (since I'm using the nerdkit programmed chip) or do I need to play with the external fuse settings.

  3. For this external crystal, is there any clock divider (like for the internal clock) that needs to be taken care of to use the full 14.7MHz freq (i'm not taking about the timer pre-scalers for PWM)?

Srry for these basic questions but I'm relatively new to this field and still finding my feet here.


July 21, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi lavaraed,

Which clock is used for chip operation is determined by the fuse settings. The chip as you received it from us already has the fuses set to use the oscillator to run its clock source.

The define F_CPU 14745600 does not have anything to do with the actual operation of the chip, it is merely a reference for any piece of code that needs to know what the frequency of the CPU is.

There is a register that will set up a division factor for your system clock if you want to use it. You can read about the CLKPR register on the datasheet page 38.

Hope that clears thing up.


July 21, 2011
by lavared
lavared's Avatar

Thanks Humberto. That answers my question.

Post a Reply

Please log in to post a reply.

Did you know that you can connect digital calipers to a microcontroller? Learn more...