A simple digital clock

Well I guess you have to do a clock at least once, right?

We have an accurate LCD clock in our living room that is really good for what it does but it’s hard to read when the light isn’t bright. And we don’t like too much light in the living room so it’s a pain when trying to keep an eye on the clock to know when dinner is ready say.

I’ve been planning to make a clock based on an IV-18 vacuum fluorescent display tube for a while and already had a couple of samples of Maxim DS32KHz temperature compensated crystal oscillators. I could use one of those and try everything out on what should be a simpler project. So I picked up a couple of 4 digit, 7 segment LED displays for about £1 each. They’re about 1″ tall so perfect for a clock. Throw in a photo-resistor so it can react to ambient lighting, a button or two and an ATmega328 running at 8MHz with the onboard clock and that should be enough.

After doing some reading up, I decided that driving a 7 segment display from the ATmega was too much faff – and wouldn’t give good results without a lot of work – so I bought a few MAX7219 7 segment display drivers (eBay, from China) for about 90p each. This gives you an easy way of limiting the current consistently to each segment and also digital brightness control on top plus a simple serial interface requiring only 3 pins on the MCU.

I found a good write up here and decided to try everything out on a breadboard or two.

Attack of the breadboards

There must be a rat in there, somewhere…

From left to right we have:

  • Display and MAX7219 IC
  • Photoresistor
  • A couple of buttons
  • ATmega328
  • Maxim DS32KHz

The main aim of using the breadboards was to sort out the software. I’d hoped to use one of the ATmega328 counters/timers but wasn’t able to find anything that let me do what I needed to do. They seem fine with crystals as input but the MAX32KHz doesn’t give the same kind of signal. I’ve since found a better reference that should let me use the Timer1 counter rather than the crude interrupt (pin INT0) and software counter that seems to be a really bad way of doing things – 32KHz gives an interrupt every ~31us.

The (still under development) sketch can be found at github.

I added a 3V backup battery since that photo was taken and I’ve made a start on building the clock (which will go in a plastic case that held a foil cutter for use on wine bottles). More investigation of the Timer1 counter required so I can sort this software out. I also need to detect when it’s running on the backup battery so I can shutdown the MAX7219 (and the display) – my attempts so far have been useless but I think I just need to use the ATmega328’s internal reference voltage and a suitable voltage divider to decide if we’re at ~5V or ~3V.

The MAX7219 has an “RSET” pin that you connect to +5V with a suitable resistor. It applies 100 x that current to each segment so you get uniform brightness. The forward voltage on these segments is 1.9V and the maximum current is 20mA. I aimed for 10mA current so Table 11 in the MAX7219 datasheet suggested a 63KOhm  resistor – I had 68K so I went with that.

To be continued…

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *