Internet Explorer is not a supported browser for TI.com. For the best experience, please use a different browser.
Video Player is loading.
Current Time 0:00
Duration 9:09
Loaded: 1.82%
Stream Type LIVE
Remaining Time 9:09
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected

[AUDIO LOGO]

Hello, and welcome to Introduction to Real Time Clocks. In this video, we will be discussing what a real time clock is, as well as applications and considerations for using one. So what is a real time clock? A Real Time Clock, often abbreviated as RTC, is an accurate timekeeping reference that enables the system to keep track of time and date in human readable formats.

There are many applications that depend on having a reliable time reference. For example, a thermostat needs to be able to change the temperature set point on a precise schedule. Applications that log information may need to record time and date for a log entry. Or a water meter may collect water usage information on a monthly interval. These applications and many more depend on having an accurate source of time.

Before we talk about the details of RTCs, it is helpful to understand alternative approaches for keeping track of time. The simplest way to schedule operations in an application is to use a software delay. Software delays force the CPU to perform a predetermined amount of no operations, or no ops, which creates a gap in the program's execution. While this approach may be simple and useful in prototyping, it is not a good solution because it is inaccurate and wastes power.

A better solution is to use a hardware timer. Hardware timers are accurate and don't require the CPU. If your application needs to schedule an operation on a short interval, then a hardware timer is a good choice. However, if your application needs to schedule an operation on a daily or weekly interval, hardware timers can become cumbersome because they lack calendar features.

The best solution is to use an RTC. An RTC is a timer that stores the date and time in formats that are easy to manipulate and code. Operations that need to be scheduled on an hourly, daily, or weekly interval are simple to configure thanks to the RTCs calendar and date features. RTCs will also offer error compensation features to ensure accurate timekeeping.

It is worth noting that RTCs can be integrated directly in the MCU, or it can be external devices. Integrated RTCs offer low cost and simple configuration, whereas external RTCs offer a wide array of features at the expense of cost and complexity. In this video, we will primarily be discussing integrated RTCs. But almost all concepts apply to both integrated and external RTCs.

This diagram shows a typical block diagram of an integrated RTC. In the rest of this video, we will give an overview of how all these subsystems work in the context of an MCU. One of the main features that separates RTCs from general purpose timers is the calendar functionality. An RTC has the ability to store the current date and time in a format that is readable to humans.

If you look at the sample configuration code on the right, you'll notice that the current year is stored as hex 2022. This is known as binary coded decimal. It may seem like an odd choice because hex 2022 does not, in fact, equal 2022 in decimal. However, this format presents an advantage when converting date and time to an Ascii or text representation.

If the date/time field were stored as a binary representation, the application would have to perform a conversion from binary to Ascii. To convert a BCD value to its textual representation, the application can simply separate the field into 4-bit sections, each of which corresponds to a digit. In our example, hex 2022 can be easily decomposed into 2, 0, 2, and 2.

To demonstrate the use of this functionality, let's take a time stamping example. Perhaps your device needs to log a time when a door is opened. The life cycle of this application can be broken down into a couple operations. When the application detects a lockable event, it reads the date and time from the RTC. With this information, it writes a log entry to nonvolatile memory and goes back to a sleep state. This is just one of many applications that make use of the RTC's calendar features.

Another important feature of RTCs is the alarm functionality. With the alarm function, an application can tell the RTC to fire and interrupt at a specific point in the future. While the application waits for the interrupt, it can enter a sleep state to minimize power consumption. Applications that need to run for years off a battery can use the RTC alarm function to schedule operations in the future and remain in ultra low power states in between.

We can see how an alarm feature may be used in a simple thermostat. For most of the day, the thermostat can remain in sleep mode, or it can attend to other operations. At a scheduled time, the RTC can fire an interrupt to alert the application that it has reached a specific point in the schedule. The application can then perform the required tasks, such as changing the temperature set point, and return to the main application code.

As you can see, the RTC alarm function provides an easy way to schedule events in an application. It's worth noting that the RTC alarm function is well suited for requirements perform a task at 5:00 PM on Tuesdays. But the RTC alarm function is not well suited for requirements like perform a task in 100 milliseconds. For operations that require subsecond scheduling, it's better to use a general purpose timer.

RTC accuracy is often a key performance metric. Let's talk about some factors that affect the accuracy of an RTC. RTC accuracy is determined directly by the accuracy of its clock source. Crystal oscillators are the best choice because of their low cost and good performance. However, they are not perfect.

All crystals will have an offset error that shifts the operating frequency away from the nominal. Generally, a crystal manufacturer will describe the offset error in terms of Parts Per Million, or PPM. This graphic shows that the actual operating frequency will be somewhere between the offset error pounds given by the crystal manufacturer. To learn more about crystal oscillators, check out the selecting an external crystal video linked below.

In this example, our 32 kilohertz crystal has a worst case offset error of plus or minus 50 PPM. This may seem negligible. But if we perform a calculation to find the worst case error in seconds over a day, we find that a 50 PPM crystal could have as much as 4.3 seconds of drift per day. It will be up to you to determine if this is an acceptable range for your application.

Some RTCs will also offer offset calibration to help reduce the effects of offset error on a per unit basis. The first step is to measure an actual RTC clock frequency against a high accuracy clock. Once the offset error is quantified, it can be accounted for in the RTC. Internally, the RTC will be able to automatically add or subtract clock pulses to account for the relative error of the input clock.

In addition to the offset area discussed in the previous slide, crystal oscillator sources also drift considerably with changes in temperature. Some RTCs offer the ability to compensate for changes in temperature to help reduce air. In general, a crystal manufacturer will give an equation that describes how the operating frequency changes with respect to temperature.

To account for this, an application can predict the expected change in operating frequency based on the ambient temperature. Just like with offset calibration, the RTC may be able to adjust the incoming clock source accordingly to account for the expected error.

In order to maintain accurate timekeeping, an RTC must always be powered. There are two primary options for satisfying this requirement. Option one, the system provides constant power to the RTC. An MCU in its powered down state with an integrated RTC enabled may draw less than 1 micro amp of current. This may be acceptable in many battery powered applications.

The downside is, if the battery loses charge, your system will lose track of time. Furthermore, not all systems have the ability to provide reliable power sources. Systems powered by the mains, for example, maybe disconnected at any time.

Option two, the RTC switches to a backup power supply when the system power fails. The backup power supply could be a coin cell battery or a large capacitor. And it should be able to supply the system until the primary power is restored. The benefit of this approach is that accurate timekeeping is preserved even in unstable power environments. The downside is it requires additional circuitry, and not all RTCs support this feature.

In review, an RTC is a special type of timer designed to perform accurate timekeeping. An integrated RTC can be easily configured using software. External RTCs will require a communication interface to send configuration information. An RTC will generally offer calendar and alarm features for easy scheduling.

An RTC can inform the CPU through interrupts, or the CPU can directly read the date and time from RTC registers. An RTC's performance is directly tied to the accuracy of its clock source. Using compensation and calibration features, you can sometimes improve the long-term accuracy of an RTC despite error in the input clock source.

And finally, an RTC must always be powered to keep track of time. There are different techniques to achieve this. Thanks for watching our introduction to real time clocks. To find more TI microcontroller technical resources and search products, visit ti.com/microcontrollers.

This video is part of a series