The software has been continuously calculating the adjustment and keeping track of the RTC seconds count. The count shown is 100251 followed by 100252. In this case, the number in the boxes is the seconds counter. What if the RTC does not have a special prescaler to adjust the timing? This diagram shows another method.įigure 5. The same situation as shown in Figure 4, but without a prescaler However, the technique requires an adjustable prescaler and additional registers to hold the special prescale count and the number of seconds between application of the special count. This technique has the advantage of a small change in the period from second to second. A representation of oscillator cycles counted by a prescaler To compensate for this small error, the software tells the RTC to change the modulus of the prescaler to 32,781 for every fourth second to add some time.įigure 4. The software uses temperature readings and the initial error to determine that the oscillator is running a little fast and 32,768 cycles is actually a period of 0.99990 seconds. The first two seconds are the usual 32,768 cycles. The first diagram (Figure 4) depicts the number of oscillator cycles counted by the prescaler for each period of the seconds counter. Here are two ways to change the timing of an RTC as part of a system to compensate for errors. Fortunately, aging is usually only a few ppm per year. Crystal aging is difficult to compensate for. Keep in mind 1 ppm over a year is about 30 seconds. The yellow band is a reasonable target for accuracy after careful compensation. If the initial error is measured after the circuit board is manufactured and the temperature is known, it is possible to compensate for the largest error sources. The key to compensating for temperature is the fact that the behavior of a crystal is well known and predicted with a quadratic equation. The pink trace shows just the temperature error. The dark blue trace on this graph shows a typical initial tolerance and the change with temperature. The graph below shows several concepts related to RTC accuracy.įigure 3. Graph showing error measurement using temperature used courtesy of Texas Instruments There are three major sources of error from a crystal. An external TCXO can be used for highly accurate timing, or special frequency compensation techniques are used with less expensive crystals and the internal oscillator. In a well-designed crystal oscillator, the major source of error is the crystal. The accuracy of an RTC depends on the 32,768 Hz clock source. This power pin is typically connected to a battery or separate power supply. An RTC will have several possible events to generate a processor interrupt.Īn RTC often has a dedicated power pin to allow operation when the rest of the microcontroller is powered down. A common option is a 1 Hz square wave from an output pin. Some RTCs have specialized counters to keep track of the time of day and the calendar date.Ī basic RTC without time and date counters uses software for this purpose. An external clock source allows the use of a very accurate and stable device such as a TCXO (temperature-compensated crystal oscillator).Ī clock source is selected with a multiplexer and input to a prescaler which divides the clock by a factor of 32,768 (215) to produce a one-second clock.Ī basic RTC has a seconds counter which is usually 32 bits or more. The next diagram shows common hardware features of an RTC.įigure 2. Real-time clock hardware featuresĪn RTC often has its own internal oscillator with an external crystal and an option to use an external frequency reference. Two primary requirements of an RTC are accuracy and continuous operation. Notice the seconds counter runs continuously and does not stop and start. You can see a representation of this in the diagram below.įigure 1. This timing diagram depicts the basic function of an RTCĪlso shown is a program function, A, reading a seconds counter and scheduling an event, B, to occur three seconds in the future. The real-time clock's basic function is to produce intervals of one second and maintain a continuous count. This article describes RTCs inside a microcontroller. There are RTC devices external to a microcontroller which interface with an I 2C or SPI bus. Many of the features of an RTC are very specialized and required for maintaining high accuracy and very reliable operation. In addition, an RTC is often used to keep track of clock time and calendar date either in software or hardware. Real-time clocks (RTC) are timers dedicated to maintaining a one-second timebase. The first article describes the major features of most types of timers and covers periodic timers, and the second covers pulse width modulation MCU timers. This article is the third of a series on microcontroller timers.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |