circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

November 2004, Issue 172

Test Your EQ

Answer 6—Set up the processor’s counter/timer to free run, clocked by the processor clock. Connect the synchronization signal to an external interrupt of the processor. Every time the interrupt fires, take a snapshot of the counter/timer value. In software, keep a queue of these snapshots that’s at least 200 entries deep.

Each time you take a snapshot, scan through the queue to find the entry that’s closest to being one second old. For example, suppose the processor clock is 10 MHz ±100 ppm (±1 kHz). If the current snapshot value is N, there will be a previous entry in the queue that has a value somewhere in the range of N – 9,999,000 to N – 10,001,000.

The number of entries back in the queue in which this older snapshot lies tells you the frequency of the external reference signal. Furthermore, the exact difference between this entry and the current snapshot tells you exactly what the average frequency of the processor clock was over the past 1-s interval. Because crystal oscillators usually have good short-term stability, you can use this value to interpolate time values over the next one-second interval.

For example, suppose the exact difference is 10,000,487 counts. If you measure the difference in time between two external events to be 100,000 processor clock periods, you know that the actual time is the following:

 

It doesn’t matter what the absolute accuracy of the processor clock is as long as it doesn’t change by more than 0.1 ppm in 1 s. All time interval measurements will have the basic accuracy of the external reference, plus the peak-to-peak jitter of the processor clock period.

 

Contributor: David Tweed

   

E-mail eq@circuitcellar.com with questions or comments.

Back to Questions