The UTC SUPERCLOCK

By Murray Greenman ZL1BPU

A simple precision clock, with LCD display. The clock uses an inexpensive precision reference
for accuracy of a few seconds per year.

INTRODUCTION

Ever wanted a clock that would keep really good time, even during power cuts? Ever wanted a clock with the bells and whistles YOU wanted? This little project keeps very good time, and has battery backup, so it keeps going (and telling the time) through power failures. It also features serial time output and a built-in phase detector system for self-calibration. There are resources to spare for additional features to be added. Best of all, the source code is free, so you can make your own adaptations and add your own features.

The project utilizes some interesting concepts in time keeping and frequency precision, and makes maximum use of recycled components. The Superclock makes a great platform for learning about time and frequency, and comes with source code, so you can make changes and learn about how it works as well.



The clock display

The display shown is a 24 x 2 unit. The design can also be used with the more common 16 x 2 unit. The longer display allows visibility of "engineering" information, normally hidden from the user. In this case the extra information is the reference phase and a power failure warning message. When a 16 x 2 display is used, the UTC and local time are centred in the window.

The clock is quite inexpensive to build - two ICs and a couple of transistors. One of the ICs is an AVR microprocessor - also inexpensive, and quite powerful. The other is a simple three-terminal regulator. The LCD display is a standard type used everywhere, and could be recycled from a broken business phone or appliance. Precision time keeping is achieved through the use of a Temperature Compensated Crystal Oscillator (TCXO). These can be reasonably expensive, but the unit used here can be recycled from a trashed cellular phone. Just about any frequency from 9 to 15 MHz can be used. Some of the features of the unit are:

The serial data can be used for time logging, or setting other clocks. The phase information can be used for calibration or long-term tracking of the reference oscillator error.



The Superclock project prototype
Click on picture to view full size

DESCRIPTION

Follow the Superclock Schematic as you read this description. Power for the unit comes from two sources - a simple plug-pack connected to the DC socket J4, and a backup battery, B1. The supplies are isolated from each other by diodes D3 and D4. When the plug-pack output (nominally 10-12V DC) is higher than the battery voltage, D3 is reverse biassed, D4 conducts and the clock operates from the AC supply. D4 also prevents reverse-voltage damage. Micro input PD2 (pin 6) is held high by R2, R3 and D5.

When the AC supply fails, D3 conducts, D4 is reverse biassed, and the clock continues to operate from the battery with no loss of time. However, since R2 is no longer able to keep micro input PD2 (pin 6) high, the micro detects power failure and displays a "BATT" message. The battery can be a small alkaline 9V type if power failures are rare, and will last normal shelf life. If power failures are frequent or the clock is used as a portable time source, a 6-cell 500mAH or better NiCd or NiMH battery pack is recommended. R1 can be added to slowly charge the battery from the AC supply.

Regulator U1 provides 5V with sufficient current to operate the micro controller, LCD display and TCXO X1. Since the micro runs very fast, the current isn't all that low, even though snooze mode is used much of the time. The total load is about 10 - 15 mA.

The RS232 transmit signal from the micro requires a negative voltage supply, and to keep supply current to a minimum, this voltage is derived from the mostly idle PC transmit data line, which is normally negative. TR1 converts to RS232 levels and transmits the serial data. Note how its collector supply is derived from the RS232 receive line, via D1 and R28. C8 maintains the -10V supply even when data is being received from the PC. TR2 is the RS232 receiver, with D2 catching the reverse voltage to prevent reverse bias damage.

J3 is the LCD connector, a standard 14 pin type. The LCD is operated in 4-bit mode to minimize the number of micro controller pins used. R20 is the display contrast adjustment, and usually does not require adjustment after setup (it can be internal). J1 is the programming header, a simple 2x5 pin device.

X1 is the TCXO, which needs to provide at least 1V p-p sine wave or a square wave output. A simpler alternative reference using a conventional crystal X1*, C2 and C3 is shown in grey on the schematic, but will result in considerably inferior performance.

The micro controller operates in snooze mode. The main timer interrupts and wakes up the micro briefly every 500µsec, where the 1 kHz output is toggled and a divide by 2000 counter stepped. Once every second the counter overflows, the 1 sec output is pulsed, UTC time is incremented, and the output updated. When each task is done, the processor goes back to sleep. The processor is very fast, and achieves these tasks very quickly. Thus the average current drawn by the device is moderately low, despite the high clock speed.

