0

I would like to do precise timing of events which trigger hardware interrupts on a microcontroller. I am aware of the stability issues associated with microcontroller oscillators and I think a 30ppm (or smaller) stability in 50 MHz (or greater) oscillator will be good enough for my project. But an oscillator can be very stable and yet be inaccurate as a time keeper because the frequency of oscillator may not be what one thinks it is. So my question is: How does one go about calibrating the external oscillator of a microcontroller board?

Thank you!

D_J_S
  • 39
  • 6

4 Answers4

2

If you are willing to do the measurement over a period of time (one midnight to the next), the frequency of the US power grid is maintained to exactly 60 Hz over a 24-hour period as discussed here. The frequency will vary during the day, but it is trimmed at the end of the day so that exactly 5,184,000 (60*60*60*24) cycles will occur from one midnight to the next.

To count this, you will need a zero-crossing detector. There are many such circuits on the web, here's a fairly simple one:

enter image description here

Count up how many cycles your clock is putting out in 24 hours (perhaps after going through a divider), and then compare those counts with the counts off the power lines.

Run this the first time and it will give you the frequency. Run it another day and it will give you the drift.

tcrosley
  • 47,708
  • 5
  • 97
  • 161
  • Right, and also the power grid(s) in Europe are calibrated to be exactly 50 Hz over a 24-hour period. During daytime it's allowed to slow down a bit because the loads are high; at nighttime it's run a bit faster to compensate for the daytime. The reason is that there's a plethora of different tariff clocks/grid control gizmos/whatever devices in the grid, that take their timing reference from the grid's frequency and this way they keep their time for extended periods of time. – PkP Nov 06 '14 at 16:36
1

Let me expand a bit on tcrosley's excellent answer from yesterday. Let's define first how accurate you wish to be. You say 30 ppm, so that means more accurate than two seconds (exactly 2.592 seconds) drift per 24 hours.

You could follow tcrosley's idea of locking on to the power grid. And with it, you could do continual adjustment of the device if it's continuously connected to the grid.

There's a couple of other alternatives. You could use GPS time. There's an excellent article "The Science of Timekeeping", which is Hewlett-Packard's Application Note 1289 and by quick googling, it's available for example here. Did you know that Hewlett-Packard started by doing oscillators and frequency counters?

Using the atomic clock provided by GPS might be easier than you think. Your computer might already use NTP protocol to keeping its time in sync with UTC. If not, you can install a NTP client to your computer. NTP servers generally derive their time from GPS atomic clocks and in any case the accuracy is way better than 2 seconds per day. So calibrating (checking) the speed of the microcontroller's oscillator might be as simple as sending the microcontroller's "time" periodically to a PC and writing a small PC application to display the time and compare that to the PC's NTP corrected time.

PkP
  • 7,567
  • 2
  • 23
  • 42
  • Thank you very much for the link to the "Science of Timekeeping" article. And I will consider GPS. – D_J_S Nov 06 '14 at 20:42
0

The most standard way to characterize and calibrate self-made oscillators is to use proper calibration instruments, like frequency counters with a stable time base (say, Rubidium clock). Example of affordable tool is Stanford Research SR625 Frequency Counter. The tool is accurate to 0.1ppb (part per Billion), if I calculated this correctly. The price tag is just $7k, but you can rent it for a lot less.

Ale..chenski
  • 38,845
  • 3
  • 38
  • 103
-1

U can use DFLL(Digital frequency locked loop) with RTC clock or any external cheap crystals with less ppm, given as input to the DFLL, to calibrate the microcontroller. From my personal experience, Atmel's ATXMega series would give u variety of controllers with reliable internal oscillator.

There is also a PLL inside some micro-controllers. U can connect a one second accurate clock (a RTC clock) and multiply it with a factor of 1-31, so that to get an accurate system clock

Atmel XMega:

  1. In-built DFLL circuitry.
  2. In-built PLL circuitry.
  3. Factory calibrated internal 2MHz oscillator.
  4. Factory calibrated internal 32.768 KHz RTC oscillator.
  5. 32MHz run-time calibrated and tuneable oscillator

For calibrating the clock source refer this datasheet. U can get some ideas by clicking here

gzix
  • 403
  • 9
  • 22
  • I was thinking of using the TI Hercules Launchpad and it's external oscillator in this project. I don't think any internal oscillator (crystal or RC) on a commercial uCon can do better than the accuracy of the oscillator I am trying to calibrate. Am I wrong? I am newbie. – D_J_S Nov 05 '14 at 19:49
  • @D_J_S External oscillator will always do better than internal oscillators. There is a trade-off between reliability and accuracy. U can rely on internal osc but for high accuracy u go for external oscillator. For cost effective solution and high accuracy, u can use external RTC 32.768 KHz and internal PLL multiplier. [RTC crystals](http://www.digikey.com/product-search/en?FV=fff4000d%2Cfff8016d%2C22c0060&k=crystals&mnonly=0&newproducts=0&ColumnSort=1000011&page=1&stock=0&pbfree=0&rohs=0&quantity=&ptm=0&fid=0&pageSize=25) – gzix Nov 06 '14 at 01:19