Clock in action. |
One interesting dilemma was that how to light 128 LEDs with a CPU, that has only 16 GPIO pins. The problem is somewhat reduced by the matrix modules themselves, which provide only 16 pins: 8 anode and 8 cathodes. The modules can even share the cathode pins, so one only needs 16+8 pins, which may be driven by couple of 74595 shift registers and 8 AVR IO pins. The '595 drive the LED anodes and the AVR IO port sinks the cathodes via current limiting resistor.
In this design, the '595 are driven perhaps too close to their limits, but in practice they work fine for this first version. I did order some real LED driver chips (MAX7219) for some other project, perhaps I'll try to use them in the next revision of the clock.
The mechanical building was a bit harder than I thought, as the LED matrixes had a slightly incompatible spacing as the normal perforated 0.1" board I use and the sheer amount of pins (2*16+24=56) which each needed a short wire on the daughter board.
After the CPU board was ready, it was time to do the easy part, i.e. the software. The code is structured as a state machine, which is ran from a timer interrupt 12500 times a second. On each step the code shuts down one, and lights one led, from left to right. After one row is shown, the next anode line is grounded and others set to high-z state. The rest of the time the CPU sleeps in the idle mode to save some power.
The time keeping itself is the easiest part, as it is handled mostly by a DS1302 chip. The chips is easy to use via three wire serial interface, and it even has its own circuit to handle the backup power source. For backup, I chose a super capacitor, but have not yet actually written code for charging it. The cap is rated for 5.5V, which should drive the clock chip for quite a many days, but perhaps I'll try to play safe and make the DS1302 to drive only 3.3...4 volts into it.
Anyway, the clock works now and is waiting for a enclosure and place to keep it.
Here are the basic components:
- CPU: Atmel Attiny26L-8PU (Obsolete part, but nice to use as the port pins are close to eahc other)
- RTC: DS1302
- Output: 2*LED matrix (8x8)
- IO multiplexing: 2*74HC595
- 1.0F (!!) super capacitor
- resistors, capacitors and switches, 32768Hz crystal
Schematics drawn with Eagle. The pin headers SV1, SV2 and SV3 connect to the daughter board and ISP to the programmer. R9-10 are there to protect CPU from ESD, just in case. |
Undersides of both boards. |
Top side, which shows also the huge capacitor. The cap seemed slightly smaller on the ad, so it did not fit well into board;) |
Hi, I'm just building almost the same project, I want to add 2 ds1820 for temperature reading.
ReplyDeleteWould you like to share your code?