ClockWatch User's Guide

< Prev     index     Next >

< Prev       Next >

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,