1
\$\begingroup\$

Hello I will use this circuit to put lights in a model car:

Now the question is if you can see is required one ATMEL AVR ATmega168P with CPU clock frequency to 8 mhz and I can´t find in any place something with 8 mhz. For example:

http://www.mouser.com/ProductDetail/Atmel/ATMEGA168P-20PU/?qs=sQl1Qs3BAuUB3FY8Qd8AOQ%3D%3D

http://www.amazon.com/ATMEL-ATMEGA168P-20PU-ATMEGA-20MHZ-DIP-28/dp/B00MMYP0AM/

I heard about the ATmega168P-PU like the link at top but in specifications they say 20mhz. In resume any place I found 168P I can´t see something that say 8Mhz. Can I use for example that chip amazon sells and does not affect in the function?

I bought this programmer also:

Atmel AVR AVRISP mkII AVR ISP mk2 USB XPII Debugger Programmer for Studio 4/5/6 eBay item:251058218265

I hope you can help I have everything I just miss the 168P 8Mhz or if someone know where can I buy.

update:

Then in conclusion I can buy

http://www.amazon.com/ATMEL-ATMEGA168P-20PU-ATMEGA-20MHZ-DIP-28/dp/B00MMYP0AM/

And I will be safe ok?

\$\endgroup\$
  • 1
    \$\begingroup\$ The clock frequency the CPU runs with depends on the external crystal you use. The data sheet specification (like 20MHz) is just the maximum you can run the controller at. \$\endgroup\$ – Rev1.0 Jun 4 '15 at 13:11
  • \$\begingroup\$ You are using many leds so make sure that you check the max allowed current per pin and port in the electrical characteristics section of the datasheet. \$\endgroup\$ – alexan_e Jun 4 '15 at 14:45
2
\$\begingroup\$

The clock frequency the CPU runs at depends on the external crystal you use. The data sheet specification (like 20MHz) indicates just the maximum clock frequency you can run the controller at.

Most (all?) AVRs also provide an internal RC clock generator which is set to 1MHz by default. However, the internal RC clock has large tolerances and tends to drift massively with temperature changes. This might not be an issue for your project though.

If the circuit is supposed to use and external crystal, the circuit diagram you posted omits it. There are other things "missing" like the reset-line pull-up, so the schematic is probably just intended to show the required GPIO wiring.

\$\endgroup\$
  • \$\begingroup\$ Is from that video I found that diagram but is there something missing what is? Someone told about reset-line pull-up. I have all the components on way but if there is something more to add or buy what can I add? On the video I don´t see nothing more special. \$\endgroup\$ – field3d Jun 4 '15 at 15:13
  • \$\begingroup\$ @field3d the reset resistor is important for noisy environments. I suggest you add a 10k ohm resistor from the RESET pin on the ATMEGA168P to VCC, \$\endgroup\$ – KyranF Jun 4 '15 at 15:40
3
\$\begingroup\$

For microcontrollers in general the speed rating is the maximum recommended clock rate for operation. So a 20 MHz device like you've found can operate at a lower rate such as 8 MHz. The ATmega168P has an internal 8 MHz RC (resistor / capacitor) clock which while not especially accurate saves having to use external components for a clock.

That's no doubt what that circuit uses because a crystal or external clock would need to be connected to pins PB6 / PB7 which are used for other purposes in that circuit. The RC clock is enabled by default so go ahead with a 20 MHz device and you should be fine.

By default there's something called a CKDIV8 fuse setting that may cause it to run at 1 MHz, so depending on the code / programmer you may need to change that if it seems to run eight times slower than you're expecting but that should be a simple configuration change, so I'd buy the part and see how it goes for a start but keep in mind you might need to work out how to change that CKDIV8 fuse if it runs too slowly.

\$\endgroup\$
3
\$\begingroup\$

Most of the ATMega MCUs can run at up to 20MHz (although lower max MHz if you run them at lower Vcc - look for 'Safe Operating Area' in the datasheets), but you can clock them at any frequency you want, up to 20MHz.

The good news for you is that the '168 (and most other ATmega MCUs) have an internal RC-oscillator that can run the MCU at up to 8Mhz, no external crystal required, although out-of-the-factory they start-up at 1MHz, until your initialisation code changes the CPU clock divider to go faster (or slower).

At clock frequencies above 8MHz one would typically need an external crystal or ceramic-resonator (connected to PB6 & PB7, with fuse bits set accordingly).

Also, if you're wanting to reprogram the 168 while it's in your circuit (i.e. without having to remove it, assuming you've got it in a DIP-socket) you're going to need to allocate 4 pins to the ISP functionality (which is what your AVR ISP mkII connects to, to be able to reprogram the 168 without having to physically remove it) - those signals are: PB3 (MOSI), PB4 (MISO), PB5 (SCK), & pin-1 (RESET). You need to bring those 4, & Vcc & Gnd, to a 6-pin (2x3) 2.54mm-pitch header that your AVR ISP mkII programmer can connect to for reprogramming. Also, make sure you don't disable the SPI peripheral with your fuse settings, otherwise you'll brick the 168 & need a 'high voltage programmer' to be able to reprogram it again.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.