DS1994 Memory/Time iButton
Techniques for Accurate Time Measurement with the Dallas Semiconductor DS1994 Memory/Time iButton
I. Historical BackgroundThe first requirement for accuracy in time measurement arose from the need to determine longitude at sea from celestial measurements. Because of the earth's rotation, a time measurement error of 4 seconds creates a longitude error of 1 arc minute, or about 1 mile at latitudes near 30 degrees. To determine a ship's position to within a mile, it was essential to have a good sextant and a chronometer capable of giving the correct time to within 4 seconds, even after many days at sea.
The first navigational chronometers to provide the needed accuracy were precision mechanical devices. These instruments did not provide an accurate time reading directly. Instead, a chronometer was carefully characterized on land to determine exactly how fast or slow it was and how the error depended on temperature and other environmental factors. Each chronometer was supplied with its own unique set of characterization data which could be used at sea to calculate the correct time from the uncorrected time supplied by the instrument.
A modern, cheap quartz digital wristwatch is now superior to the best early navigational chronometers. With careful characterization and corrective calculation, it is possible to obtain a high degree of accuracy from a modern quartz timepiece. For practical reasons, the correction calculations that were so important for early chronometry are seldom performed with modern timepieces. As a result, a wristwatch, PC clock, or other quartz timepiece may gain or lose a second or more per day in its uncorrected reading. A properly executed corrective calculation can reduce this error substantially. Microprocessors and microcontrollers can now perform this calculation with relative ease, allowing a microprocessorcontrolled timekeeping device to achieve a dramatic increase in accuracy.
II. Sources of Timekeeping ErrorThe sources of error in a quartz crystal controlled timepiece are listed below:
A. Temperature DependenceThe oscillation frequency of a quartz oscillator depends on temperature. A typical 32.768kHz wristwatch crystal has a frequency which depends quadratically on temperature, with the maximum frequency occurring near "room" temperature (25°C).
B. Calibration ErrorThe oscillation frequency of a quartz oscillator depends to a degree on the values of the circuit components that comprise the oscillation circuit. Calibration error is the error in adjusting (trimming) the circuit components at the factory which causes the maximum frequency described in II.A above to be greater or less than the intended value.
C. Relaxation with TimeThe manufacturing process induces mechanical stresses in the quartz crystal which affect its oscillation frequency. These stresses spontaneously relax during the lifetime of the crystal, resulting in a slow, longterm change in frequency.
D. Shock HistoryA severe mechanical shock can suddenly relax existing stresses in the quartz crystal or induce new stresses. This results in a step function change in the crystal frequency, followed by subsequent relaxation of the new stress pattern over time.
Changes in oscillation frequency caused by relaxation with time and shock history are not predictable and therefore not subject to automated correction. However, a recalibration performed after the change in frequency has occurred can eliminate these effects until they occur again. The two most important effects on practical timekeeping accuracy are therefore the temperature dependence of the oscillation frequency and the factory calibration error.
Temperature effects may vary widely in significance depending on the environment. A wristwatch worn continuously is exposed to a temperature environment which is very nearly constant. In this case, the observed error is due almost entirely to calibration error. Even if a watch is left on the dresser at night, it still experiences a daily average temperature environment which is very nearly constant from one day to the next. On the other hand, a timekeeper exposed to daily and seasonal extremes of outdoor temperature would be expected to exhibit substantially larger temperature effects.
In principle, the calibration error can be made arbitrarily small. However, in a manufacturing environment, it is impractical to calibrate very precisely for several reasons. Watches have mechanical adjustments for trimming the oscillator which have backlash and creep that limit the precision with which they can be set. A more important factor is that very exact calibration requires a long period of time to perform because the timekeeper requires time to accumulate a measurable error. As a result, watches and crystal controlled timekeepers used indoors are limited almost exclusively by the imprecision of their calibration.
III. Correction of Timekeeping ErrorAs noted above, the principal limitation on the accuracy of an indoor, crystal-controlled timekeeper is the precision of its factory calibration. Like the early navigational chronometer, the device is capable of measuring time very accurately but does not display the accurate time directly. To achieve the desired accuracy, it is necessary to determine the correction coefficients and then to perform a corrective calculation to determine the corrected time. This correction takes the following form:
Corrected Time = Uncorrected Time + (Uncorrected Time - A) / B
In the above equation, the values A and B are the correction coefficients that are obtained by characterization. To set the timekeeper and determine the values of A and B, the following steps are required:
- At an initial time T1, synchronize the timekeeper with a highly accurate time standard. The National Institute of Standards and Technology (NIST) provides both a radio service (WWV at 5 MHz, 10 MHz, and 15 MHz) and a 9600 bps modem line (303-494-4774) for this purpose. Set the coefficient A equal to the time T1.
- Wait a long period of time to allow the error in the uncorrected time to build up. Good results can be obtained with a delay of several days to a week, but the longer the delay time, the better. During the long delay time, the timekeeper should be exposed to the average temperature environment in which it will later be used.
- At a later time T2 provided by the highly accurate time standard, read the uncorrected time T from the timekeeper and solve the following equation for the coefficient B.
Now that the coefficients A and B have been determined, the corrected time can be computed from any uncorrected time measurement by applying the correction equation using the values of A and B obtained from the characterization. Note that the value of B may be positive or negative, depending on whether the timekeeper runs slow or fast respectively. It should also be noted that the value of B can be regarded as a large whole number (signed integer).
The correction described above, while simple in principle, is complicated by the fact that the practical units of time (years, months, days, hours, minutes, seconds) are related in a complicated way. To determine T - T1, for example, it is necessary to find the total number of seconds between the date and time represented by T1 and the date and time represented by T. To facilitate the corrective calculation, it is highly desirable that the timekeeper measure time in a single standard unit (e.g., seconds). One such standard is that of the UNIX operating system, in which time is kept as the total number of seconds that have elapsed since the beginning of January 1, 1970. Using this standard, the corrective calculations are easily performed with long integer arithmetic.
IV. Memory/Time iButtonThe DS1994 Memory/Time iButton manufactured by Dallas Semiconductor is a small, sealed, internally powered timekeeping unit with 512 bytes of nonvolatile RAM memory and numerous specialized timekeeping features. Data transfer to and from the DS1994 is accomplished over a single serial data wire using the Dallas Semiconductor 1-Wire® protocols for data communication. The DS1994 has several characteristics which make it especially suitable for the type of corrective calculation described above:
- The DS1994 accumulates date/time information in a 5-byte register as the number of 256ths of a second since some arbitrary reference date. (For compatibility with the UNIX operating system, use of the reference date January 1, 1970 is recommended.) This date/time format is ideal for performing the corrective calculation described above and also makes it easy to determine the day of the week. After the correction has been applied, the corrected date and time can be converted easily to the more standard form (MM/DD/YYYY, HH:MM:SS).
- The correction coefficients A and B can be stored in the nonvolatile RAM memory of the DS1994. This modularity provides a manufacturing advantage because the DS1994 can be characterized and loaded with its A and B coefficients and then used later as a component for assembling the final timekeeping product. It is not necessary to tie up the entire product for the relatively long times needed to perform an accurate characterization of the DS1994. This modularity also facilitates repair or replacement.
- The oscillation frequency of the DS1994 is fixed at the factory. The fixed-frequency circuit offers long-term stability that is superior to that of mechanically trimmed components because it is free of mechanical relaxation effects in the trim adjustment.
- Because of the 1-Wire interface, the DS1994 may easily be located at some distance from the rest of the product. This is significant when the product itself generates heat that may affect the accuracy of the timekeeper. (For applications requiring extreme accuracy, in which the timekeeper itself is kept in a constant temperature oven, the packaging and 1-Wire interface of the DS1994 simplify product design.)
V. Programs to Calculate Corrected TimeDallas Semiconductor has developed a demonstration program for the DS5000 (Intel 8051 compatible micro-controller) which calculates the corrected time from a characterized DS1994 and displays the results on an LCD display. Using this program and a properly characterized DS1994 with A and B coefficients stored in its nonvolatile memory, accuracies of 1 second in six months have been observed indoors over a two-month period. PC programs to characterize DS1994s and compute and store the correction coefficients have also been developed. The PC programs communicate with the DS1994s using the DS9097 COM Port Adapter and DS9092 iButton Probe. The adapter and probe attach to any RS232C serial port of the PC, and the PC reads and writes data to the DS1994 simply by touching it with the probe. The programs in this demonstration set are described below.
A. SetTimeThis is a PC program which performs the calibration step described in section III.1. T1 is obtained from the DOS clock of the PC. Since PCs typically have poor timekeeping accuracy, it is necessary first to synchronize the PC clock with the NIST standard so that it can be used as a secondary time standard. (This synchronization can be performed with a 9600 or faster bps telephone modem and the MS DOS utility program TIMESET, available from Life Sciences Software, P.O. Box 587, Stanwood, Washington 98292, phone 360-387-9788. A similar program, WTIME, is available as a free utility for Microsoft Windows from PC Magazine, October 27, 1992.) To set the DS1994 time and the first correction coefficient A, type
SETTIME <com port number> <time zone offset>
at the DOS prompt and then touch the DS1994 with the probe. <com port number> is the number of the COM port to which the DS9097 adapter is attached. <time zone offset> is the number of hours of offset required, and is entered as -1 if the PC is set to daylight savings time. The program sets the time register and the A coefficient in the DS1994, responds with "Date and Time Successfully Set" and terminates.
B. CalTimeThis is a PC program which performs the calibration step described in section III.3. Before using the program CalTime, the DS1994s should be allowed to remain for several days or weeks in the typical environment in which they will be used. T2 is obtained from the DOS clock of the PC. Again, it is necessary first to synchronize the PC clock with the NIST standard so that it can be used as a secondary standard. To compute and set the second correction coefficient B, type
CALTIME <com port number> <time zone offset>
at the DOS prompt and then touch the DS1994 with the probe. The program sets the B coefficient in the DS1994, responds with "Date and Time Successfully Calibrated" and terminates.
C. LCDTimeThis is a program for the DS5000 microcontroller which reads the time and correction coefficients from a DS1994, computes the correction, and displays the corrected time, date, day of the week, and daylight/standard time indicator on an attached LCD display. (To avoid the problem of daylight savings time, the program reads standard time from the DS1994 and automatically converts it to daylight time when daylight time is in effect.) The program is written in KSC Pascal, and the Hitachi LCD controller is attached to the DS5000 in the manner recommended by KSC, with the base address changed from 6000 hex to 0000 hex. The program can be compiled with the SYSTEM51 (Ver 3.10) software development system from KSC Software Systems, Ludvig Holsteins Alle 137, DK-2750 Ballerup, Denmark, Phone (Int. 45) 44 97 69 11, Fax (Int. 45) 44 97 96 12.
D. ReadTimeThis is a PC program which reads a DS1994 using the serial port adapter and displays corrected and uncorrected time values, calibration constants, and measurement errors. To read the DS1994 and display these results, type
READTIME <com port number> <time zone offset>
at the DOS prompt and then touch the DS1994 with the probe. The program displays the uncorrected date and time, the corrected date and time, the difference in seconds between the corrected and uncorrected times, the values of the correction coefficients A and B, the current DOS time, and the difference in seconds between the corrected time and the current DOS time.
Note that in all of the above programs, the values of A and B are stored in the unused Real Time Alarm and Interval Time Alarm registers in the "clock page" of the DS1994. This was done so that the 512 bytes of nonvolatile RAM memory could be kept free for other possible uses. The values of A and B can be independently reset at any time in the future with the SetTime and CalTime programs respectively.
VI. Tests of the Calibration ProcessTo investigate the effectiveness of the calibration process, a set of 50 DS1994s was divided into five groups of 10 parts each. The first calibration point was set with SetTime for all parts at 11:50 a.m. Central Standard Time on July 14, 1992. Each of the five groups, designated A, B, C, D, and E, were recalibrated after different periods of time. The second calibration point was set with CalTime for the various groups as follows:
Group A at 11:50 a.m. CST on July 16, 1992. Group B at 9:30 a.m. CST on July 22, 1992. Group C at 3:40 p.m. CST on July 29, 1992. Group D at 9:10 a.m. CST on August 3, 1992. Group E at 7:35 a.m. CST on August 13, 1992.
When the parts were not being read or calibrated, they remained in a desk drawer in an air-conditioned office environment. On September 15, 1992, at 11:50 a.m. CST, all parts were read with ReadTime and the errors in the corrected times were tabulated in seconds as shown in the table below:
|Part #||Group A||Group B||Group C||Group D||Group E|
Days Cal. in the table above indicates the number of days between the first and second calibration points, and Days Idle represents the number of days after the second calibration point before the final reading was taken on September 15.
Note that the corrected times marked with asterisks represent errors of less than 2 seconds per year. The parts calibrated for shorter times show larger errors and larger standard deviations, indicating the effects of end-point calibration inaccuracy and short-term temperature fluctuations. (By comparison, the uncorrected times from the 50 DS1994s showed a mean error of 526 seconds/year, with a standard deviation of 210 seconds/year.)
A final measurement was made on July 14, 1993 at 11:50 a.m., one year after the initial setting. The uncorrected times showed a mean error of 550.6 seconds with a standard deviation of 207.8 seconds, consistent with the two-month measurement cited above. In parts per million (ppm), this is 17.5 ppm ± 6.6 ppm. The mean errors in the corrected times for the five groups were as follows:
|Group A:||26.83 sec ± 6.81 sec||(0.85 ppm ± 0.22 ppm)|
|Group B:||22.91 sec ± 6.94 sec||(0.73 ppm ± 0.22 ppm)|
|Group C:||18.30 sec ± 3.83 sec||(0.58 ppm ± 0.12 ppm)|
|Group D:||15.48 sec ± 2.81 sec||(0.49 ppm ± 0.09 ppm)|
|Group E:||15.94 sec ± 3.70 sec||(0.51 ppm ± 0.12 ppm)|
While not as accurate as the measurements made over the two-month period, these accuracies are still impressive. The deviations in the corrected readings are all in the same direction, indicating a possible seasonal change in the temperature of the environment in which the parts were stored. As expected, the group having the shortest calibration period (Group A) had the greatest error. The average error in the corrected readings of groups D and E is 35 times smaller than the average error in the uncorrected readings.
VII. SummarySignificant improvement of timekeeping accuracy can be achieved by using a real time clock with supplemental nonvolatile SRAM for the storage of calibration constants. Whenever the timekeeper is reset, improved calibration constants can be stored in the nonvolatile SRAM, so that successive resets adaptively enhance accuracy. When the timekeeper is read, these constants are supplied along with the uncorrected time-base to a microprocessor program that calculates and displays a more accurate reading. If the timekeeper maintains time by counting the seconds from a designated reference time then a simple program code can quickly compute a more accurate, compensated time. In this way the practical effect of errors from temperature, initial calibration, quartz aging, and shock history can be minimized. Experimental data indicate that an accuracy of ± 2 seconds per year is achievable over a two-month period, and approximately 16 seconds over a full year. To obtain copies of the programs described above, further information on the demonstration circuit, and information on how to obtain components, contact Dallas Semiconductor (972) 371-6824 or open a support request at http://support.maximintegrated.com/ibutton.
The DS1994 and DS2404 are no longer recommended for new designs.