Friday, December 26, 2014

Countdown Clock - Stratum 1 Not Required

Well, someone has tasked me with building a "Christmas Countdown" clock.  A couple of blocks away from our house are a few houses that have been referred to as "Yards in which Walmart threw up" - meaning they had so many "cheap" decorations that they essentially didn't have a yard.  One of these homes has a countdown clock in the front window.  We'll call this "The House" in this post.

A neighbor of mine loves Christmas (he is a good friend of mine).... to the extent that the family has to drive past The House every day just so he can see the clock.  He doesn't work a soldering iron at all, but he has requested that I build him a custom countdown clock.

First, I needed a good way to count down to a target date/time.  I didn't want something attached to a network (e.g. using "NTP), and I didn't want some fancy clock that had Stratum 0/1/2 (which, incidentally, are all NTP - I know this, but I'm simply using that as a reference point so that you can understand that I don't need accuracy over a long period).

There are a number of ways to create a clock.  They are broken into two categories - analog and digital.  An analog clock is (usually) simply a motor and gearing to move the hands on the dial.  The digital requires a signal input - often referred to as a "clock" (go figure).

Because he wants a days/hours/minutes until Christmas clock, it should probably be digital.  I can go the highly-accurate way and procure a crystal oscillator and design a circuit around that, or I can simply use an inaccurate oscillator - the infamous 555 timer. For the purpose of this, expecting it will be used once a year for only a couple of months, I'm settling on the 555 timer.

With that settled, I needed a circuit.  I really needed something fairly accurate to the 1/1000th of a second.  Here's a circuit that should give you pretty good results :

The thing I see wrong with the circuit above is it is about a 66% duty cycle, meaning that the output will be "high" 2/3rds of the time.  I'd rather have it closer to a 50% high, 50% low duty cycle.  But it also has to have that accuracy.  Let's tackle the accuracy first.

There are 86400 seconds in a day.  If we are slightly off by 0.004 seconds, over one day, we lose almost 346 seconds.  That's 5 minutes we lose (or gain) every day.  Let's say we are only using the clock from Thanksgiving until Christmas.  We'll round it to 30 days just for the sake of simplicity.  That turns out to be 10368.0 seconds over the 30 days, or 172 minutes, or nearly 3 hours over the course of 30 days!  Probably unacceptable.  Even if we are at 0.001 seconds off every second, it still comes out to about 43 minutes over the 30 day period.

That means I have to get this pretty close (unless I have to procure a crystal).  With that out of the day, here's the formula for figuring out the resister/capacitor combination :

f =1.44
(R1 + R2) x C

So, now we have to do some math.  We want the frequency (f) to be 1 Hertz, or 1 cycle per second.  To get this, we have to have the capacitor times the sum of both resistors equal to 1.44 .  I wanted at least the R1 to be a standard value, and I found that I can put R1 to a 1k Ohm resistor - that's common enough.  Also, a common capacitor is 47 uf, or micro farads.    I can plug that in where the "C" is in the formula.  It means I now have a formula that looks like :

r2 =1.44 - (r1 x C)

So, what is the result of the math?  Unfortunately, it came out to just under a 1k Ohm resistor (969.361 Ohms).  But looking at some 555 timer calculator sites, it says I need a 14.855k Ohm resistor (or a combination that adds up since they don't make a 14.855k Ohm resistor).  I must have done my math wrong.  Back to the drawing board!