TopfieldClock - your NTP clock at the living room

© Erkki Seppälä <flux@modeemi.fi> 2012-2013, last edited 2013-08-08.

Why

On year 2011 the old faithful Topfield DVB box gave up and swapping the capacitors from the PSU only prolonged the inevitable (thanks CountZero for the donor hard drive, which promptly died :)). When the end was near we started using the TVKaista service, which stores the data on the network so the need for a separate DVB device was gone—and we already had a PC hooked up to the TV.

What didn't go away, however, was the need to see the time of day. While the box by itself was able to post through the boot sequence it seemed more interesting—and possibly safer, from the flakey-PSU-point-of-view—to replace its guts with something else. So I decided make use of the old box and as a bonus I decided to make use of its seven-segment display instead of adding a display and display controller of my own. And why not add network connectivity with NTP support while at it!

Research

I started the project by opening up the box and hooking an oscilloscope to various places. I soldered some additional pin headers to the front panel port and determined which of the pins were active when the display was being updated. I also needed to make a guess on which end of the bus was doing the talking.

A surprising thing was that the display module itself had a clock (but no battery-backed RTC). I imagine this is so that the main unit doesn't need to be powered and it can still maintain the time of day. For my purposes I didn't try to find how the time of day was sent to the display but I was rather focused on how to control the individual segments of the display.

With the assistance of a logic analyzer (although I quickly changed into a program in the microcontroller, just way more easier to analyze when you get the data straight out to command line) I captured the sequence that was sent during the startup to the display. In addition I captured some sequences that affected various parts of the display. By sending the initialization sequence myself (I wrote a program for sending sequences via the MCU on Seeeduino, in the Arduino environment; it accepted a text input and then sent the bit sequence) I was able to make the display show the same fixed output that the Topfield itself had shown: win!

After figuring out the protocol I started fiddling around with the messages. I modified some parts of the message and saw the effects on the display. At times the device became unresponsive and I needed to start again. Through this iterative process I was able to determine the structure of the bit fields and I achieved the complete control of the display. Well, barring the set time of day -functionality and while I did decode the infrared receiver part and buttons at the front panel as well I didn't really make attempts to write software to use it. The power button was the only thing beyond my reach.

The messages themselves aren't particularly interesting. But here is the template for commands setting digits. A bit length is 52 microseconds.

00100000 01110101 01100111 0$DIGIT0 111110$DIGIT1 111 10$DIGIT2 1111110 S$DIGIT3 11000111 2 011000000 2

$DIGITX here is the Xth digit in form of seven bits (one for each segment, 0 indicating "show segment"). 2 indicates at least 12 consecutive ones, could be more. Here is the document where I was trying to figure it all out. It's a bit mess.

Implementation

I finally had all the information I needed to write the code. In addition to using only the display I also used an ENC28J60 Ethernet module that plays well with an Arduino. I took a look at the NTP RFC and was rejoiced about how simple it was to decode; what I wasn't rejoiced about was that I was not able to determine a 'local' time zone for the clock, so the first version had a fixed time zone offset (the current version has hard coded Finnish time zone, that takes summer and winter time changes into account).

The implementation listens to the NTP broadcast messages sent by ntpd. For that I needed to modify the existing ENC28J60 code so that it configured the chip to accept broadcast messages.

The precision of the time Arduino was able to maintain was abysmal. I don't quite remember the specifics but probably it could travel dozens of seconds per day compared to the real clock. It didn't quite affect this case, though, because I was able to retrieve the time of day quite often. But I did add code to adjust the rate the clock was progressing, depending on how much the expected time differed from the time that was received from the network. (Later on I also added code to stop showing the time if there was no solid time information received within the last 24 hours.)

Finally, once the code was feature-complete, I decided that it would be too wasteful to put a whole Arduino in there, so I designed a basic PCB that had the microcontroller, a regulator for powering the front panel module and the required pins to interact with both the front panel module and the the Ethernet module. I still made use of the Arduino Uno bootloader, as life is just that much simpler with it.

Future

As in all projects, some ideas were still left unimplemented. One idea was that maybe XBMC—the media center of choice—would be able to send the name of the current file being played over the network to the device. The name would then scroll over the display periodically, like in the original Topfield (with the additional TAP enabling some functionality).

Another feature would be to make it fully configurable with the remote control. Set IP, etc. That way it would resemble more an end product than a hack, though..

Maybe something could be added to use the infrared receiver. The received control messages could be passed back to XBMC and let normal controls work as expected. Currently we just use a mini-keyboard.

In addition to showing time I could show maybe new messages in IRC, new email, status of TVKaista-transfers, current kitchen timer countdown, beef thermometer readings, distance to a person walking to the front door, whether there's new mail in the physical mailbox, etc.. As we can see, possibilities are unlimited! Except when limited by the 4-digit seven-segment display :-).

Links

Pictures gallery

Git repository

Github clone