Providing clock to micro: crystal vs oscillator - Page 1
Forum section: electronics / beginners

author: Moriambar
author_rank: Unknown
timestamp: May 26, 2021, 07:09:51 pm
content: Hi,as the topic suggests, what are the differences between a (let's say 16MHz) crystal and oscillator? Is one or the other better to provide a clock to a mcu (eg, attiny)?Cheers

author: ledtester
author_rank: Super Contributor
timestamp: May 26, 2021, 07:33:41 pm
content: An RC-oscillator (like the one internal to the attiny) is not going to be as accurate as a crystal. It may not work for serial communication (especially high speed) or if you need precise timers.A crystal, on the other hand, is a very accurate and stable clock source.Edit: Crystal oscillators are also much less affected by temperature than RC-oscillators.A relevant stackexchange thread:https://electronics.stackexchange.com/questions/15455/internal-or-external-oscillator

author: pigrew
author_rank: Frequent Contributor
timestamp: May 26, 2021, 07:46:07 pm
content: Let me give a few advantages of eachAdvantages of crystals:CheaperLower power, able to easily be automatically disabled during MCU sleepGenerally lower EMI generation (with good PCB layout)Commonly used on dev boards, so there are many example designsAdvantages of an oscillator:Guaranteed to work without fuss. Crystals may need adjustment to series resistors, load capacitor values, amplifier drive strengths, etc.No need to study behavior across PVT (process,voltage,temperature) to ensure oscillator starts upTighter frequency tolerance without pulling (i.e., tweaking capacitors)Temperature compensation is availableEasy to fan-out to multiple clock inputsLower EMI: Availability of spread-spectrum clock outputs (for those who want jitter but lower RF emission peaks)

author: Moriambar
author_rank: Unknown
timestamp: May 26, 2021, 07:50:57 pm
content: Thanks for your replies. To clarify I was talking about external components not internal, but I got a really nice answer on that one.Cheers

author: Zero999
author_rank: Super Contributor
timestamp: May 26, 2021, 08:29:50 pm
content: A crystal requires an oscillator circuit to produce a clock signal, so the original question is nonsensical. All modern microcontrollers have the oscillator circuit build-in, so all that's required is an external crystal. Many microcontrollers also have a built-in RC oscillator, which will work without any external components.Going back to the original question: what do you mean? A 16MHz crystal oscillator vs another type of oscillator? What other sort of oscillator are you comparing it with? The microcontroller's internal RC oscillator? An oscillator made with a ceramic resonator? A MEMS oscillator?

author: Moriambar
author_rank: Unknown
timestamp: May 26, 2021, 08:41:08 pm
content: Quote from: Zero999 on May 26, 2021, 08:29:50 pmHello, and pardon my noobiness.I was talking about the difference fromthis(listed on digikey under oscillator) andthis, listed under crystal.Is one better than the other to use with an mcu? Why? With the crystal (as told) I should worry about extra components, or should I (based on what you said)?The internal oscillator of the tinys doesn't go up to 16MHz, that's why I wanted to use an external component.Anyhow my only experience with crystals is with rtccs and tweaking caps and calibration is a pain usually…thanks!

author: Zero999
author_rank: Super Contributor
timestamp: May 26, 2021, 09:21:42 pm
content: Quote from: Moriambar on May 26, 2021, 08:41:08 pmThe first link is a crystal oscillator, which contains the crystal and all the other necessary circuitry, required to produce a clock signal.The second link is a plain crystal. It requires external components in order to make an oscillator. Fortunately modern microcontrollers contain the other parts required to make an oscillator, from a plain crystal, except for a couple of small capacitors.The data sheet for the plain crystal lists several tolerances from ±10ppm to ±100ppm, with ±30ppm being standard. The data sheet for the crystal oscillator gives ±100ppm. I think the plain crystal is better, but it will depend on the exact part.

author: james_s
author_rank: Super Contributor
timestamp: May 26, 2021, 10:18:57 pm
content: Using a separate oscillator can be preferable if you need to clock other parts of a circuit with the same signal, not just the microcontroller. They also can provide a wider range of supported frequencies, or make selecting between multiple different frequencies. You have options for greater precision with a separate oscillator too, oven controlled or even rubidium oscillators are avalable.In most cases a crystal connected to the internal oscillator in the microcontroller is perfectly adequate, but an external self contained oscillator may have advantages in specific applications and you can always use one anyway if you wish.

author: Moriambar
author_rank: Unknown
timestamp: May 27, 2021, 06:15:26 am
content: Quote from: Zero999 on May 26, 2021, 09:21:42 pmAh, I see... I'm quite scared of crystals though: usually determining which values to choose for the caps is a demanding task (or one has to use a trim cap) since stray capacitance and whatnot are difficult to understand and calculate. Or is there a trick? I've seen the datasheet of the micro I'm considering (ATTINY84) and it's somewhat vague since they don't know which crystal you'll be using (I expect the same from other chips/manufacturers). Is there any trick I'm missing? Perhaps something specific to micros?Thanks

author: Moriambar
author_rank: Unknown
timestamp: May 27, 2021, 06:16:44 am
content: Quote from: james_s on May 26, 2021, 10:18:57 pmI see. I think I don't need the oscillator then, except for what I've written in my previous reply, namely that usually it's the pain to find the right capacitors/total capacitance to put at the pins of the crystal.thanks

author: james_s
author_rank: Super Contributor
timestamp: May 27, 2021, 07:11:31 am
content: It doesn't have to be a pain. Usually you can just toss something around 18pf on there and it will work, I think that's what I've mostly used, simply because I have a bag of them that I got about 20 years ago.

author: Moriambar
author_rank: Unknown
timestamp: May 27, 2021, 08:28:52 am
content: Quote from: james_s on May 27, 2021, 07:11:31 amAh, how can I determine the value?thanks

author: Zero999
author_rank: Super Contributor
timestamp: May 27, 2021, 08:37:47 am
content: Quote from: Moriambar on May 27, 2021, 08:28:52 amType crystal load capacitance into a search engine.

author: Moriambar
author_rank: Unknown
timestamp: May 27, 2021, 10:05:09 am
content: Quote from: Zero999 on May 27, 2021, 08:37:47 amI did that and I found a document (on my other computer) about evaluating the pin capacitance, the stray pcb capacitance etc... so definitely nothing immediate but the "tweaky calculation" I was referring to.Edit: by "tweaky" I mean that I don't know how actually have a value for the stray capacitance. Eventhis document by adafruitsaysQuoteso there's no way to know it unless I'm missing some rules

author: gcewing
author_rank: Regular Contributor
timestamp: May 27, 2021, 10:41:30 am
content: The exact capacitor value isn't critical unless you're really fussy about the frequency.The data for the crystal you're using will give you a recommended capacitance. As long as it's somewhere near that, the worst that will happen is that it will oscillate just a whisker off the frequency marked on the crystal.For most applications, that won't matter at all. If it does matter, you're probably going to want to put a trimmer on it for adjustment.

author: Ian.M
author_rank: Super Contributor
timestamp: May 27, 2021, 10:59:08 am
content: Unless you are trying to get spot-on frequency, which is generally not worth it, as you trim at a particular time and temperature, but ageing and temperature drift will almost certainly guarantee it doesn't stay exactly on frequency, as several others have pointed out, the crystal load cap values aren't that critical.If your layout is nice and tight, the stray capacitance will only be a few pF, so it generally comes down to see crystal datasheet for nominal load capacitance, double it (as the Pierce oscillator caps are effectively in series from the crystal's point of view), then pick the next lower E6 series preferred value, the rounding down roughly compensating for the expected stray capacitance.If your layout isn't nice and tight, why not? A sloppy layout with excessively long tracks to the crystal or excessive loop area not only makes choosing the load capacitors significantly harder, but it also vastly increases the oscillator's susceptibility to EMI, and its own EMI emissions. Don't forget ground track length to the load capacitors is also very important, nearly as important as keeping the crystal tracks short.

author: BBBbbb
author_rank: Unknown
timestamp: May 27, 2021, 11:06:33 am
content: Quote from: Moriambar on May 27, 2021, 10:05:09 amAda's recommendation seems reasonable in addition to manufacturing recommendations (should be in the datasheet/AN).Validating it yourself for offset and stability is probably out of your possibilities, so stick to the recommendation as close as possible.E.g. whenever we (my company) do some changes to the its caps we ask manufacturer (NDK) to validate on their side. We have this luxury since the quantity is not insignificant...

author: Moriambar
author_rank: Unknown
timestamp: May 27, 2021, 11:35:19 am
content: Quote from: Ian.M on May 27, 2021, 10:59:08 amso you're basically saying: choose a random value for the stray capacitance around 3-5pF (as per ladyada), take the load capacitance of the crystal, double and move down in the E6 series at least by the estimated stray capacitance?With numbers: CL=10pF, 3pF stray 10x2=20; 20-3=17 => 15pFand that will be close enough, right?Or am I missing something still?

author: Ian.M
author_rank: Super Contributor
timestamp: May 27, 2021, 12:10:17 pm
content: If you are explicitly subtracting the stray capacitance go for the nearest E6 value, not the next lower. If you go for the next lower, the assumption is that the stray capacitance to ground is comparable to the difference between adjacent E6 values.

author: ledtester
author_rank: Super Contributor
timestamp: May 27, 2021, 12:57:28 pm
content: I have a feeling you're sweating the stray capacitance issue a little too much at this point in the game.Even with all of the stray capacitance they add, there is no problem using crystals on breadboards:-https://youtu.be/sNIMCdVOHOM-https://youtu.be/ufQZnAAxZ7A-https://youtu.be/J3DYgzRvLT8Yes, the frequency will be affected, but you will still get a very stable clock signal.On a breadboard you can easily tweak the crystal's load capacitance by adding small picofarad caps in parallel. Program the MCU to output a steady clock signal on a GPIO pin and you can observe how the load capacitance affects the frequency.You can create small picofarad caps by simply twisting two pieces of wire together -- they're called gimmick capacitors:https://hackaday.com/2018/07/03/these-capacitors-are-a-cheap-gimmick/If you're designing a PCB you can add footprints for additional load capacitors which can be populated to fine tune the crystal's frequency.

author: Moriambar
author_rank: Unknown
timestamp: May 27, 2021, 01:03:06 pm
content: Quote from: ledtester on May 27, 2021, 12:57:28 pmmaybe. My past experience with crystals has been with rtccs and it was a pain. I guess for micros, as has been pointed out to me, precision is not that much of an issue

author: ledtester
author_rank: Super Contributor
timestamp: May 27, 2021, 01:07:46 pm
content: What's rtccs?

author: Moriambar
author_rank: Unknown
timestamp: May 27, 2021, 01:18:04 pm
content: Quote from: ledtester on May 27, 2021, 01:07:46 pmReal Time Clock and Calendar(s)

author: ledtester
author_rank: Super Contributor
timestamp: May 27, 2021, 01:33:00 pm
content: If those use 32 KHz crystals, then I agree that they are more difficult to work with especially on breadboards. I think you'll have a much easier time using the MHz crystals.

author: Zero999
author_rank: Super Contributor
timestamp: May 27, 2021, 01:54:33 pm
content: Quote from: Moriambar on May 27, 2021, 10:05:09 amDid you find the documens linked below?https://www.ti.com/lit/pdf/swra372&usg=AOvVaw07hrK5qhcqPR5RBU0xUJp7http://ww1.microchip.com/downloads/en/appnotes/00826a.pdfIf you want to be pedantic about getting the right value, it's possible to calculated it.The MCU input pin and parasitic crystal capacitances can be found on the data sheets. It's also possible to calculate the parrasitic, but as mentioned above, an approximate value is good enough for most applications.

author: Moriambar
author_rank: Unknown
timestamp: May 27, 2021, 02:07:15 pm
content: Quote from: Zero999 on May 27, 2021, 01:54:33 pmno I did not find those, well not in the first results... thanks for the links.Anyhow now I have a better grasp of the whole matter, thanks!