Digital clock with PIC series microcontroller (PART-1)

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

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







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


No comments:

Post a Comment

Labels

PROJECTS 8086 PIN CONFIGURATION 80X86 PROCESSORS TRANSDUCERS 8086 – ARCHITECTURE Hall-Effect Transducers INTEL 8085 OPTICAL MATERIALS BIPOLAR TRANSISTORS INTEL 8255 Optoelectronic Devices Thermistors thevenin's theorem MAXIMUM MODE CONFIGURATION OF 8086 SYSTEM ASSEMBLY LANGUAGE PROGRAMME OF 80X86 PROCESSORS POWER PLANT ENGINEERING PRIME MOVERS 8279 with 8085 MINIMUM MODE CONFIGURATION OF 8086 SYSTEM MISCELLANEOUS DEVICES MODERN ENGINEERING MATERIALS 8085 Processor- Q and A-1 BASIC CONCEPTS OF FLUID MECHANICS OSCILLATORS 8085 Processor- Q and A-2 Features of 8086 PUMPS AND TURBINES 8031/8051 MICROCONTROLLER Chemfet Transducers DIODES FIRST LAW OF THERMODYNAMICS METHOD OF STATEMENTS 8279 with 8086 HIGH VOLTAGE ENGINEERING OVERVOLATGES AND INSULATION COORDINATION Thermocouples 8251A to 8086 ARCHITECTURE OF 8031/8051 Angle-Beam Transducers DATA TRANSFER INSTRUCTIONS IN 8051/8031 INSTRUCTION SET FOR 8051/8031 INTEL 8279 KEYBOARD AND DISPLAY INTERFACES USING 8279 LOGICAL INSTRUCTIONS FOR 8051/8031 Photonic Transducers TECHNOLOGICAL TIPS THREE POINT STARTER 8257 with 8085 ARITHMETIC INSTRUCTIONS IN 8051/8031 LIGHTNING PHENOMENA Photoelectric Detectors Physical Strain Gage Transducers 8259 PROCESSOR APPLICATIONS OF HALL EFFECT BRANCHING INSTRUCTIONS FOR 8051/8031 CPU OF 8031/8051 Capacitive Transducers DECODER Electromagnetic Transducer Hall voltage INTEL 8051 MICROCONTROLLER INTEL 8251A Insulation Resistance Test PINS AND SIGNALS OF 8031/8051 Physical Transducers Resistive Transducer STARTERS Thermocouple Vacuum Gages USART-INTEL 8251A APPLICATIONs OF 8085 MICROPROCESSOR CAPACITANCE Data Transfer Instructions In 8086 Processors EARTH FAULT RELAY ELECTRIC MOTORS ELECTRICAL AND ELECTRONIC INSTRUMENTS ELECTRICAL BREAKDOWN IN GASES FIELD EFFECT TRANSISTOR (FET) INTEL 8257 IONIZATION AND DECAY PROCESSES Inductive Transducers Microprocessor and Microcontroller OVER CURRENT RELAY OVER CURRENT RELAY TESTING METHODS PhotoConductive Detectors PhotoVoltaic Detectors Registers Of 8051/8031 Microcontroller Testing Methods ADC INTERFACE AMPLIFIERS APPLICATIONS OF 8259 EARTH ELECTRODE RESISTANCE MEASUREMENT TESTING METHODS EARTH FAULT RELAY TESTING METHODS Electricity Ferrodynamic Wattmeter Fiber-Optic Transducers IC TESTER IC TESTER part-2 INTERRUPTS Intravascular imaging transducer LIGHTNING ARRESTERS MEASUREMENT SYSTEM Mechanical imaging transducers Mesh Current-2 Millman's Theorem NEGATIVE FEEDBACK Norton's Polarity Test Potentiometric transducers Ratio Test SERIAL DATA COMMUNICATION SFR OF 8051/8031 SOLIDS AND LIQUIDS Speed Control System 8085 Stepper Motor Control System Winding Resistance Test 20 MVA 6-digits 6-digits 7-segment LEDs 7-segment A-to-D A/D ADC ADVANTAGES OF CORONA ALTERNATOR BY POTIER & ASA METHOD ANALOG TO DIGITAL CONVERTER AUXILIARY TRANSFORMER AUXILIARY TRANSFORMER TESTING AUXILIARY TRANSFORMER TESTING METHODS Analog Devices A–D BERNOULLI’S PRINCIPLE BUS BAR BUS BAR TESTING Basic measuring circuits Bernoulli's Equation Bit Manipulation Instruction Buchholz relay test CORONA POWER LOSS CURRENT TRANSFORMER CURRENT TRANSFORMER TESTING Contact resistance test Current to voltage converter DAC INTERFACE DESCRIBE MULTIPLY-EXCITED Digital Storage Oscilloscope Display Driver Circuit E PROMER ELPLUS NT-111 EPROM AND STATIC RAM EXCITED MAGNETIC FIELD Electrical Machines II- Exp NO.1 Energy Meters FACTORS AFFECTING CORONA FLIP FLOPS Fluid Dynamics and Bernoulli's Equation Fluorescence Chemical Transducers Foil Strain Gages HALL EFFECT HIGH VOLTAGE ENGG HV test HYSTERESIS MOTOR Hall co-efficient Hall voltage and Hall Co-efficient High Voltage Insulator Coating Hot-wire anemometer How to Read a Capacitor? IC TESTER part-1 INSTRUMENT TRANSFORMERS Importance of Hall Effect Insulation resistance check Insulator Coating Knee point Test LEDs LEDs Display Driver LEDs Display Driver Circuit LM35 LOGIC CONTROLLER LPT LPT PORT LPT PORT EXPANDER LPT PORT LPT PORT EXTENDER Life Gone? MAGNETIC FIELD MAGNETIC FIELD SYSTEMS METHOD OF STATEMENT FOR TRANSFORMER STABILITY TEST METHODS OF REDUCING CORONA EFFECT MULTIPLY-EXCITED MULTIPLY-EXCITED MAGNETIC FIELD SYSTEMS Mesh Current Mesh Current-1 Moving Iron Instruments Multiplexing Network Theorems Node Voltage Method On-No Load And On Load Condition PLC PORT EXTENDER POTIER & ASA METHOD POWER TRANSFORMER POWER TRANSFORMER TESTING POWER TRANSFORMER TESTING METHODS PROGRAMMABLE LOGIC PROGRAMMABLE LOGIC CONTROLLER Parallel Port EXPANDER Paschen's law Piezoelectric Wave-Propagation Transducers Potential Transformer RADIO INTERFERENCE RECTIFIERS REGULATION OF ALTERNATOR REGULATION OF THREE PHASE ALTERNATOR Read a Capacitor SINGLY-EXCITED SOLIDS AND LIQUIDS Classical gas laws Secondary effects Semiconductor strain gages Speaker Driver Strain Gages Streamer theory Superposition Superposition theorem Swinburne’s Test TMOD TRANSFORMER TESTING METHODS Tape Recorder Three-Phase Wattmeter Transformer Tap Changer Transformer Testing Vector group test Virus Activity Voltage Insulator Coating Voltage To Frequency Converter Voltage to current converter What is analog-to-digital conversion Windows work for Nokia capacitor labels excitation current test magnetic balance voltage to frequency converter wiki electronic frequency converter testing voltage with a multimeter 50 hz voltages voltmeter

Search More Posts

Followers