I recently found six 2.3″ red 7 segment displays in my collection which I purchased from Rapid Electronics when they were clearing out non-RoHS stock. Since I have no clock at my work bench I decided to construct one from some prototyping pad board, a Microchip PIC18F26K20 microcontroller and a Dallas DS32KHZ temperature compensated 32.768kHz crystal.
I wanted this to be a fairly quick project to complete, so the schematic is fairly simplistic. The schematic diagram of the clock is shown below:
The 7 segment displays are common anode displays, with segments consisting of four red LEDs in series and the decimal places consisting of two red LEDs in series. To reduce the number of GPIO used to drive the display, various methods can be used – such as multiplexing, shift registers or dedicated display drivers. I’ve chosen to use plain display multiplexing, requiring one GPIO for each digit common anode, and one GPIO for each segment – with the colon separators, that gives 7 common anodes, and 8 cathodes with the decimal places and colons commoned together. There are many methods to reduce the number of GPIOs needed further than this, but the chosen microcontroller does not have a shortage of GPIO for this application.
The forward voltage of the segments is slightly high – the datasheet specifies between 7.4V and 10V. For this reason, the anode drivers for the displays have to perform both voltage translation in addition to sourcing enough current for the displays.
A BC327 PNP transistor is used to source the 12V supply to the digit common anode. The transistor used here must be rated for the full current of each digit with all segments lit. The BC327 is rated for a maximum collector current of 800mA, which is more than adequate for these displays, even when driving them at high peak forward currents. With a minimum current gain of greater than 100, the 2kΩ limits the maximum base current to prevent damage to the transistor whilst allowing around 500mA collector current to flow.
The voltage translation is provided by a ULN2003A darlington transistor array. This is effectively a package of 7 open collector darlington transistors which is used in this circuit to turn the BC327 on by pulling the base to 0V through the 2kΩ resistor. The 10kΩ resistor acts as a pull up resistor to hold the transistor off when the open collector transistor is off.
The cathode drivers simply use a ULN2803 8 channel darlington transistor array to drive the individual segments on the displays. The open collector configuration rather than a logic 1/0 is important here in order to prevent the digits staying dimly lit when turned off. If 3.3V logic drivers were used, the logic high of ~3.3V could still provide a high enough potential difference between the anode drive to cause the LEDs to remain lit.
You’ll notice the cathode current limiting resistors here – these have been selected to drive the display at higher than the 20mA rated current of the displays. When the displays are multiplexed, the maximum duty cycle is limited to 1÷(multiplex cycles), in this case, 1/6 or around 16%. Provided that maximum power dissipation in the LEDs do not exceed the datasheet specified value, it is safe to drive the LEDs at higher current to recover the original brightness of the LEDs.
The clock is driven by a Microchip PIC18F26K20 microcontroller. This is a 28 pin device and was somewhat arbitrarily selected based on the first 28 pin microcontroller I came across in my collection. Very little processing power is required for this clock, so selection was merely based on having at least two hardware timers which were configurable enough for multiplexing the displays and keeping time. Although I plan to interface this clock with my GPS Disciplined Oscillator, this build has a local crystal so that it can be used as a standalone clock and also so any readers of this blog can build their own.
I chose to use a Dallas DS32KHZ Temperature Compensated Crystal Oscillator, purely because I quite like the devices in this range – both the integrated RTC modules and the plain TCXOs. It also means you don’t have to worry too much about tweaking the load capacitors on your 32.768kHz crystal, or adding in code to correct for oscillator drift.
The TCXO just needs power and it’ll output a 32.768kHz square wave which in this circuit is fed directly into the Timer 1 clock input. The crystal oscillator regularly checks the temperature and adjusts the output frequency to maintain a relatively accurate 32.768kHz output.
The microcontroller code can be easily adapted for a standard 32.768kHz crystal if required.
Power for the microcontroller is provided through a 3.3V regulator from the 12V supply rail.
When the circuit was being designed, I wasn’t sure if I’d add any status LEDs or anything else to the circuit, so I estimated with the microcontroller running at 16MIPS, TCXO and some additional margin, the 3.3V regulator should be capable of providing 60mA. Given the LP2950-33 used here is in a TO92 package, the ~500mW dissipation at 60mA is a little high for comfort. Three 330Ω resistors in parallel are used here to dissipate up to ~400mW of the power when the regulator is fully loaded at 60mA, whilst ensuring the supply voltage to the LP2950-33 is high enough to maintain regulation. A single larger ~110Ω resistor could be used, however I had none available.
The schematic also shows an RS485 transceiver set up for reception only – this is to interface with my GPSDO, so not needed in typical applications.
The code to drive the clock is attached below, designed for Microchip XC8 compiler. This runs the microcontroller at the full 16MIPS, multiplexes the displays at 250Hz and uses the three momentary buttons to set the time.
I’ll add a bit of documentation to go with the code shortly.
Please feel free to use the schematic and code to build your own clocks for your lab. Don’t forget to post a comment below with any pictures or comments!