Last March I was bored and decided to build a clock using analog meters. My idea was to use three analog meters with scales that went from 1-12, 0-59, and 0-59 and indicated hours, minutes, and seconds respectively. Although it’d look analog I planned to use a microcontroller to do the heavy lifting.

I wanted to use antique meters and go for a steampunk look. After cruising Ebay for a while I realized that antique meters are collectible and that they cost collectible prices. Who the fuck collects antique meters? I didn’t really feel like spending $100 on a meter I wanted and since it was unlikely I’d find them in the scales I needed, I went to plan B: buy regular meters and make them look antique.

The first step of the project was to write some software to put on the microcontroller. I had a PIC 16F84 lying around (who doesn’t?) so I decided to build my clock using it.

Prototype of the meter clock built on a breadboard.

In order to control the output to the meters I used pulse width modulation (PWM). Since the microcontroller is digital, it can’t easily output analog amperages (meters measure amperage not voltage even if their faces say “Volts”) so if it takes 1mA to put the needle at full swing (and 0mA to put the needle at its lowest setting) I can get arbitrary points between no- and full-swing by changing the amount of time the microcontroller is outputting 1mA. For example, if the microcontroller is outputting 1mA half the time and 0mA half the time the needle should stay at around the center of the dial. If this switching is done quickly the needle should hold still and not vibrate.

[Update 20081111: As the drier winter weather started the clock started to reset and stop ticking about once a day.  A little examination of the schematic reveals that I forgot to connect the /MCLR pin on the PIC to a pull-up resistor.  The /MCLR pin should be connected to VDD via a 1K resistor]

Schematic of clock (click to enlarge).

Since I needed 60 discrete positions to put the needle for the minutes and seconds I needed to pulse width modulate the meters at some multiple of 60 (so to show 39 minutes I’d need to output an “on” to the meter for 39 cycles and then “off” for 21 cycles and then repeat).

Another view of the prototype. The microcontroller is the black IC at the bottom.

I originally figured using a 60Hz duty cycle would be fast enough. I wrote my software using carefully timed assembly language so that exactly 60 pulses happened every second which, with my original clock crystal selection of 4MHz meant that each pulse of my duty cycle had to happen exactly every 16666 2/3rd instructions.

This was a giant pain in the ass. Because 60 didn’t divide one million evenly (a PIC executes an instruction on every fourth clock tick so 4Mhz = 1 million instructions per second) I had to put all sorts of complicated compensatory code into my subroutines. To make matters worse, once I built a prototype circuit on my breadboard I found that my meter needles vibrated. A 60Hz duty cycle was too slow.

After several iterations I eventually settled on running a 10MHz crystal and using a 600Hz duty cycle. Also, to make the timing less complicated I switched to using Bresenham’s Line Algorithm. This algorithm is normally used to draw lines on computer screens, but it can be applied to timing applications as well. The idea of using this algorithm is that the duty cycles don’t have to be be exactly timed and if they’re off by a microsecond here and there it doesn’t matter as long as the timing averages out correctly over time. Although any particular event might not be exactly correct there is zero culmulative error and over time everything works out correctly.

The finished circuit built onto perfboard.

The circuit I designed had four buttons and three potentiometers: one button to force all the needles to the max setting, one button to advance the hours, one button to advance the minutes, and one button to reset the seconds. The three potentiometers were for fine tuning where the “max” setting for each needle falls.

Meanwhile, I was checking Ebay for something steampunk-ish to put my clock into. Eventually I got the idea of using an antique radio. Not exactly steampunk, but the idea of an anachronistic “clock radio” seemed pretty funny to me. I settled on a home made 1920’s radio.

Finished circuit with meters (original faces) connected.

The meters I had chosen still needed to be made to look antique and to have their scales altered so their units went from 1 - 12, 0-59, and 0-59. I carefully took each of the meters apart, scanned their faces into my computer and edited them using The Gimp (a freeware equivalent to Photoshop). When I was happy with the look, I laser printed them and soaked them in tea to make them look aged. I carefully cut each new meter face out and glued it over the old one and put everything back together. They looked awesome.

The finished clock radio.  The time indicated is 1:10:30.

Finally I had to mount my meters in the radio. The front of the radio was made out of Bakelite which is super fucking brittle. I cracked the face of the radio several times trying to cut holes in it. Each time I cracked it, I had to super glue the cracks back together.

Finally everything was complete.

Close up of the meter faces. Notice the edited graduations and tea-stained “antique” look. Time is 1:09:55.

The clock radio now sits on a shelf in my living room and actually keeps very accurate time.