![]() |
![]() |
![]() |
![]() |
|
||||||
Real Time Clock chipNow that the display is working, it's time to get it to show something meaningful. Currently, it's right twice a day and could keep the time perfectly, if someone were willing to stand there and press the button once a minute. But clocks have long been automated and though the miracle of electronix there's no reason why this one can't be, too. |
Roman Numeral Clock Project |
|||||
|
Many real time clock (RTC) chips exist and I happen to own a few - I had a couple of DS1302 real-time clock chips from Maxim lying around, so I figured those should work. In fact, they do a lot more than I need, including date, day-of-week, and even leap year compensation. And best of all, they also let you attach a backup battery so the clock will remember the time through power outages. |
As of this writing (6/23/05) Digi-Key has the RTC chip for $3.31 U.S., part number DS1302-ND (DIP) or DS1302Z-ND (SOIC). |
|||||
ChiplomacySo the first task is to get the PIC 16F628 talking to the clock chip. The DS1302 uses a 3-pin serial interface: one for chip enable, one for a data clock, and one as I/O. Wiring this to the PIC was pretty easy, but I was a bit worried that it wouldn't work on a breadboard because of the elaborate DS1302 application-note instructions on how to hook up its crystal. The crystal you're supposed to use is a 32.768KHz watch crystal, and you can find these everywhere but not always quite to the specifications the application note demands. That app note is a rather picky document, but you do have to go through quite a lot to get a clock to be really accurate, so I don't begrudge it. |
||||||
To the left you can see the hackery I did to be able to breadboard the watch crystal. These things are tiny cylinders with hair-fine leads, so there's no way they'd work in a breadboard as-is. In a spare bit of the printed circuit board I made for the display, I made some little breadboard adaptors for a surface-mount part I plan to use in another project, and used part of an extra one of those for the crystal. This setup is probably a disaster as far as really high accuracy is concerned, but -
It works! (I'm using a 16x2 LCD display for these RTC tests since it's easier to manage than the Roman Numeral Clock display, and can show debugging info.) And a minute and 27 seconds later,
It still works! This little test just set the DS1302's time to 00:38:17 and let it run, querying the RTC about 10 times a second to update the display. |
||||||
Faking the ClockNow that the RTC is talking to the PIC, it's time to add all the functionality I want in a clock. This is pretty minimal, I just want it to show the time and be capable of waking me up at a given time in the morning. It won't have to work very hard because I'm a very light sleeper. |
Because the clock is Ancient Roman style, it will not have an alarm but rather an alarum. |
|||||
Here we have the fake clock display showing the following: “SZ” in the lower-right means the fake clock is currently in snooze mode. The alarum went off at 16:54, and I pressed the mode button, which starts the snooze.
Now the snooze-alarum time has been reached and the alarum is ringing again. The fake clock seems to be working fine - it can even restore the time and alarum time from battery back-up if I shut it off while it's going. It needs a bit more tweaking and testing, but even now it should make a satisfactory alarum clock. ConclusionsWow, it's a lot more work than I thought to write a clock. I had to switch to the 20x4 display because there was a lot more internal state data than I expected. I wanted some sort of fancy features - snooze, for instance. Also I wanted to make it so that the alarum would never ring for more than an hour because sometimes you forget and leave the alarum enabled when you're out of town. It's very annoying to have an absent neighbor's clock screeching all day, I know from experience, so in the interest of neighborhood goodwill I limited the ring time. If you don't wake up by the time the alarum's been going off for an hour, you're probably not going to anyway. Now all that remains is to use the real display! And as soon as I have this working, I'll write it up! Check back later! |
||||||
|
Page Top
|