Saturday 22 December 2012

LED Clock Part 3 - Display Multiplexing

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

Recently I've been looking at replacing the circuit in an old LED clock that finally gave up after 30 years faithful service. Previously, I've looked at a simple replacement and a teardown of the original clock.

Having now given up on CPC supplying the LED displays for the replacement circuit (I'm told they're due sometime in January), I've decided to look at reusing the original display. It's unusual as most LED displays these days are sealed units, where as this one has LED chips on a PCB with a white frame around that and a red diffuser on top.
You can just see the some of the segments are lit, they're just washed out by the camera flash. The method of driving is also unusual and is one of those circuits that I just don't think anyone would design like that these days.

Traditionally, you have two options to drive a 4x7 segment display, either directly drive each segment from an IO pin via a current limiting resistor, or multiplex the display digit by digit. The former option requires 4x7 = 28 IO pins and current limiting resistors and all segments are connected to ground. At 10mA per lit segment, it would use 280mA worse case. The later saves both pins and power, at the expense of more complicated software. The segments are all wired in parallel, but the grounds are switched per segment. So for example, although all the top bars (segment A) are driven from the same IO pin, only one of them will be switched to ground at any time. So the loop is:

  1. setup the output for the first digit, 
  2. turn the first digit on (the display now shows 1_:__) 
  3. wait a set time, 
  4. then turn off digit 1 
  5. setup for digit 2, 
  6. turn on digit 2 (the display now shows _2:__)
  7. wait...
  8. and so on
If you do this fast enough (usually > 50Hz), persistence of vision takes 1_:__, _2:__, __:3_ and __:_4 and merges them, so you see 12:34. This only need 4+7 = 11 IO pins, 7 with current limiting resistors for the segment anodes, and 4 with drive transistors to control the common cathodes. The power is also reduced as only one digit is ever on at a time, so the worst case is only 70mA.

The display on this clock was sort of an unorthodox mix of the two. Rather than 1 phase for each of the 4 digits, this has only 2 phases, each of which controls bits of each digit. There are no current limiting resistors as the IO pins of the TMS3450 are current limited at 18mA. The common cathode drive transistors are also missing as it makes use or a rather neat trick, but one as I said, I don't think anyone would come up with these days. What it does is use the ac from the transformer which already alternates at 50Hz, fed via diodes, so that on each cycle of the mains, one of the common cathodes sinks current as it's on the negative cycle. The other is on the positive cycle, so the diodes are reverse biased and therefore off. The flickering of the F segment on the hours I used to see occasionally must have been due the timing drifting slightly out and this being set before the phase cycle was complete.

I've slowed down the cycle. Here is phase 1:
And here is phase 2:
When switched fast enough, you get the combined result:
So, can I drive this from my microcontroller? Yes, it's just a case of providing 14 io pins for the segments and 2 drive transistors. I used MCP23008's for the segments, one for the hours and one for the minutes. The colon and the common cathode transistors were driven direct from the ATMega328P. I added a DS1307 real time clock, as per the simple version, and here it is, the slightly more complicated LED clock:
The next step is to build that up on veroboard and install it in the original case.

On to part 4, finishing the LED clock

Wednesday 12 December 2012

LED Clock Part 2 - Teardown

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

I am working on a more complicated version of the 'Simple LED Clock' in my previous post, however this is currently delayed as CPC has messed up my order again and I'm still waiting for some of the parts I ordered. So the prototype is currently using 2 MCP23008's to drive one digit each:
Whilst I'm waiting, here's a look inside the original 30 year old clock.
Inside there's a lot of space where the radio used to live.
It's a three board construction
With one for the top buttons, one the logic board with a single IC and finally the display
The chip is a TMS3450NL, and the date code (32nd week of 1983) seems to fit with the 30 year old estimate.
I have managed to find a scanned datasheet for the chip:

After all this time of putting up with a 12 hour clock, I find that not only did the display have sufficient segments to display 1 and 2 (but not 8), the chip supported 24 hour mode, it just needed a pin shorting to ground.

On to part 3 - more on display multiplexing.

Friday 7 December 2012

Simple LED Clock


This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

For the last 25 years or so, I've had an old LED bedside clock by my bed. It was discarded by my parent's after they'd used it for a good few years as the radio broke, so is probably about 30 years old in total. I think I fixed the radio, but I never used that anyway, At some point, I replaced the alarm-triggered radio with a relay to turn on first a light and later (ironically) a radio. But for most of those years, it simply stood there with 3 1/2 seven segment led displays showing me the time.  It was a 12 hour clock with an LED to indicate PM. I personally prefer a 24 hour format, but I put up with that as I suspect the leftmost digit can only display a 1 (i.e. is missing the segments to do 20:00). Also a couple of the segments occasionally flicker at half brightness when they are meant to be off, but again that wasn't a major issue.
It's been pretty solid for all those years, I hardly ever had to adjust it, twice a year to add or remove an hour for summer time, and the occasional tweak to the minutes, and of course resetting it after power cuts. I suspect it used the old school technique of counting the mains 50 Hz cycles. Whilst it can vary by a few Hz, it is (or at least used to be) guaranteed to average out to 50Hz over 24 hours. So clocks like this one just filter the ac from the mains transformer, and every time they count to 50 increment the seconds counter.

However, last week I noticed it was out by a few hours. I readjusted it and later found it was out again. It seemed to be ok for a day or two, then I was it was about 6 hours out again. I reset it and then saw it was incrementing the minutes about every 30 seconds! A quick check with a meter showed the mains frequency was 49.95Hz, so it couldn't be that. At this point, I decided it might be time to replace it.

I have designed and made a number of clocks over the years, many using a 40 pin PIC (16F874), multiplexing the displays with a high side driver (ULN2803) an open collector driver (7407). I also liked to use tri-colour LED's which faded through the colours from red to green as part of the display multiplexing.
However, it seemed only right that the replacement for this should be fairly plain red 0.56" 7 segment displays as before, nothing fancy. There were two main elements to deal with, the clock and the display.

The PIC based ones main clock was derived from a 4.194304 MHz crystal which can be divided that down to get a 1 Hz counter (4194304 = 2^22). For this, I'd decided to go for the easier option and use one of the DS1307 real time clocks. This should have sufficient accuracy and a battery backup. This is a nice simple DS1307 module from adafruit.

I went through a few designs for various display options, the favourite using I2C IO expanders (MCE23008 or MCE23016) with direct drive. I finally went for something even simpler. An I2C controller 4x7 segement display module, also from adafruit.
Building up the circuit with an Arduino and the two I2C modules was embarrassingly simple, 8 wires in total!

The code with then almost trivial as well. Ask the rtc what time it is, update the display. sit around doing not very much for a while. Then start again. I went back and added a 2 Hz flash of the colon so that the Arduino didn't get too bored.

I didn't even bother with setting buttons as the adafruit library made it easy to sync the RTC to the PC time, and because of the battery it maintains that time. The date is also set (although not displayed - something I might think about for the future?) so I could expand the code to adjust for daylight saving.

So there it is, about as simple as I could make it. Lets hope I get 30 years out of this one!

Onto part 2 - a teardown of the original LED clock