| What is it? | The Hardware |
|---|---|
| Circuit Operation | The Software |
| Operation | Parts List |
| The Files | Download |
It comprises a clock/timer using 3 double-digit 7-seg led displays
giving 6 digits in all. There are 8 push-switches, 1 piezo buzzer,
2 leds and 1 logic output. As well as a 4 pin programming
connection.
Setting time is much easier than a conventional electronic clock
or stopwatch because there are two buttons each (INC and DEC) for
hours, mins and seconds. It is written in A84 assembler.
The common-anode double-digit LED displays were salvaged from old computer cases, the Switches, 4 pin socket and LEDs from old computer monitors, the Piezo buzzer and Transistors from old computer printers, the 74138 from an old XT computer mainboard, and the Crystal from an old computer modem.
The crystal frequency was selected to give the highest integer byte value for Interrupts Per Second. ( IPS =( (Mhz/4)/256 )/PRE where PRE is from 2 to 128 ) Only one TMR0 Prescaler value (8) suits the above for 1.8432. A frequency of 3.2768Mhz has 4 possible prescaler values but the maximum interrupt rate is 25Hz slower than that available with 1.8432Mhz. The strobe rate of the LEDs and LED displays is IPS/8, so with IPS=225 the strobe rate is 28.21 per second. Using 3.2768 yields a maximum of 25 per second. Anything lower is seen to flicker. If you wish to use IPS greater than 255 then the software will need to be changed to allow 16 bit decrements.
IPS for 4 common crystals:- (* = Usefull values)
b0-2 Pre 1.8432Mhz 3.2768Mhz 4.0000Mhz
~~~~ ~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~
000 1: 2 900.000 1600.000 1953.125
001 1: 4 450.000 800.000 976.562
010 1: 8 225.000 * 400.000 488.281
011 1: 16 112.500 200.000 * 244.140
100 1: 32 56.250 100.000 * 122.070
101 1: 64 28.125 50.000 * 61.035
110 1: 128 14.062 25.000 * 30.517
111 1: 256 7.031 12.500 15.258
Any double-digit displays from computer cases should be tested because some don't have certain segments or dp connected even though the pin is present on the base. To test one, connect 5-12v+ to the Anode pin (see diagrams for pinouts), and touch the -ve via a 1k resistor to each segment pin to test. WES Components in Australia sell double-digit displays as replacements for those used in some TVs (Green=LED402G and Red=LED402R) for about $5 each, but I have not tried them.
I used BC640s because they were what I had on hand but just about any general purpose PNP transistor would do as long as it has ECB or BCE pin configuration. Of course if you are re-routing the PC board then the above does not matter.
6 Vdc was chosen because the displays will be brighter than if they were run from 4.5v. Also 4xAA battery holders are more common than 3xAA. The PIC has a Max Vdd of 5v, so two 1N4148 diodes are used to drop the voltage about 1.2v to 4.8v.
The ON/OFF switch is DPDT type (double pole) and is wired to short both supply rails to ground when OFF. This is because with the board connected to the programmer, the PIC takes power from the TTL lines and will not otherwise reset properly. However, double pole switches are much more common that single pole switches and would normally be used and wired as single pole.
The Piezo Buzzer is rated at 12v but is quite usable at 4.8 volts. It is not ear-piercing but nevertheless audible at 15 meters indoors and consumes only 1mA.
The Button Switches are the 4 pin type with bridging links (2 pins per contact), which seem to be the most common type used in monitors and printers.
The displays and LEDs are multiplexed. That means that at any one time only 1 is actually on. 225 times a second the ON display is shifted. Because there are 8 display devices in all, each device is on approx 28 times per second. At this rate the eye perceives all displays as being on simultaneously.
Because the PIC16F84 has only 13 I/O lines, and 8 are used for the segments and switches, and 2 for the logic out and buzzer, that leaves only 3 lines for 6 displays and 2 LEDs, ie, portA bits 0, 1 and 2. The 74138 is a 3 to 8 decoder. The 3 input bits select which of the 8 output lines will be LOW. Three bits can encode from 0 to 7 (000 - 111). When an output line is LOW it turns ON the corresponding transistor which connects the common anode of the corresponding display or LED to +6V. Almost any variety of 74138 would do, eg, 74LS138, 74HC138 etc.
To form a numeral on one of the 7-seg displays, it has to have some or all of it's segments turned on. When a particular segment cathode is brought low, current flows through through the segment LED causing it to light. The seven segments and decimal point cathodes are all connected in parallel with the corresponding segments of all the other displays and are connected to the portB bus.
To form a "1" on display 4, for example, segments B and C corresponding to PortB bits 1 and 7 are brought low. PortA bit 2 is then brought low to select and power display 4.
The eight switches are attached to PortB. 28 times a second portB is put into a high-impedance state (input) and read in. Any switches that are down result in a zero bit.
The MAIN routine initialises the TMR0 prescaler to 1:8 (225 Hz), and PORTB pullups are enabled, and the TRIS registers are setup for the ports. Various variables are set, EEPROM is read. The program then loops continuously testing the SWITCHES variable. If any switches are down then the program carries out the corresponding function and returns back to the loop.
The main loop is interrupted 225 times a second by the interrupt routine at 0004 which updates the display and tests the switches. If any switches are down the displays are turned OFF by turning LED2 ON. This prevents the corresponding segments of the all the displays from lighting because the switch completes the circuit. The interrupt routine also divides by 225 to produce a branch every 1 second which increments or decrements the time as well as decrementing the blanking timer.
The time is maintained in three 8 bit BCD registers. The upper 4 bits (MSN) are the TENS and the lower 4 bits (LSN) the UNITS. These three registers are saved in EEPROM whenever the counting is started. To display the time, these registers are separated into tens and units registers corresponding to the 6 LED displays. Four bits of these regs are used for the time, 1 bit is used to indicate a suppressed zero, and one to specify whether the decimal point is on or off. These registers are updated whenever a change occurs to the corresponding BCD time register.
Whenever the hours increment in clock mode a flag is set to signal chiming. The main loop tests this flag and calls the chime routine if set. Timing for the beeps and hour chimes is accomplished by a general-purpose timer register which is decremented 225 times a second by the interrupt routine. A delay routine simply loads this register and then waits for it to hit zero.
S1 = Inc hours S2 = Inc Mins S4 = Inc Secs S6 = Toggle Dis / Sel mem
S0 = Dec hours S3 = Dec Mins S5 = Dec Secs S7 = Start/Reset
S0+S1 = start clock mode S2+S3 = toggle logic out S4+S5 = Zero time
S1+S2 = toggle total blank S6+S7 = Sel mem forwards
1 x IC PIC16F84 Microprocessor
1 x IC 74LS138, 74HC138 etc.
8 x Transistors BC640, BC636, 2SA733, 2SA1015, 2SA844 ect.
2 x 1N4148 Diodes
3 x Double-Digit Common Anode 7 Segment (+dp) LED Displays (see text)
2 x Leds
1 x 1.8432Mhz Crystal
1 x Piezo Buzzer (see text)
2 x 27pf Ceramic Capacitors
2 x 1u Monolithic Capacitors
8 x 100 ohm 1/4W resistors
10 x 1k 1/4W resistors
1 x 10k 1/4W resistor
1 x 270 ohm 1/4W resistor
8 x Button Switches (see text)
1 x DPDT slide switch
1 x DIL18 IC socket
1 x 4 pin socket
1 x 4xAA battery holder
4 x AA Batteries
1 x PC Board 110x74mm
Making PC Boards
| PICOVER.GIF | - The PCB overlay diagram for parts placement. |
| PTIMERC.GIF | - Full-sized circuit diagram for printing at 300 dpi. |
| PICPCB.GIF | - Full-sized Copper-Side PCB pattern for printing at 300 dpi. |
| PICTIMER.ASM | - The source code in A84 format. |
| PICTIMER.GIF | - Operational Layout diagram |
| PICTIMER.ZIP | - All files plus the original CorrelDraw files. |