!!! Mediawiki has been upgraded !!! Slack integration has been disabled for now due to an incompatibility. If you want to testdrive the new skin (Tweeki), make sure your language settings are set to 'en - English' in your preferences!
Load Capacitor Calculation for Oscilators
When using microprocessors, you will use most of the time an external oscilator to provide the clockspeed of the processor.
This page assumes you are using quartz crystals in "parallel resonance"-mode and not another kind of resonator like a ceramic resonator or other kind of oscilator setup. (This page covers about 99.9% of all hobby-projects.)
Besides the quartz crystal of the chosen frequency, you will also need so-called "load capacitors" in order to have a functioning clocksignal.
Resonator or Oscilator?
Let's start by confusing you: What most people call an oscilator is most of the time actually a resonator.
A resonator needs 2 load capacitors in order to make it oscilate. This combination of 2 capacitors and 1 resonator is called an oscilator and connects to the oscilator pins of your microprocessor.
An actual oscilator has all these required components into one housing.
To know the difference:
- A resonator has only 2 pins.
- A oscilator has 3 or 4 pins.
Most of the time you will be using resonators.
The crystal inside the resonator doesn't really vibrate at the exact specified frequency. It can even vibrate in different directions at the same time! Because all these vibrations have different frequencies, and there is this thing called "harmonics", we need to filter out the frequencies we don't want or our processor will not work as intended.
Luckely for us, a capacitor (and/or inductors) makes a good frequency filter. The "load capacitors" used with the crystal actually attenuate the unwanted frequencies, and let the "right" frequency pass through.
Calculation of capacitance
Every resonator has a capacitance of its own. This is most of the time mentioned on the crystal, together with its frequency. This is the crystal's own "load" capacitance. We call this CCrystal.
Furthermore, the PCB traces (or wires on a breadboard) and microprocessor pins also have a specific capacitance. You can measure it, but that would be overkill in "hobby" projects. You can safely assume this "stray" capacitance (CStray) is between 2pF and 5pF. (Near 2pF for PCBs with a recommended layout, near 5pF for breadboards. Badly designed PCBs can have an even higher stray capacitance.)
(Please note: The stray capacitance will vary with frequency, so if you measure it, it best to measure it at the intended frequency.)
In a parallel resonant oscilator circuit, the following holds true:
Because we will keep C1 and C2 the same, we can transform this formula to something much simpler:
So, depending on the capacitance of the resonator, you can now calculate what capacitors you should use!
Recomended PCB layout
Always consult the datasheet of your microprocessor!!!
You will find something like this with alongside some text describing the limitations and other important bits.
Is the capacitance value critical?
If you want a working oscilator circuit: No, it is not critical.
Choose something in the neighbourhood. It will not be perfect, but good enough.
If you want to do calculations based on oscilator clock: Yes, because the value of the external load capacitors will change the frequency of the resonator.
You can mitigate this requirement by buying an "oscilator" instead of a resonator, but an oscilator tuned exactly to a specific frequency will cost you some money. You can also use a variable capacitor to tune the oscilator to a very specific frequency. (For RF circuits.)
For time-critical applications, most of the time the circuit is just built and afterwards the processor speed measured against an external, known, timesource.
The software is built with a "tuning"-variable to compensate for any difference in clock frequency.
Another possibility is writing auto-syncing software, ex: by using the 50Hz from the electricity network as a timebase. (Mostly used with dimmer circuits.)
If the value of the external load capacitors is way off, your oscilator will not "tick" or the microprocessor will behave erratically.
What kind of capacitors should I use?
Do not use electrolytic capacitors, they will not work.
Always use ceramic capacitors in an oscilator circuit.
This sounds really fun, I want to know it all!
Good starting points to quench your thrist for knowledge are:
Actually this wasn't a "frequently asked question"... ;-)