Choice of the microcontroller oscillator depends on many factors. Before choosing one, you should consider Cost, accuracy and environmental parameters. Clock sources can be grouped into two major groups: based on mechanical resonance(crystals and ceramic resonators) and RC (resistor, capacitor) oscillators.
A most popular form of mechanical resonant generators in microcontrollers are Pierce oscillators:
Ceramic and crystal based generators provide very high accuracy and low-temperature coefficient. But they have slower startup comparing to RC generators. But the RC generator’s precision suffers from temperature variations and supply voltage. Nominal frequency can variate from 5% to 50%:
Oscillator stability can be expressed in figures as ±20ppm’ which means 20 parts per million. How to understand this? Imagine that there are 32 million seconds per year. Then in every million seconds generator may miss 20 seconds. SO over a year generator will lose 32×20 seconds, what is around 10 minutes. Standard crystals are rated from Â±10ppm to Â±100ppm what means from 5 to 50 minutes a year.
For better stability, you need to calibrate oscillator and keep it all time in constant temperature like in the fridge. But it is not practical. There is another option – Temperature Compensated Crystal Oscillators (TCXO). These oscillators in their package include circuitry that is responsible for temperature compensation. Such devices can provide stability to up to ±0.1ppm, which means around 1 minute every 20 years. But…these crystals are expensive (can be about 100$ cost).
You don’t always have to buy TCXO – sometimes you may add a temperature sensor and adjust timing according to temperature.
Other disadvantages of crystals are that they are susceptible to vibrations and they loose stability with the age.
To reduce vibration affect, you may chose to use ceramic resonators. They may not be damaged by vibrations as crystals can, but they have much lower stability- typically ±500ppm what means about 50 minutes/week.