Hardware Reference
In-Depth Information
hardware RTC to your Raspberry Pi, this would not be a problem. The system would read the time from the RTC on
boot and continue on its happy way. If you are going to use your Raspberry Pi as a stand-alone PC or even as part of
a non-networked project all hope is not lost if you don't have an RTC. Most common Linux distributions contain a
software clock that will record the last shutdown time. This will solve your login issues as your time won't drift back to
the 1960s, but it's far from an accurate time source.
The need for an RTC will really depend on your project. Unfortunately it's not some feature you can just enable or
plug in. That's what this chapter will cover: how to make an RTC circuit and how to attach it to the Raspberry Pi. This
chapter will include some minor SMT, but don't be put off by that work. When I come to the SMT work I will show you
some tricks to make it easy for you.
The Beginning of the RTC in PCs
The first PC to use an RTC was the IBM PC/AT, launched on August 15, 1984. As you can see, PCs have used RTCs for
a long time. The PC/AT used the MC146818, made by Motorola at the time. The original MC146818 was a 24-pin dual
inline package, or DIP package. A DIP package is where you have the chip in the middle of pins that run on each side,
and the chip is then placed into a socket or soldered into holes on a PCB. Compare that to the RTC you will be using;
it's a rather large chip. I want to talk about how the MC146818 gives out a valid date and time. Once you understand
the MC146818, you can move on to using any RTC as they are all loosely based on the MC146818.
The MC146818 had a set of nine registers that you could read and write to.
Registers 0, 2, and 4 controlled the time: register 0 was the seconds register, 2 was the
minutes register, and 4 was the hours register.
Registers 6, 7, 8, and 9 were responsible for the date functions: register 6 was the day of
the week, register 7 was the date of the month, register 8 was the month, and register 9 was
the year.
When the RTC is in a fully powered and operational state, you can read any combination of the above registers to
get your desired date and time. If you wanted to, you could also write a date and time value back to the registers.
This was often done when you first used an RTC to set its time.
At the heart of it, an RTC is just a simple counting device. Every one second it updates the registers to their next
value. Exactly how would this chip know what one second is, though? That's where your crystal oscillator comes in.
This small device, as the name implies, oscillates at a set frequency. This frequency is printed on the device and you
will be using a 32.768-kHz crystal. How can something oscillating at 32.768 kHz give you a one-second timer? Well,
it can't. That's where another chip comes into play.
This little chip is part of the main RTC chip. It's called a prescaler and its main job in life is to divide the input
frequency into a stable, slow clock rate. This prescaler is what gives us the 1-Hz frequency that in turn gives us the
one-second tick value: after all, 1 Hz is equal to one pulse per second. Unfortunately, crystals are affected by the
temperature and many other environmental effects. Any of these effects can alter the frequency at which the crystal
oscillates. This is where your clock skew comes from. There is nothing that you can do about this and I am sure you
have all experienced it: for example, when you turn on an old PC that has been powered down for a while and notice
that it's lost a few hours. Of course you're going to need a way to keep this crystal oscillating when your device is
turned off. This is where the little coin-shaped battery has its one and only job. Its job is to supply just enough current
to keep the RTC chip alive and the crystal oscillating. If your battery goes flat you will instantly lose the stored date
and time.
You may have noticed that when I was talking about the registers I skipped a few numbers. There is another
function of the RTC and that is an alarm function. The skipped registers provide a way to set an alarm date and time
for an event to happen. If you had poked around your PC's BIOS you would have come across a setting that can wake
up your PC at a set time. This function directly uses the RTC registers to listen for the set alarm date and time.
Pretty much every RTC you will find today will bear some similarity to the MC146818, so as long as you
understand the basic functions of the MC146818 you will be fine to select any RTC for your project. It's time to take a
closer look at the RTC you will use for this project.
 
Search WWH ::




Custom Search