Project/Vetinari Clock

From rLab

Overview[edit]

Vetinari Clock
Schematic
The Control Board

A 'Vetinari Clock' is a DiscWorld inspired timepiece that ticks irregularly and yet still manages to keep good time, my clock is hung in the main RLab hackspace room above the door into the 'chill out' area.

Hardware[edit]

The clock is based on a standard AA cell wall clock I bought from the local Staples in Reading. The clock module was disassembled and wires were connected to the ends of the coil used to drive the movement. A Microchip PIC 12F683 is used to generate a pulse into the coil to make the second hand move by one tick. I used the same circuit as several other vetinari clock designers based on a 32.768kHz watch crystal. As this was a one off project I built the circuit on strip board (rather than a PCB) and hot glued it to the back of the clock.

Software[edit]

My software drives the PIC rather differently from other designers. The PIC is configured to use its internal RC oscillator at 4Mhz when it is executing code and the 16-bit timer 1 module is configured to use the watch crystal as its source of timing pulses even when the CPU is in its low power sleep mode. The main body of the code uses a Linear Feedback Shift Register to generate a series of random numbers in the range 0 to 15 by extracting some bits from the register. These numbers in turn are used to select a pattern of ticks for the following eight seconds. There are four patterns with 0, 1, 2 and 3 irregular ticks encoded within them.

The random numbers are mapped to patterns such that there is a 10 in 16 chance of the regular pattern being used, a 3 in 16 chance of one irregular tick, a 2 in 16 chance of two irregular ticks and a 1 in 16 chance of three. So most of the time the clock works normally and occasionally it will tick abnormally. Timer 1 is used to count the period between ticks and during this period the PIC is put into a low power state. When the timers counter reaches zero the CPU wakes, loads the timer for the next period and generates a pulse to move the seconds hand before going back to sleep. This means the CPU is active for just over 50mSec during each tick. This should make the batteries last much longer than designs that run the CPU continuously.