This project was originally published in the Australian electronics magazine, Silicon Chip, 3/2001.
It is issued here as a kit with permission. Some modifications to the original published circuit and software have been made and are are mentioned at the end of the documentation.
The Big PIC Clock is based on a PIC16F84 micro-controller (uC.) The software in the uC allows for very accurate timekeeping. For visibility at a distance it uses 2.3/57mm super large, hi-efficiency red LED displays for the hours and minutes and smaller 0.56 LED displays for the seconds. The circuit incorporates a dimming feature so that at night the reduced ambient light is sensed and the display is dimmed. Before you construct the clock please read through the following theory about clock adjustment and setting and the general circuit description.
Accuracy Theory and Adjustment.
The clock may be adjusted for very good long-term accuracy. All crystal-based clocks have a tendency to run fast or slow. Some use a trimmer on the crystal for adjustment but they will still drift due to temperature changes over time. However, in this design an accurate adjustment feature has been built into the software. Carefully adjusted you should be able to get the clock to keep time to within a few seconds a year. The adjustment technique requires you to correctly set the clock and wait a few days to see how accurate it is. Then an adjustment mode is selected and the number of seconds the clock differs from the correct time calculated over a period of 60 days is entered in. However, it is not necessary to wait 60 days. At the beginning, a day or so is long enough to get a good idea how fast or slow the clock is running. The only requirement is that you calculate the number of seconds it would gain or lose in 60 days. Of course the more days you wait the greater the accuracy of the adjustment After entering the adjustment figure the clock then maintains time by slightly adjusting the length of a second every so often. If the crystal was running slow then there will be an occasional shorter second (999msec) to speed up the clock. Conversely, if the clock was running fast there will be an occasional longer second (1.001 sec) to slow it down. In software the adjustment figure of seconds per 60 days is divided by 10,368 to obtain a reference counter value. For example, if the adjustment figure is 60 (1 second per day) then the reference value will be 10,368/60 or 172. This value is compared with a second counter which is increased once every 500msec. When the second counter value reaches the value of the reference counter, the second counter is altered by 1msec. The second counter is then reset to count up again. For our example value, the second counter will reach 172 after 500 x 172msec, or 86,400msec. Therefore, a correction of 1msec is made every 86,400 msec which is equal to 1 second per day. Thus there will be 1000 corrections per day. (One day has 86,400 seconds.) The number of seconds per 60 days adjustment figure requires a positive or negative sign to indicate whether the clock needs to use slow seconds or long seconds. A minus means the clock is slow and needs speeding up. A plus (no sign) means the clock is fast and will need to be slowed. The adjustment range is from 0 to 255 and from 0 to 255 seconds per 60 days with 1 second per 60 days resolution. This corresponds to 0ppm through to +/-50ppm adjustment with just under 0.2ppm steps. The time adjustment is initiated by pressing both the hatkey switches (one is for hour adjustment and the other for minutes) simultaneously. The seconds display will show an Ad. Upon release the current adjustment figure will be shown. You can increase it by pressing the hour switch and decrease it by pressing the minute switch. If the number goes below zero the minus sign will appear and these negative numbers are used when the clock is running slow. The positive numbers are for fast clocks.
Press both switches simultaneously to return to the clock. The time will need to be reset correctly. The adjustment number is stored in memory and will be retained unless changed by entering the Ad mode again and changing.
Example: if you find the clock is 1 second fast every 60 days you need to add +1 to the current adjustment figure. Thus if the current adjustment figure is 35sec/60 day correction, then it must be changed to 34. Or if the current value was 38 then it must be increased to 39.
Use the minutes switch to go to the correct hour and minute with the seconds at 00. You just wait until a reference clock (TV, radio) begins the next minute. Pressing the minute switch will go to the next minute, reset the seconds to 00 and thus enable the clock to be set accurately to about 1/10th second.
This is easy to do and non-disruptive. To advance the clock just press the hour switch once. To retard the clock one hour just press it 23 times. That is, keep it depressed until the previous hour comes up. In both cases the minutes and seconds are unaffected. 12 or 24.
You may toggle between each display mode by depressing the hour switch when you apply power.
In 12 hour mode am or pm (your decision) is indicated by the decimal point LED of the leftmost display coming on. On initial power-up the clock is in 24 hour mode.
This is under software control. The duty cycle for the multiplexed signals to all 6 displays is varied. In a multiplexed display only one digit is on at any one time but the displays are cycled on/off at such a rapid rate that there is no noticeable flicker. When the displays are driven at full brightness each display is on for 1/6th of the time (the duty cycle is 16.6%.) The dimming feature uses a 1.5nF capacitor and a Light Dependent Resistor (LDR). The capacitor is discharged each time a digit is about to be lit and the PIC waits until the capacitor is charged before lighting the display. In bright light the resistance of the LDR is low so the capacitor charges up quickly and the display is lit fast. In darkness or low light the LDR has a much higher resistance, and the capacitor takes longer to charge so the duty cycle for each digit is reduced. That is the display is dimmed. The displays are dimmed only in clock mode.
Power and Battery Backup
Use a 12VDC plug-pack for normal operation. Space has been provided for 4 x AA NiCd or NiMH cells with solder tags. We have NOT provided the batteries. The metal pins to attach the batteries to are provided. With the batteries present when there is a power failure the seconds hands keeps counting but not the large displays.
Pinouts are different for the two displays. See the top overlay of K73A for the pinout details of each display. Note that two of the large 2.3 displays are mounted upside down.
Software is the key to the circuit. The hardware is really just a collection of interface chips, displays, and components to input and output results into and out of the software to and from the real world.
A look at the schematic brings this point home clearly. Some familiarity with the PIC16F84 uC is assumed.
Both the commented source code and the object code are available.
The interface circuit is complicated by the fact that the PIC requires 5V while the large displays require 12V. These requirements are catered for by connecting the Vdd terminal of IC1 (pin 14) to the +12V rail and the Vss terminal (pin 5) to a +7V rail derived from a negative 3-terminal 5V regulator. IC2 (4051) then acts as a level translator (voltage shifter) for the outputs of IC1 so that they can drive IC3 (ULN2003A) and the large displays. Power from the 12V plug-pack is applied to the circuit via a 2R2 resistor and diode D1 which provides polarity protection. The 2R2 resistor limits the current into the zener diode should the voltage go above 15V. REG1 is a negative 5V regulator. Diode D2 in the GND leg sets the output at about 5.6V below the 12V rail but this extra 0.6V is lost at diode D3 which feeds pin 5 of IC1. The 100uF and 10uF capacitors decouple the inputs and outputs of REG1. The reason for increasing the output of REG1 to 5.6V is to give a slightly higher charged voltage for the backup batteries which are charged via the 10R resistor. D3 is included to reduce the supply to IC1 down to 5V. D4 is included to bypass the 10R resistor when the circuit is powered from the batteries. This lowers the impedance of the battery supply which is desirable when driving a multiplexed display, otherwise voltage variations to IC1 could cause false resetting. Note that there is a link LK1 between the batteries to allow the backup supply to be disconnected. IC1 operates at 4MHz as set by crystal X1. The 27pF capacitors provide loading for the crystal so it will oscillate within tolerance. These capacitors are Negative Positive Zero (NPO) types which mean that their temperature coefficient is zero and that they do not alter their capacitance with normal temperature variations.
Traditionally, clocks have always used crystals which oscillated at a frequency which was a power of 2, making it easier to divide the frequency down to 1 Hz using binary counters. The most common value of a crystal used in this way is 32.768kHz. Others are 3.2768MHz and 4.096MHz which need to be divided by 100 and 1000 respectively. First before division by powers of 2. In this kit, however, we have used a standard 4.0MHz crystal because beside being readily available the need to divide by powers of 2 is unnecessary when using a uC to provide the clock function. We divide the 4MHz by 16, then by 250 to obtain a 1kHz signal to multiplex the displays. This again divided by 500 to obtain a 2Hz signal which is used to flash the colon on/off. The seconds display is updated on every second 2Hz signal, that is, 1Hz. The RA4 pin on IC1 is set as an output and is used to discharge the 1n5 capacitor via the 470R resistor. When RA4 is taken high, its output is open-circuit and the capacitor charges via the 2K2 resistor and the LDR. As mentioned above the capacitor charges faster when the LDR is in bright light (low resistance) and slower when the LDR is in dull light. The charge time is monitored by RA4 and used to control the display dimming. The RB0-RB7 outputs of IC1 drive transistors Q1-Q8 via a 470R base resistor. When the outputs are low, the transistors are switched on to drive the segments in the six displays. The segments are driven via 82R resistors while the decimal points are driven via a 180R resistor.
The 0.56 display segments are driven by 220R resistors. Different feed resistors are used because the 2.3 displays have 4 series LEDs per segment and two series LEDs in the decimal points. The 0.56 displays only have one LED per segment.
Normally with multiplexed displays such as this the same segments for each digit are connected in parallel. This circuit, however, is different. Two displays are mounted upside down. This has been done to obtain a colon between the hours and minutes and to obtain the am indicator.
The common cathode connections to each display are driven by IC3, a ULN2003A 7-transistor array. IC3 is driven via IC2, a 4051 8-channel analog switch or de-multiplexer. In this circuit it has two roles. Firstly, it acts as a decoder which converts the binary signals on its three input lines (A, B, C) to drive six outputs, one for each common cathode LED display. Secondly, it provides logic level (voltage) translation, changing the 5V signals on its inputs to 12Vsignals to drive IC3. IC2 can do this because it has three supply connections: the Vdd pin (16) connects to +12V, the Vss pin (8) connects to the 5V from REG1 (ie, 5V below +12V supply) and the Vee pin (7) connects to 0V. As well as acting as the B & C outputs to IC2, pins 17 & 18 of IC1 are monitored via diodes D5 & D6 which connect to the Minutes and Hours switches resp. The other side of the switches both connect to the RA3 input (pin 2) of IC1. Normally, pin 2 is held low via the 10K resistor to pin 5. However, if a switch is pressed and the B or C line driving the switch is high, the RA3 input will also be pulled high. This signals to IC1 that the switch is pressed. IC1 can determine which switch is pressed because it knows which line (B or C) is high at the time.
Runs on 12vDC.