ATmega168 clock speed?

I've built a couple of single sided serial boards with the intention of populating them with ATmega168s. I've had some trouble getting started with the 168, but I accidentally found out why - I was running it at 20MHz. When I forgot to switch an ATmega8 crystal out of my development board and ran it at 16MHz it worked fine.

Where did I get the idea that the 168 Arduino ran at 20MHz and, more importantly, what has to be done to run it at 20MHz? I know there are a few things that need to be done in the Arduino environment, but what about the bootloader? I assume it will need to know so that the RS232 rate is correct.

-j

All I had to do is replace the 16 MHz crystall with a 20 MHz, and flash a 20 MHz bootloader to the 168. I think the delaymicroseconds command is hard coded, so your delays withh be 80% shorter than at 16 Mhz. I have previously posted the HEX for the 20 MHz boot loader on this forum somewhere… If you can’t find it readily I can PM you one.

D.

Looks like I need to get the bootloader source from http://webzone.k3.mah.se/projects/arduino-workshop/upload/default.asp?folder=40, then build a copy for 20MHz.

Is there an easy way to add entries to the Arduino environment? I'd like to have two ATmega168 entries when choosing the processor: one for 16MHz, one for 20MHz.

-j

We're planning something like that, but for now you'll have to edit the preferences.txt file manually. As we get more people making custom boards, we'll probably implement a better method for creating custom configurations.

Could someone confirm that the 168 MUST be used with an external 16mhz crystal for Arduino to run 100% correctly? (i.e. there is no way to get it to run totally properly with the internal oscillator.)

Thanks!

The internal oscillator will only go at 8MHz or less. You would need to reprogram some fuses, build a new bootloader for your speed, and set f_cpu down in your preferences.txt and even then some functions in 0007 won’t be right. More importantly, the oscillator in the 168 is not terribly accurate (+=10%), and unless you do the oscillator calibration procedure (±10%) you may not be able to stay in intolerance for rs232.

Thanks for the details. We're using the 8/168 for some heavily timing dependent applications like stepper motors and servos (and also RS-232), so it sounds like the internal oscillator is quite out of contention.

Can anyone suggest a part number for a crystal with the caps built in that's worked well for them? Our projects are reaching the point where space is becoming an issue.

Thanks!

hi

If you are in the US or Canada, try looking in the Digikey catalogue for surface mount crystals and caps. You should be able to get a combination that is really really small.Of course similar items are available in the EU and elsewhere, but I am not sure of the supplier.

D

In addition to surface mount crystals, you can also switch to a surface mount 8/168 for a serious size reduction. Look at the arduino stamp for comparison.

-j