2

I try to make an SD card-based WAV player with ATmega168. I have connected a 16 MHz quartz crystal, and it can give a 64 kHz carrier frequency and a 8 kHz sampling frequency.

But in that project I can multiply my frequency. So I connect a 16 MHz quartz crystal to ATtiny85, multiply it to 64 MHz and give a 250 kHz carrier frequency and a 32 kHz sampling frequency - much better.

I can't find a multiply function in the ATmega168 datasheet, so can I just connect a 64 MHz quartz crystal to MK?

Peter Mortensen
  • 1,676
  • 3
  • 17
  • 23
murzagurskiy
  • 123
  • 3

3 Answers3

4

You cannot do this. The architecture is not designed to operate at clock speeds over 20 MHz, there will be undefined behaviour.

The external clock sources are not multiplied inside the AVRs/ATtiny, they are only ever divided down. More advanced processors like the Atmel SAM series ARM Cortex processors have onboard PLL circuits for frequency multiplication which allows you to give it a 12 MHz external source, and multiply it up to the required 64,72, 120 MHz, etc. for the master clock. It seems the ATtiny x5 series does have an internal PLL with a x8 multiplier, but that is only for "peripherals" which is all you need anyway for the timers and PWM peripherals.

In the AVR chips you are using, if you read the datasheets they cannot operate on a master clock greater than 20 MHz, and even that is pushing it if you have low-quality power supply or temperature conditions.

On the ATmega168 you can PWM at around 250 kHz with a 16 MHz master clock (from external source) using the chip's "fast PWM" mode, sacrificing the bit resolution down to only 6-bit PWM.

You need to read more about clock sources, clock division, how these ATmegas deal with their clocks, and how "timers" are used with the PWM hardware in order to create these "carrier" signals at high speeds you are looking for.

Peter Mortensen
  • 1,676
  • 3
  • 17
  • 23
KyranF
  • 6,248
  • 16
  • 25
  • 2
    Oh it is certainly possible. http://3.14.by/en/read/arduino-liquid-nitrogen-overclocking – David Freitag Nov 09 '15 at 22:21
  • @DavidFreitag It's because as the switching transistors in the processing core get hotter, their resistance increases, and they slow down in switching speed and begin to malfunction if things are not as they should be when the next cycle is ready to begin. If you reduce the heat then of course you can delay this inevitable! – KyranF Nov 10 '15 at 03:06
  • I would be worried about the freezing stress cracking solder joints or other mechanical failures actually, and the whole idea is silly when you can just get an Atmel SAM3 or SAM4 ARM processor and get 64Mhz+ out of the box, on only 3.3V VCC, and no silly liquid nitrogen xD – KyranF Nov 10 '15 at 03:08
  • @KyranF, 6-bit PWM - where i can find the info about it? I try to find it in datasheet and can't. Should i just start FastPWM mode from 0xFF to 0x3F in OCR0A - which means 6 bit - and compare with OCR0B? It's seems like i could get 250 kHz... Am i right? – murzagurskiy Nov 10 '15 at 16:20
  • @gek0n There are many blogs about people doing this, here is one with code http://withinspecifications.30ohm.com/2014/02/20/Fast-PWM-on-AtMega328/ – KyranF Nov 10 '15 at 18:39
  • 1
    @KyranF Yes but simply saying you can't do something just because it can't be done at room temperature is just silly. Almost as silly as running an AVR that is cooled using liquid nitrogen. – David Freitag Nov 10 '15 at 19:57
  • @DavidFreitag your point is taken, but I'd prefer to take the aggressive "no" stance here, for the benefit of noobs. Adventurous people can always attempt to (and often succeed) break commonly accepted barriers. – KyranF Nov 10 '15 at 20:08
3

No, it won't work. See the datasheet. There are 10MHz and 20MHz speed grades.

ATmega168 speed grades

Matt Young
  • 13,734
  • 5
  • 34
  • 61
3

ATMega168 doesn't have the internal 64MHz PLL peripheral you are looking for, which indeed multiplies the clock frequency for some of its peripherals. ATtinyX5 series in the linked project does have this PLL. Only specific peripherals support this higher PLL frequency and certainly not the core itself, therefore you cannot simply connect an external high frequency clock to the device.

Here are some AVRs that are more or less similar to the ATtinyX5 used in the linked article, which do have support for PLL:

ATtiny26
ATtiny261a (The 'a' is an essential part of the part number! Similar for the other part numbers.)
ATtiny461a
ATtiny861a
ATtinyx5
ATmega128rfa1
ATmega16m1
ATmega16u2
ATmega16u4
ATmega32c1
ATmega32m1
ATmega32u2
ATmega32u4
ATmega32u6
ATmega64c1
ATmega64hve
ATmega64m1
ATmega8u2
ATtinyx61

But be sure to check the datasheet before purchase, because implementation and supported frequencies in specific devices may differ.

jippie
  • 33,033
  • 16
  • 93
  • 160