Time is kept in Packed BCD format ('Binary Coded Decimal'), where the lower four bits represent the units 0 - 9, and the upper four bits represent the tens. This makes counting more tricky, but simplifies display. Every time the UTC time is incremented, the BCD values need to be checked to ensure they follow the BCD format, which means checking that the low nibble is <10 and the high nibble <6. The hour is checked to see that it remains <24, and is set to zero when 23 is exceeded.

Local time is calculated by adding the local time offset, correcting the BCD, converting to 12 hour AM/PM format, and checking the BCD again. The maths is correct with offsets as large as ±13 hours. Negative offsets are achieved using signed hexadecimal numbers, for example, "FF" is -1, "FE" is -2 etc, although the user does not need to worry about it since the offset is simply incremented and decremented one hour at a time. The default offset is kept in EEPROM, along with the reference division and serial port baud rate.



The prototype circuit board

The LCD connector is top left. To the right is the LCD brightness control and further right the programming connector. The resistors beneath it are unused in this project. At the centre right is the micro. The two-pin connector bottom left is for the backup battery. The silver box bottom right is the TCXO. The prototype was built on a small Dick Smith H5608 project board with copper spots on the back.

CALIBRATION

Calibration of the Superclock can be achieved quite quickly using a GPS or TV based reference. Using an oscilloscope, TV line pulses can be observed while using the clock 1 kHz reference as a trigger source. Place one probe near an operating TV set, and another to the Superclock 1kHz output. The clock reference is adjusted for zero drift of the TV line pulses. This technique does not require direct connection to the TV set, but does require the TV station used to have a Rubidium timing standard (or better). In New Zealand, use TV1 or TV2.

If you choose a TCXO frequency that is an exact multiple of the TV line frequency (e.g. 10.0, 12.0 or 12.5 MHz) you can calibrate the clock by observing lines from the clock divider on the TV screen. This technique is very simple, requires no code changes, but is not documented here or in the manual. Contact the author for details.

The Superclock also includes a phase detector, which samples the phase of the local clock divider. An external reference is temporarily connected to an input of the the micro, and samples the local phase, which is displayed on the screen and transmitted via the serial port for tracking on a computer. See the manual for details. The manual also shows how to make a simple and accurate TV sync reference source for a TV receiver or video recorder using an LM1881.

Even using the simplest of techniques, the clock can be adjusted to give accuracy approaching one or two seconds per year.

COMMS PROTOCOLS

TRANSMIT (DATA)
The clock transmits time and phase every second, starting just after the second event. The format is

HH:MM:SS PPPP
where PPPP represents the phase of the local counter sampled by an external reference, typically 1 Hz GPS or 50 Hz TV frame pulses. The value of PPPP can be from 0000 to one less than the divisor required from the clock reference to 2 kHz, and is expressed in 16 bit HEX.

The clock also transmits responses to some of the time setting commands.

RECEIVE (COMMANDS)
There are no front panel controls on the clock. After all, it is accurate and battery backed, so what would need adjusting? The local time offset will need to be changed every six months thanks to daylight saving, and at this time the clock accuracy can be checked. It should be within a second of UTC if correctly set up and calibrated. All adjustment is achieved using the serial link to a PC. There are eight commands:


Hnn	Set UTC hours to nn (BCD) hours
Mnn	Set UTC minutes to nn
Snn	Set UTC hours to nn
+	Add one to UTC seconds
-	Subtract one from UTC seconds
>	Increment local time offset by one hour
<	Decrement local time offset by one hour
R	Retard clock by 10 ms

The commands should be used in the order shown while setting the clock. The commands shown in red cause the clock to stop while they are entered, so must not be used during time-keeping. Lower case letters are accepted and used as upper case. Invalid commands are ignored. The clock can be set with a simple ASCII terminal program, such as Windows TERMINAL, or even HYPERTERM.

By comparing the 1pps pulse output with a reference such as WWV or a GPS receiver, the clock can be set to within 10ms of real UTC time, and when calibrated, will stay there for months on end.

USER MANUAL

A comprehensive Superclock User Manual is available in PDF format. It includes a primer on frequency references, comparison and and calibration.

