|
What Causes Clock Drift?
The Clocks Inside Your PC Two time-of-day clocks reside in every AT-compatible computer. These clocks go by several different names, but for simplicity, we'll call them the software and hardware clocks. The software clock runs only when the computer is turned on. It stops when the computer is turned off. The hardware clock uses a battery and runs even while the computer is turned off.
Every computer that runs DOS or Windows has a built-in software clock. On PC or XT-compatibles, the Intel 8253 timer-counter chip or an equivalent device drives this clock. AT-compatible computers use a device equivalent to an Intel 8254 timer-counter. The timer-counter is programmed by the BIOS to generate an interrupt every 54.936 milliseconds, or about 18.206 times per second. Another BIOS routine counts the interrupt requests and generates a time-of-day clock that can be read or set by other software programs. For example, Windows uses the information from the software clock when it date and time stamps files.
The software clock is useful, but it has several limitations. First, the software clock is a poor timekeeper. Its accuracy is limited by the stability of the interrupt requests. Any change in the interrupt request rate causes the clock to gain or lose time. If you leave your computer turned on for long periods, the software clock might be off by large amounts, perhaps a minute or more for every day that the computer was left turned on. It's also possible for an ill-behaved software program to use the timer-counter for another purpose and change its interrupt rate. This could cause the clock to rapidly gain or lose time.
Another problem with the software clock is that it cannot display all possible time-of-day values. The resolution of the clock is limited to the interval between interrupts, or about 55 milliseconds as stated earlier. Only times that are even multiples of this interval can be displayed. For example, 00:00:01.00 could never be displayed by the software clock. The closest possible values it can display are 00:00:00.98 and 00:00:01.04.
The single biggest limitation of the software clock, however, is that when the computer is turned off the clock stops running. On the original IBM-PC, this meant that you manually had to set the clock each time you turned the computer on. You could purchase an optional battery-backed clock for the PC, but there were several different standards, and not all of them worked with all software packages. This problem was addressed with the introduction of the IBM-AT in 1984, which included a battery-backed hardware clock as standard equipment. An AT-compatible hardware clock is included with every X86 computer produced today.
The hardware clock is based on the Motorola 146818 Real Time Clock Chip, or a functionally equivalent device. The clock is supported by the AT BIOS, and BIOS services are available that let software programs read and set the clock.
The hardware clock is a CMOS device that consumes very little power. When the computer is turned off, it runs on batteries. When the computer is turned back on, the software clock starts running again and sets itself (within 1 second) to the hardware clock. Although the two clocks are synchronized at start-up, they may run at very different rates and will probably gain or lose time relative to each other while the computer is running.
The hardware clock is updated once per second and cannot display fractions of a second. For this reason, it cannot be read or set within better than a second. The accuracy of the hardware clock is determined by the quality of its time base oscillator (typically a 32.768 kHz crystal). These crystals are economical, costing less than $1 in single quantities. However, they offer only marginal time keeping performance. They are sensitive to temperature and other factors and are often not calibrated at the factory. Even under the best conditions, these oscillators are not likely to be stable to better than 1 part per million (about 0.1 seconds per day). In actual operation, most hardware clocks seem to gain or lose time at a rate of about 1 to 15 seconds per day, with 5 or 6 seconds per day being typical. Although the
hardware clock usually outperforms the software clock by a considerable amount, its performance often pales in comparison to even a low-cost wristwatch.
As you can tell by now, neither the software or hardware clock is suitable for accurate time keeping. Fortunately, however, there are several ways you can keep accurate time on your PC if your application demands it.
Prepared by the NIST -Boulder, CO
|
|