Build by David McKinnon novak |at| gekkoscience.com
This week's write-up is a bit late, but the last one I posted early so we'll pretend that I'm not a terrible person. This is an article about clocks. I like clocks as electronics projects, because they have a nice mixture of simplicity and pretty lights. Currently I'm working on a nixie tube clock (You may have seen the write-ups by Kittan, who is working on the power supply), and also I've put in some data on an old binary one I built a while ago.
The binary clock I build was done entirely out of 4000 and 7400 series logic chips, and just using the chips that I had on hand, which is why they're not entirely optimal, and have a few more pins than needed. Here's the clock on a breadboard.
The clock's time-base is a 32768 Hz. crystal, fed into a 4020, which is a 14 bit binary counter with an onboard oscillator circuit. This chip then emits pulses every half second into the seconds counter, which is a 4040, a 12 bit binary ripple counter (here are your extra pins). The 4040 has outputs driving the LEDs for seconds, and the reset is tied to three gates of a 7408 quad-AND gate, so that when it reads 120 half-seconds ((64&32)&(16&8)) it auto-resets. The reset is also tied into the 4040 counter for minutes, so every time the seconds zero themselves they also trip the minutes. The minutes are configured nearly identically, except that they only count 60 whole minutes rather than 120 halves, and reset on ((32&16)&(8&4)) from their own 7408. The hours are also a simple counter and use a single AND gate from the minutes 7408 quad package, and it of course it only counts to 24 (16 & 8). The clock is set up to output 24 hour time, rather than 12.
The time setting on the clock is extremely simple, and works by pulsing an input to correct counter, exactly as would happen if it were to receive an input pulse from the counter beneath it. A diode blocks the set button from resetting the counter beneath it (for example, setting the hours does not reset the minutes). Setting the seconds simply strobes the reset on seconds, clearing them to zero.
Here's the assembled clock. I put it together simply, so you could still see the guts of it, which I think are pretty cool. Definitely a lot of fun building the entire thing from discrete chips rather than a microprocessor.
The nixie clock is still a work in progress, but the clock portion is done. I used a microcontroller so that I'd be able to add an alarm function to it. I was unable to locate a clock IC with BCD output and an alarm, which sort of surprised me. I found several capable of driving seven segment displays, but none that simply output BCD, as a nixie tube driver would need. At any rate it is not difficult to implement on a microcontroller. I selected the AT90PWM3B microcontroller, an 8-bit AVR because it had high resolution PWM which might be very handy for creating a pretty alarm sound, and also because it would be reasonably easy to manufacture boards for. It comes in a SOIC-32 package, which has 0.05 inch spacing- lager than most surface mount processors, but still does not require holes to be drilled in the board.
I wrote all the software in AVR assembler, which I have not written any of before, though I've written ARM and x86 assembler. For the most part I found it pleasant but sometimes things like the lack of a DIV instruction threw me for a loop.
Building a test socket for the processor to stick on a breadboard took me longer than I would like to admit with my soldering iron (a lot longer, actually), but at least I got it on the first try. The basic idea of the circuit is to count pulses from a crystal oscillator, which is much more accurate than the internal R/C oscillator which is used as the processor clock. The oscillator emits 32768 pulses per second, which go directly into the 8-bit counter. The counter is set up to trigger an interrupt on overflow, which increments fractions of a second. This fractional second count is triggered 128 times per second, and when it reaches 128, it jumps to a routine that increments seconds. When seconds equal 60, it increments minutes. Minutes, however, is separate from tens of minutes, and hours are separate from tens of hours. This is because each is a distinct digit, which will be driven by a separate circuit. The BCD outputs on this test board are simply driving LEDs, but of course they will drive nixie tubes in the final design.
There are also set buttons on this clock, which, when pressed, go into a short delay loop before reading the appropriate value- minutes or hours- from memory and incrementing it. This delay loop is to ensure that the set function takes a few moments to trigger and does not move too fast.
Also, since this display is fully driven by a microprocessor, there's no reason to lock it down to either 12 or 24 hour. Instead, that's an optional setting, and there is a light that comes on to indicate if the time is PM if it is on 12 hour mode. The time is always stored in 24 hours, but each time the fractional settings are updated, the display is too- and the time is written in either 12 or 24 hour mode. I did not use a state table for converting between 12 and 24 hour mode but instead a pair of conditional statements. A possibly clearer method to make the software would be to save the conversion table into memory and simply access the appropriate element, but this also works.
By way of comment about the outrageous spiderweb of wires here, I've never seen a more chaotic pinout than on this chip. It does have a lot of pretty handy functions though, such as 64 MHz PWM, 16 bit timer/counter, dual on board comparators, and 10 bit DAC. Overall I like it but I can't help but laugh when they can't seem to put any of the pins for the same port next to each other.
I also made a test BCD counter and drove a nixie off of Kittan's power supply, just as a test. Look how pretty that is.
Questions, comments, corrections or humorous mockery? Email me at novak|at|gekkoscience.com.