The manual gives construction, programming, setup and calibration information. To save this manual on your hard disc, right click on the above link and select "Save Target As ..." The file size is 800kb. The manual contains 16 pages including illustrations, photographs and the schematic. It can be printed on any A4 printer.

UNDOCUMENTED FEATURES

A few recent additions to the clock are not documented in the manual. These include an hourly CHIME output, a POWER FAIL sensor, and suggestions for driving beepers, generating alarms, and use of the Superclock as a network time server. See Undocumented Features for details. These features, a frequency reference and much higher accuracy are also built into the GPSClock.

BELLS AND WHISTLES

Because the source code is available to you, and there is plenty of code space remaining in the processor, and several spare port pins, you could add additional functions to the clock. Here are some suggestions:

SOFTWARE

The suprclk2.zip archive contains the following micro controller files:
suprclkn.asm          Clock assembly program source code
superclk.inc          Clock assembly definitions include file
2313def.inc           Standard definitions for 2313 processor
suprclkn.eep          EEPROM download file (14.85 MHz, 9600 bps)
suprclkn.hex          Executable code download file for clock
The suprbas.zip archive contains the following PC files:
sclock.bas            Phase display PC program QBASIC compiler source code
sclock1.exe           Phase display executable (COM1)
sclock2.exe           Phase display executable (COM2)
The first group of files are those used to create the AVR micro controller firmware. The suprclk2.asm source file is carefully structured to be easily understood, and is comprehensively commented so modification should be straightforward.

You can compile the source code for yourself by getting a copy of the AVR Assembler free from Atmel. You will also need a copy of the ISP, or "In System Programming" software, free from the same source. Obviously, if you want to modify the software, you will need both programs. If you don't want to change the software, simply use the ISP to load the executable software (suprclk2.hex). You will also need to make or borrow a suitable Programming Adaptor, which operates from a parallel printer port, or use a commercial serial port unit such as the Jaycar KC-5340 or the Atmel AVR ISP.

Note that the programming adaptor recommended on this web site will not work with versions of ISP programming software later than V 2.65. There is more information, including where to get ISP V 2.65, in the Superclock User Manual.

The second group of files are the PC software, which is only used for calibration. You can run sclock1.exe or sclock2.exe in a DOS box directly from Windows™ 3.1, 95, 98 or 2000. They can also be run directly from DOS. Computer requirements are minimal - a 486 processor and a serial port. Use the sclock.bas source file (used to compile the two DOS programs) as a guide to writing your own software if you wish. To recompile the software as a DOS executable, you will need Microsoft Quick BASIC 4.2 or another advanced BASIC compiler. (GWBASIC or other similar BASIC interpreters may be too slow).

The Superclock software is free for private use. Most of my projects will cost you $30 for the source code, but not this one! However, I'm a busy boy, so the free offer does not include email support for the project. I am happy to quote for customer-specific design and code changes. Send me an email.

Right-click on the following links, and select "Save Target As..." to save the Superclock documentation to your computer.

suprclk2.zip AVR Firmware
suprbas.zip PC software
SCLOCK.PDF Superclock User Manual
CLOCK2.GIF Superclock Schematic
See the statement of ownership, permission and limitations for information regarding your rights and obligations regarding this project.

PARTS LIST

This is not intended to be a complete or exhaustive parts list. It simply lists the major parts and suggests a suitable source. The project is inexpensive since several of the more valuable items can be from a recycled source.
REF  DEVICE                DESCRIPTION                          SOURCE
-    Circuit board         Small project board, DSE H-5608      DSE, Jaycar, Tandy, Radio Shack, Digi-key
-    LCD Display           16 or 24 character two line display  DSE etc, disused business phone or FAX
-    Case                  150 x 180 x 30mm or smaller          Disused modem or TNC case (and power supply)
U1   78L05                 5V 3 terminal regulator, 100mA       DSE, Jaycar, Tandy, Radio Shack, Digi-key
U2   AT90S2313-10PC        10 MHz Atmel RISC microcontroller    Memec, Polykom, DSE, Jaycar, Digi-key
X1   5V TCXO, 1v p-p out   Typical freq 9.6, 12.8, 14.85 MHz    RAKON, disused AMPS or DAMPS cellular phones

Copyright © M. Greenman 1997-2005. All rights reserved. Contact the author before using any of this material.
home HOME