You are here

Calculating Clock Error for a Crystal

Overview
A quick look at calculating frequency error for a crystal used as an oscillator.

Sources of Error
Datasheets will list the three (3) most important sources of clock error. They are listed in ppm:

  • Process: crystals are cut and ground to very precise dimensions, but there are limits; it is permanent
  • Temperature: crystals have an error associated with temperature; it is not linear; it is not permanent
  • Aging: crystals will permanently alter their value slightly over time; it is permanent and not recoverable

There is also what is called a 'pulling' error. This is caused by the loading capacitors used in this type of application. The additional loading caused by the capacitance will shift the clock frequency slightly. It is characterized in ppm/pF.

How to use PPM
ppm is an acronym for "parts per million". More correctly it stands for "number (parts) of things A" per "one million of thing B". So 1200ppm of Sodium in a glass of water means there are 1200 Sodium atoms per million water molecules. It is a relative relationship and it has nothing to do with volume, mass or weight. Simply count.

To know the absolute number of "thing A", you must know the quantity of "thing B". For example if you have 1e9 water molecules, which is the same as 1000 million water molecules you know that there are 1200*1000 = 1,200,000 Sodium atoms in that water.

The formula looks like this:

total count = (# ppm) * (# base) / 1e6

The same is true for clocks. So if you have a 20ppm clock, and the frequency is 24MHz, then you know the error is 24*20e6/1e6=480Hz. Clocks can be positive or negative, so the actual error is +/-480Hz.

MCU/CPU Clocks
When implementing clocks for a CPU or MCU there are two types of clock error you want to be aware of: a) real time clock (RTC) error and b) high speed clock error.

High speed clock error will have a multiplicative effect on downstream IP blocks. For example you might have a USB3.x bus which is multiplied up from the high speed clock. Any error on the high speed clock is also multiplied up. That error must be less than the allowable error for that bus. This type of error can also show up in radios, where the transmit frequency is usually much higher (e.g. 2.4GHz) than the crystal.

Real time clocks work by counting cycles from a 32,768Hz crystal. Exactly 32,768 counts equals 1 second. So any error on this clock will show up as an error in the clock. This is particularly important when you need accurate time stamping or accurate timing of events.

Clock Error
Let's look closer at an RTC clock implementation. Let's say we have selected a crystal with a total error (process, temp range and lifespan in years) of 50ppm. The RTC clock runs at 32,768Hz. We would like to know the total error in time as well as frequency. First we calculate frequency error, then derive time error.

Relative error:

df=f*ppm/1e6=32,768Hz*50ppm/1e6=1.6384Hz

Total error:

f_abs=f +/- df=32,768 +/- 1.6384Hz
f_min=32,768-1.6384=32,769.6384Hz
f_max=32,768+1.6384=32,766.3616Hz

To know the time error we convert the min/max frequency to cycle time and multiply by the number of cycles. Remember that the MCU assumes that 32,768cycles=1second. What we calculate below is the amount of time that has actually passed:

T=(cycle_time)*(#cycles)=(1/f)*(#cycles)
T_min=(1/f_max)*32,768=0.999950s
T_max=(1/f_min)*32,768=1.000050s

Often cumulative daily error (ie drift per solar day) is the error we are particularly interested in:

(t_max-t_nom)*seconds_per_day=daily_error 4.32s