??? 03/10/04 12:06 Read: times |
#66414 - RE: Crystal accuracy- Patrick Responding to: ???'s previous message |
The only way to determine timing accuracy of a microcontroller crystal is to compare its frequency against some standard. Here are some ideas that could be used:
First off, knowing that a timer channel runs in direct relation to the crystal oscillator, setup a timer 2 type channel so that it supports Auto-Reload and interrupts once per millisecond. Adjust your reload value to get exactly 0.5 msec (if your nominal crystal frequency permits this) otherwise aim for a known period computed on paper out to the resolution proported by your crystal at nominal label frequency. In the ISR have a port pin get toggled each interrupt. (It is actually best if you have a timer 2 that supports the output T2 pin toggle at the time of roll-over then use that instead of software in the ISR). OK for the measurement techniques. 1) Use a calibrated instrument to see if the output pin is running at 1 KHz or not. The amount of difference from 1 KHz is your error. 2) In the ISR program up a 4 or 6 byte counter (32 or 48 bits total) function that is incremented every other timer interrupt. Start the program with the counter at zero at a known time and let it run for a precise duration of time. At the end of the time look at the count and compare it to what it should have been if the timer output was at the exact timing per the duration time you used. The longer the duration the more resolution you have to work with for accuracy check. This is due to the fact that some error is introduced from the fact that the timer interrupt is asyncronous with the known duration start to stop time. THis process can be run for multiple days to gain very high resolution. 3) An external "counter" instrument can be used to count the pulses from the timer output pin as opposed to doing it in the ISR. To count over 1 day you need a counter with at least 8 decimal digits (10 digit counter preferrable). You can coordinate the start stop time over several days to gain lots of resolution. Accuracy of the gate time needs to be at least better than one order of magnitude better than the resolution of the acccuracy you are trying to measure. Michael Karas |