I've been meaning to create this post for a while. Besides my day job, and my recent sojourn into Android, I'm into hobby electronics. Now I've had the code slinging itch since I saw my friends Timex Sinclair 1000 when I was 11, but in the past couple of years, I've really embraced the breadboard and the soldering iron. Software is very satisfying, but there is something about making something that you can hold, touch. And that you appear to your loved ones to possess some sort of voodoo that can transform a mess of wires and chips and LEDs into something that does something.
In fact, it was my desire to show my wares to the world that inspired me to finally get off my rump and create this blog.
Now to exhibit A...
Last year, after working for several grueling months on a clock, (still at 90% complete a year later, the topic of a future post), I wanted to make something that my wife would not just appreciate, but enjoy, get excited about. So I asked her what type of electronic device she felt was missing in her life. She replied that she wanted a "time out/ time's up timer" for our kids, who happen to be procrastination aficionados, and occasionally earn a trip to the stairs to "think about what they've done". And so was born the "Good Times" timer.
Here is the finished result: (right before boxing to put under the tree last Christmas)
(Apologies, I'm really an awful photographer)
|The juicy innards|
At this point, I can't remember what features were planning from the beginning, and which ones were added along the way. I can say that running on battery power was cut as a feature after early tests showed that the 4x7 segment leds alone were drawing around 180 mA when all lit.
- Timer, adjustable in +5:00, +1:00, and +0:15 increments.
- 4 digit display via 7 segment LEDs
- Play/Pause/Stop functionality
- "Happy" and "Sad" modes, to distinguish when my kids are counting time for positive or negative reasons.
- Sounds, audible button press feedback and alarm music.
- "Stoplight" LEDS, to indicate when time was almost up and when it was up. (This was a feature suggested by my wife that turned out to be pretty useful in other ways)
- Capacitive Touch buttons.
- Wooden case with black polyurethane stain.
- "Easter Eggs" I love easter eggs, and I ended up with a lot of extra flash space on the main micro-controller, I think I only used about half of the ATMega 644's 64k of flash.
This is a short clip of the basic features in action:
So here's a high level breakdown of the key hardware features:
- Two Atmel microcontrollers communicating over a UART.
- An AT Tiny 2313V running at 10Mhz that handles low level capacitive touch button monitoring and feedback LED
- An AT Mega 644P running at 20Mhz, that handles logic for stoplights, display, audio/volume control, and of course timing.
- Four 7 segment (+ decimal point) displays that are driven by four 74hc595 shift registers.
- time tracking is done with a secondary 32.768 kHz crystal driving an interrupt on the 644.
- Audio is driven by the square wave generator of the 644, and volume is modulated with a mosfet and a 4 bit "r2r ladder" DAC.
- One 20 MHz crystal drives both controllers, with the "clock out" from the 644 feeding into the 2313.
- DPST for on/off and a barrel jack supplying 7.5 volts with a 1.5 amp supply.
On the physical side:
- stained wood frame, designed with QCad (http://www.qcad.org/)
- Two "rats nest" perf proto board circuits, one to house the display, shift registers, and one to hold everything else.
- 7 Capacitive touch buttons, made from spare aluminum flashing, and "imprinted" using a laser printer and an iron for transfer toner to the flashing. (A big experiment, that turned out quite well, I wrestled a lot over the course of the project with how I would do the final buttons)
- I have misplaced the link that inspired the mechanism for capacitive touch. (Just google it, there are tons out there on how to do it). It took the basic idea, and did a lot of tweaking to get what turned out to be very robust and responsive touch keys. For most of the project, I had a test setup that consisted of pieces of aluminum foil taped to a 1x4 with wires running from the foil to a breadboard.
On the software side:
- The 2313 was coded in C using AVR Studio 4 and WinAVR.
- I coded in C, but did a lot of debugging at the assembly level. It was a minor struggle to keep memory in check, the stack would frequently clobber the static data area of ram, every single global and stack variable was scrutinized. With about 600 lines of code, I pretty much maxed out what this chip was capable of, at least with out codng in assembly.
- The 644 was coded in C++ using the same AVR Studio/WinAvr combo.
- With 64 k of flash I had a lot more leeway to get "architectural", a complete "domain model" system with managers and a "mode stack" to implement a state machine. In all, about 4500 lines of code.
- Song data for the various songs was transcribed from sheet music into a string in a custom "music language" and stored in flash and access via WinAvr's "PGM*" macros.
- Inspired in part from my youth, on a Commodore 128 : http://www.commodore.ca/manuals/128_system_guide/sect-07b.htm#22.214.171.124
An AVR 644 did give up the ghost in the making of this, luckily it was early on, when most of the project was in 3 breadboards wired together. It's the only thing so far worth over $0.10 that I've fried in the few years I've been doing this, so I consider myself pretty lucky. I inadvertently connected a 9v supply to the output side of my linear regulator instead of the input side, exposing the whole circuit to 9v for about 30 seconds. The strange thing is that the chip worked as last programmed, but it refused to accept new programming, so something in the flash circuitry died, it was a little anti-climatic, no magic smoke.
I think this is good stopping point for "part one", this post doesn't look long, but took longer than I expected it would.