Scythe crossing a pen, backed by a circuit

AVR powered true binary clock

Patrick Tait, HoA chief Mad Scientist
HoA Laboratory, department of hideously rushed projects.
Finished clock

My first microcontroller project, done as a sort of a "hello world" style introduction to the world of microcontrollers. It's a true binary clock that receives power and timing pulses from a 3 volt transformer salvaged from a wall wort. The heart of the circuit is an Atmel attiny2313 microcontroller. I chose this microcontroller specifically because of the instructable detailing a programmer that I could build almost entirely out of parts at hand. It's a true binary clock (as opposed to binary coded decimal) with three "digits", one for hours, minutes, and seconds. There are two pushbuttons, salvaged from an old mechanical switch keyboard. They advance the hour and minute digit. There's no provision for an alarm. This project taught me a good deal about how engineering projects with deadlines work. I needed to complete the project in time for Christmas because I intended to give it away to my not-quite-godfather, Kevin. As a result, I have no construction pictures, and the only one final picture. The end result has a good deal of unused code left over for a dimming function that was never implemented, but it works well enough.

The internal clock of the attiny2313 is in no way accurate enough for use as a real time clock, and getting a crystal seemed overkill for this project. However, everyone who gets electricity from a power plant gets a steady signal from the wall, be it 50 or 60hz. Since many clocks also receive time signals from the power line, it's a mandate that in any given day, the average frequency is exactly 60 cycles per second. The output is AC, but a simple diode will convert it into the DC pulses that are needed. A separate challenge is the fact that the 2313 has a total of 18 usable pins, with one reserved for programming. The clock requires an input for the 60hz signal, two more for the pushbuttons and 17 for the LEDs, for a grand total of 20 pins. To reduce the needed pin count, I used a technique called multiplexing. With multiplexing, only some of the outputs or inputs are used at a time, but the set that is used is switched rapidly enough that to our eyes they appear to be on at the same time. In this project, each string of LED's (Hours, minutes, and seconds) are separate, and only one is on at a time. Only one switch is active at a time as well, leaving the project with 6 free pins.

As shown in the diagram, the second, minute and hour LEDs are wired together, with each string sharing a common anode, and each cathode is wired in parallel with the equivalent cathode on the other strings to a pin. Power is sourced to each string in turn and the relevant pins are allowed to sink current to turn on specific LEDs. An additional pin is dedicated to pushbutton input and another for the timing pulse. Theoretically, fewer pins could have been used, but this would have complicated the programing. Two of the extra pins were used to output debug information (not showed). One was set to invert every seconds, the other with every 60 hz pulse. Again, this was code that was left in the final version out of a rush. It doesn't harm the functionality in any way, and removing it may have introduced unexpected behavior. Current was limited via a 480 Ohm resistor on the input pin for each bit of the LED string. The transformer was a 3 volt wall wort disassembled and repurposed for this project. Note that it uses a center tapped, two diode design. If the project used a four diode bridge rectifier there would be a greater voltage drop due to the fact that twice as many diodes are used. This means that running a single diode from the AC line would output a higher voltage than the power supply, leading to a voltage greater than VCC on the input pin. The 2313 has clamping diodes to prevent this from damaging the device, but it is still not a recommended practice. Adding a second diode or a voltage divider would solve the problem.

Circut diagram for binary clock

The case is something of a last minute mashup. I was originally planning on using a project box from Radioshack, but the one I was planning on using melted a bit when I sat it on top of the toaster oven I was using as a heater in the garage lab. I have since moved the lab into the basement, but at the time I had less than a day to finish the project, so I used what I had on hand. The front is the bottom of a Radioshack gift card tin, the bottom part of the back is an outlet box and the top part is the front of a spare bit box. It was all spray painted black and held together with an unholy mix of hotmelt glue and JB Quik. All of the circuitry is in the outlet box, with the transformer and circuit epoxied to the wall. The power plug is of standard PC type, salvaged from a dead power supply. It held together well enough, and even though it's kinda hideous, it looks OK from the front angle. Kevin was pleased, although he refused to take home with him on the plane for fear people would think it was a bomb. I'll take that as praise.

The only parts I purchased for this project specifically was the microcontroller and the (unused) project box. The remainder were either previously owned or scavenged. Total cost was about ten bucks. The source can be found here, was compiled under Linux with avr-gcc, and is released under the BSD licence, as detailed in the source code. For IDE independent programming, the firmware Hex file is here.

If you wish to comment on this mod, send me an email at p@ohbah.com.

Return to index.

Valid HTML 4.0 Transitional Valid CSS! powered by Vi!

All works on this page are copyright 2009 Patrick Tait. Some rights reserved: creative commons attribution 3.0 license