The 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: mechanical resonance(crystals and ceramic resonators) and RC (resistor, capacitor) oscillators.
The most popular form of mechanical resonant generators in microcontrollers is Pierce oscillators:
Ceramic and crystal-based generators provide very high accuracy and low-temperature coefficient. But they have a 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, which 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 the oscillator and keep it all-time at a 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 lose stability with the age.
To reduce the vibration effect, you may choose to use ceramic resonators. They may not be damaged by vibrations as crystals can, but they have much lower stability- typically ±500ppm which means about 50 minutes/week.