Internet Clock
Background
We recently replaced our Tivo with a TivoHD. A
consequence of that switch is that our cable box was replaced with a
cable card which is inserted into the TivoHD. With the loss
of the cable box we also lost the digital time readout which was on the
face of the box. We liked the readout and decided it should
be replaced. I suppose I could have gone out and purchased a
small digital clock but what's the fun in that. I decided it
would be a fun project to play around with.
Hardware Design
At the same time I had been experimenting with a new Wiznet
module - the WIZ810MJ.
The Wiznet module contains a complete
TCP/IP stack all on a single chip and makes interfacing with the
Internet fairly simple compared to previous solutions. So the
plan was to design and build a digital clock that would be capable of
interfacing directly with an Internet time server so that the time
would be very accurate. It would also solve the problem of
power failures as well as make Daylight Savings Time almost a non event.
The final design proved to be pretty simple with only 3 main
components. The components were an Atmel ATMEGA168
AVR
processor, a DB1-CLOCK
module from Lucid
Technologies, and a WIZ810MJ
module from Wiznet. The ATMEGA168 was actually more processor
than necessary with its 16K of flash programming memory. I
used less than half of the flash but I had several on hand and I have
tried to use this size on several projects rather than keep lots of
different sizes on hand. The 168 had all of the features I
needed - an SPI
interface to talk to the Wiznet module, several 16 bit
timers with interrupts to implement the real time clock, and enough
extra I/O to drive the clock display. The DB1-CLOCK module is
a 4 digit, .56" high LED mounted on a circuit board with an MC14489
common cathode driver chip. The LED module only requires +5
volts, ground, and three I/O lines - enable, clock, and data.
As I mentioned before, the WIZ810MJ uses the WIZ5100
chip
which is a complete ethernet interface on a single chip. The
module also has the required RJ45 connector, a 25 mhz crystal, and a
few passives to round out the interface. The only negatives
for me were the 14 X 2 X 2mm headers that were required to plug in the
interface. While these headers are not that uncommon, .100"
headers are far more common and, in fact, the next versions of the
module have .100" headers. These are the WIZ811MJ
and the
WIZ812MJ.
The only other thing I needed was a small power supply
section. I powered the clock from a 5 volt regulated wall
wart since the display requires 5 volts but the Wiznet module needs 3.3
volts so I included an LM3940IT-3.3
3.3 volt regulator.
I also powered the processor from the 5 volt supply which
worked out well since the WIZ810MJ has 5 volt tolerant I/O.
Here are the schematic and the PCB layout. Clicking
on the thumbnails will display full size images:
Software
I used the Bascom
compiler from MCS
Electronics for the programming and
I continue to be pleased with this software. Mark is
constantly improving it and, although every now and then I'm tempted to
switch to C, there's really nothing that I haven't been able to do with
Bascom. The concept is to set up an interrupt routine using a
16 bit timer. The timer start count on the timer would be set
to overflow in 1 second and the interrupt routine would simply reset
the count, increment seconds, minutes, and hours as required and then
set a flag once a minute to display the time. The routine
would also set a flag once a day at midnight when a routine would be
called to get the exact time from an Internet time server and correct
the clock if necessary. This routine would also adjust the
timer start value for the timer to correct for any changes due to
temperature drift which might cause the ceramic resonator frequency to
drift slightly.
The interrupt routine, real time clock, and display stuff were pretty
straight forward and things that I had done before. The new
part for me was the ethernet module and interfacing directly to the
Internet. Fortunately I found an excellent
tutorial on using
the Wiznet module and was able to use that to get a running
head start.
I used UDP
instead of TCP/IP
since it is a much simpler
protocol without error detection and was more than adequate for this
project. I also learned quite a bit about Internet time
servers and the different protocols used. There are basically
three different protocols used by time servers - Network Time Protocol
(RFC-1305), DayTime Protocol (RFC-867), Time Protocol (RFC-868).
You can read about the three protocols here.
Although it's not the most common, I used the Time Protocol
since it was the easiest to use for my first attempt and there were
several built-in Bascom functions that made the implementation very
straight forward.
The DB1-CLOCK module also has 4 LEDs that I made use of. One
is the AM/PM indicator, one is a daylight savings time indicator, one
is a link active LED, and the last one is an error condition indicator.
The Bascom source code is included in the download package if
you're interested in how it's all implemented. If you would
like to build a clock similar to this, you might want to contact me for
the latest code since I'm still tweaking the firmware to add features.
Enclosure
The clock enclosure was kind of fun as well. It's a simple
oak box fabricated from 3/8" red oak with a 1/8" oak back finished with
Watco
Danish Oil.
The fun part was making the cutouts in the front and back of
the case which I did with my little CNC
machine. I used
DeltCad to
draw the cutouts and SheetCam
to generate the tool paths and
G Code.
It's always fun when I can combine several hobbies
into one project.
Conclusion
So far I'm quite pleased with the way this project has turned
out but I'm actually thinking of building another one to implement all
the things I've thought of since completing the first clock.
Here's some of the things I'm thinking about:
- Making my own display board with surface mount components
to make the display module smaller to fit in a smaller case.
- Implementing the DayTime Protocol - this protocol indicates
daylight savings time so that the clock would never need adjusting.
Currently I have a small toggle switch on the back of the
clock and flipping the switch toggles daylight savings time off and on.
- My clock currently has a static IP address but it would be
nice to have it support DHCP
so that it could get its own address from the network.
- My routines only need to access the Internet at startup
and then once a day. Since the Wiznet module seems to draw
the most power, it would be nice to turn the power off to the module
and the 3.3 volt regulator except for when it was needed.
- I might even design a board using the WIZ5100 chip directly
and eliminate the module. That would cut the cost and size
significantly
Pictures
Here's the blank PCB:

Populated PCB:

Display board:

Clock with board installed:

Finished clock front:

Finished clock back:

And finally here's the
clock up and running:

Downloads
All of the necessary files are included in one download. The
file includes the schematic in TinyCad
format as well as a .jpg file, the printed circuit board in FreePCB format as
well as a .jpg file, the gerber files for having a board made (I used batchpcb.com), the
Bascom source code, and an Excel file with the complete parts list.
Questions
or Comments
Home