PIC Digital Clock

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 :

        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 :

        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.

Digital Clock PCB Layout

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 programmerEl-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 :

        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).

Here is the firmware : Digital Clock (Clock_2.asm, Clock_2.hex).

F. PROTOTYPE

        Here are my prototypes board look like:

Digital Clock when running ... PCB circuitry layout
Development phase using battery back-up Display board, some of flying wires

        Experiment running using 2 - AA 1.5V type battery, but I will change later to maxell - lithium battery CR2025 - 3V battery. It can run well.

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).

I. LAYOUT

        I make the PCB design for this clock, it's small enough and have size about 4.5 x 4.5 cm. For the display, I use a small type 7-segmen, so the device can be mounted in a small box.

Jose Pino's Digital Clock Design Layout

Here is the PCB design for Pino's clock (Min_ClkP.pcb, Minimum_PIC_Clock_Layout.pdf, Minimum_PIC_Clock_Artwork.pdf)

J. PART LIST

        Here are part list for Pino's clock circuit :

   1. Resistors :

      R1 = 220 Ohm, 1/4W, 5% ..................................... 1 pcs
      R2 ~ R5 = 10k, 1/4W, 5% .................................... 4 pcs
      R6 = 4k7, 1/4W, 5% ......................................... 1 pcs
      R7 = 100 Ohm, 1/4W, 5% ..................................... 1 pcs
   2. Capasitors :

      C1 ~ C2 = 33 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 = 7805 (Voltage regulator) ............................. 1 pcs
      D2 = 1N914 (Silicon diode) ................................. 1 pcs
      D1, D3 = 1N4007 (Silicon diode) ............................ 2 pcs
      DS1 ~ DS4 = 7-segmen common anode (FJ3161 mini) ............ 4 pcs
      LED1 = 3mm, Red (For indicator) ............................ 1 pcs
   4. Others :

      X1 = 4 MHz (Clock Crystal oscillator) ...................... 1 pcs
      Optional IC socket for 18-pins (use 20-pins) ............... 1 pcs
      Optional terminal connector CON1 ~ CON2 = 2 pin (power) .... 2 pcs
      S1 ~ S2 = Miniature push button (Push on) .................. 2 pcs

K. FIRMWARE

        Original Pino's design included with hex file for PIC16F84/A or PIC16F628 type. Both file could be downloaded at his page (PIC16F84/A and PIC16F628). The firmware run well. I make my own firmware, by modified the above version. All is still the same except that the display now has it's own generated code BCD to 7-segmen driver. Note that the hex file is for PIC16F84/A type. for another type please change the proper lines.

Here is my own firmware to run Pino's digital clock (Clk_Min.asm, Clk_Min.hex).

L. PROTOTYPE

        Here are my prototype for Pino's clock design :

Pino's Minimum Clock design Copper trace layout Display panel, see the minutes digit in reverse position
Prototype test with back-up battery After put it in a box, dots sign as second blinking indicators Running test phase

M. IMPLEMENTATION

        Pino's design more simple than mine. So this project end with the choose of his clock. Here is the implementation of my prototype, for the car's clock. The car power taken from the car's lighter. My design will be expanded to another purpose like desk clock for example. The alarm routine not develop yet. Much more we can do from that point, eg: snooze routine, song for the alarm chime, recurrent alarm, etc. May be for next project development. Happy programming!

Clock position in the CD slot The power taken from car's lighter Clock view from avanza dash board
A little hard to see in day light More clearly in the dark

N. FEEDBACK

        Some people build my PIC digital clock, but not satisfy with the result. Here are a few feedback from them ask to improved or modified some of the clock functional running;

  1. Make it run for only 12 hours clock (not 24 hours version). So here is the modified version. This version first asked by Ashwani K.who built it but did not satisfy with the displayed.

  2. Make the first digit unseen while the hours still below 10 o'clock (only just 1 digit displayed), like 9:23  instead of 09:23. So here is the modified version. This version was asked by Michael Xie from China. He want to modify the display to use big size like this circuit. I put it in here to motivate you

  3. New version firmware for PIC digital clock, using Bresenham - 1 second algorithm base on Roman Black design. More precision now counting the clock.

  4. Unique clock design using pic digital clock firmware and universal I/O board from junk. I made a unique clock from this junk board, just to utilize the purpose. Now I have one useful device! First design using Atmel AT89S52, but a pity not successful, the refresh rate is too slow (blinking visual effect). Using PIC series much more smooth.

  5. Bill Sherman design (modified from minimum pic digital clock). He made a mayan clock system count, like the movie, predator self destructive device, very attractive and inspirative idea. What a piece of a code! Note : there's some errors in the last piece code test, but after some tried, it seem the bugs found. Please download the new update.

  6. Cseh Jozsef made some improvement from my first design of minimum pic digital clock. He added 4 sec each day passed to correct the time. Here is some improvement, and also the new firmware. Be careful that he didn't use the same wired display connection I suggested. Refer to the look up table display for the right connections. Note that, he also found some bugs, address segment for look-up table, it didn't show up for PIC16F84/A types but for PIC16F628A it would reset after 7 seconds. I  also found these bugs when modified the mayan clock before.

        Note that, I didn't test all the firmware yet, so I leave it to you then. If you find some error, please give me a report!


Create on : Mar 10, 2009
- by : David Setya Atmaja
Persons who interest so far :


HomeReturn to Main Page