A. PREFACE
This project comes to mind when my sister ask me to make the clock for her new car, because her old car has a digital display on the dash board. Actually she already had a digital clock, but the display shown on LCD black and white type using a small battery. It's quiet hard to see it when it becomes dark along the journey to back home from the office at noon. It is quiet difficult to search the clock that using a usual LED display at the market. Besides that I am very pleasure to play with the microcontroller itself. So the project begin.
As usual I start it using the PIC microcontroller type, because it is simple enough and the pins is perfect to do the job. By the time of my work and my spare time, the project is on and off for a few times, and then its done. First the design only have the criteria like these :
It must have a real time clock inside It must have a battery back up to retain the time It must have capability to drive 7-segmen display to shown hours and minutes at least It must have buttons to set the time It must have to powered from a car battery voltage
Clock circuitry must not too complex to reserve low power by using a backup battery. It is the most important things at all, because we don't want to bother by this device in fact.
B. SCHEMATIC
I already had an experiment before, when I made a 24 hour timer project. So it was not to difficult to make some changes from it. First design, I plan to make 2 buttons, 1 for function select and another for increment the time. Then for the output driving I will use four 7-segmen LED display with multiplexing. It also needs an indicator to sign the seconds blink. I am a little to far, when I add the function of alarm system. It takes 1 buzzer output and 1 led sign when alarm works or not. Because I think that, it is the perfect time to experiment with this option any way. I will use the very common family of PIC micro, ie : 16F84/A, because this is the most popular type and very simplest used and very much used. Also can be obtained easily in the market. Recently the type 16F628 also easy to find (more powerful than before but with the same price). PIC16F84/A is the medium type of PIC micro family. It has 1kByte of memory (EEPROM type) and 13 I/O pins. It can be reprogrammable thousands times. Because the I/O just only 13 pins and it can be configured as input pin or output pin bit-ly. Free use of these pins. By selecting the proper pin of PIC micro, the I/O map is like these :
I/O port A-0 = Function Select button (Input) I/O port A-1 = Increment button (Input) I/O port A-2 = Led indicator sign for second blink (Output) I/O port A-3 = Led indicator sign for alarm on/off (Output) I/O port A-4 = Buzzer sound (Output) I/O port B-0 ~ B-3 = BCD number (Output) I/O port B-4 ~ B-7 = 4-Digit 7-segmen common anode (Output)
Also integrated power supply to run it modularly from a car battery
So the schematic are like this (PIC_ClockS.sch, PIC_Clock_Sch.pdf).
C. LAYOUT
I already design the PCB for this purpose, not to good but run well. Better to concentrate to the software and experiment itself. Here is one of PCB prototype. The power supply already include in the PCB design. Just connect it to car power battery. The PCB separate in 2 pieces. One for the circuitry and another for 7-segmen display. Some connection for 7-segmen have flying wires. This piece also act as the front panel.
Here is the PCB layout (PIC_ClockP.pcb, PIC_Clock_Layout.pdf, PIC_Clock_Artwork.pdf).
D. PART LIST
Here are the part list for this clock circuit :
1. Resistors :
R1 ~ R7 = 470 Ohm, 1/4W, 5% ................................ 7 pcs
R8 ~ R11 = 2k2 Ohm, 1/4W, 5% ............................... 4 pcs
R12 ~ R14 = 10k, 1/4W, 5% .................................. 3 pcs
R15 ~ R17 = 1k, 1/4W, 5% ................................... 3 pcs
2. Capasitors : C1 ~ C2 = 22 pF (for oscillator) ........................... 2 pcs C3 = 100 nF (for IC decoupling, used as necessary).......... 1 pcs C4 = 1000 uF/ 25 V ......................................... 1 pcs
3. Semiconductors : IC1 = PIC16F84/A (PIC microcontroller) .................... 1 pcs IC1 optional = PIC16F628 (PIC microcontroller) alt ......... 1 pcs IC2 = 74LS247 (7-segmen driver) ............................ 1 pcs IC3 = 7805 (Voltage regulator) ............................. 1 pcs Q1 ~ Q4 = BC558B (PNP transistor) .......................... 4 pcs Q5 = BC548B (NPN transistor) ............................... 1 pcs D1, D2 = 1N914 (Silicon diode) ............................. 2 pcs D3 = 1N4007 (Silicon diode) ................................ 1 pcs DS1 ~ DS4 = 7-segmen common anode .......................... 4 pcs LED1 ~ LED3 = 3mm, Red, Grn (For indicator) ................ 3 pcs
4. Others : X1 = 4 MHz (Clock Crystal oscillator) ...................... 1 pcs Optional IC socket for 18-pins (use 20-pins) ............... 1 pcs Optional IC socket for 16-pins ............................. 1 pcs Optional terminal connector CON1 ~ CON2 = 2 pin (power) .... 2 pcs S1 ~ S2 = Miniature push button (Push on) .................. 2 pcs Bz1 = Miniature buzzer 5V-DC ............................... 1 pcs
E. FIRMWARE
First firmware design, I use cheap clock oscillator (32.768 kHz) type, like static clock design, create by : Myke Predko. But not success, the interrupt timer I create, cannot supplied the real times for multiplexing the display. Then I change clock oscillator using regular 4 MHz x'tal. With this type, I can create 1 millisecond timer interrupt. From that then the multiplexing digit could be done. The firmware write in ASM type. I tried to write in PICCLite version (a free limited version C language compiler) from Hi-tech software, but the display had a distortion badly, I could not fix that problem yet. For you who want to modified the routine, must have the ability to understand the free MPLAB assembler compiler also. As usual I use my PIC programmer, El-Cheapo to program the chip. Note that the compiled hex file is for the PIC16F84/A type. For PIC16F628 you must change the proper lines.
For this clock algorythm, I make the sequence like these :
Real time clock run using TMR0 interrupt timer 1 msec. (modulo 4) There are 6 states made by Function Select button consecutively roll over, ie;
State 1 - Normal Clock operation, just display the hours and minutes State 2 - Setting Clock hour, display only clock hour number part State 3 - Setting Clock minute display clock minute number part State 4 - Setting Alarm sign on/off State 5 - Setting Alarm time hour part, display only hour number part State 6 - Setting Alarm time minute part, display only minute number part Minute or hour number count up by pressing increment button Clock setting to set the real time clock Alarm time setting to set when the buzzer output on Number are shown in multiplexing 4-digits 7-segmen display
A little explanation for the interrupt timer and my RTC algorythm. Interrupt occur every 1024 usecs in fact, by use x'tal = 4 MHz, div by pre-scaler (4096) is about 976,5625 Hz. This is not exactly about 1000 usecs, so by rounded the numbers, the rest is about 9 interrupt for every 16 secs, this will keep the time to be accurate. Display time using multiplexing, about 976/4 times per sec, and blink rate about 976/32 times per sec. Response button set to about 1 sec per changes as the second routine update, so the number not to fast to change over and eliminate bounce (bounce less).
- 1 sec = 1/1024 = 976.5625 interrupts, rounding it equal = 976 interrupts
- 16 secs = 976.5625 x 16 = 15625 interrupts, round the number = 976 x 16 = 15616 interrupts
- Error about = 15625 - 15616 = 9 interrupts every 16 secs
- 15616 / 9 = 1735.111111 ... , rounding it equal = 1735 times
- Error = 15625 - (1735 * 9) + (9 * 1) = 15625 - 15624 = 1, every 1735 interrupts add 1, and every 9 times 1735 add 1
- The problems is at the end of 9 times of group 1735 there is 2 count rather than 1 additional interrupt. So the error maybe still 1 interrupt every ??? times interrupts occur, when the mili_seconds variable is already zero, by dec. it the count may jump to the next second. So it's better to eliminate this count (1024 usecs) rather than 1 second error.
- By using a small iteration program, I got the specific number when the state happen. So the error about once every 3195 secs + 354x(976.5625uS), or once every 3195.345703125 secs (53.25576171875 mins), the percentage is about = 0.305620296 e-6 % or 19.19 secs faster a year. Note that this error not included instruction latency time else where. A little differences from myke design at least.
Here is the firmware : Digital Clock (Clock_2.asm, Clock_2.hex).
F. PROTOTYPE
Here are my prototypes board look like:
G. MINIMUM CLOCK DESIGN
Last searching the net for digital clock using PIC series, a bunch designs comes up, but I found one design with minimum system inside, Jose Pino's design. The design is more about crucial for me, cheap and dirty design, but it run well. A pity he doesn't give the source code also, only the hex file for PIC series. So by making some changes to my firmware itself, it give the result with modified Pino design. Running the clock would rise about 25 mA, while in sleep mode (battery back-up) it took only 3 mA. A perfect clock design! Thank's to Pino!
H. SCHEMATIC
I make some changes to the original design. Added the power back-up battery circuitry and input sensing for power failure. All the other is still the same as original.
Here is the minimum clock schematic (Min_ClkS.sch, Minimum_PIC_Clock_Sch.pdf).
No comments:
Post a Comment