24 Hours Timer using PIC-16F84A microcontroller (PART-1)



A. PREFACE

        I use an electromechanical timer (OMRON) in my house to turn on the front lamp automatically at night. The timer use a mechanical gear to drive the setting. Recently this timer may start to worn out. The time not accurate any more. It must be set a lot and a lot. I become boring to set it day by day. So I start to think that I want to build it using a microcontroller. As usual I start it with my own knowledge and from reference. I think that I will build it using PIC microcontroller type. At last this project could be done during National day Idul Fitri 2008. I have a week working day vacation. So I start with this exiting electronic experiment pleasantly.
        The timer that I want to build must have 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 at least 220V/3A load
  • It must be set to on the output at any time
        Timer will function like a clock, and have a setting time to maintain the clock, also have a setting time for the output relay when to be on or off during an interval time of period, besides that the circuitry must not too complex to reserve low power by using a backup battery.

B. SCHEMATIC

        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 a power relay. It also needs an indicator to know that the time works or not, I need a visual display. For this purpose I will use led to sign the time and to display the number also. To reduce component using and power, I don't use a 7-segmen type. I will use the very common family of PIC micro, ie : 16F84/A, because this is the most popular type and very simples 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 (Output)
  • I/O port A-3 = Led indicator (Output)
  • I/O port A-4 = Driving Relay (Output)
  • I/O port B-0 ~ B-7 = Number indicator (Output)
  • Also integrated power supply to run it modularly
        So the schematic are like this (TimerS.sch, TimerS.pdf).

C. LAYOUT



        Since this is an experiment project, I don't make the PCB design more detail. I think that I must make it as fast as possible, so I can concentrate to the software and experiment itself. Here is one of PCB prototype. Note that the power supply not include in the PCB design.






Here is the PCB layout (TimerP.pcb, TimerP.pdf, TimerP_Artwork.pdf).

D. PART LIST

        Here are the part list for this timer controller :
   1. Resistors :      R1 ~ R8, R11 ~ R13 = 1k, 1/4W, 5% ......................... 11 pcs
      R10 = 4k7, 1/4W, 5% ........................................ 1 pcs
      R9, R14, R15 = 10k, 1/4W, 5% ............................... 3 pcs
   2. Capasitors :      C1 ~ C2 = 27 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
      IC2 = 7805 (Voltage regulator) ............................. 1 pcs
      Q1 = C1061 or H1061 (Power NPN transistor) ................. 1 pcs
      Q1 (alt) = BC548B (NPN transistor) output up to 25 mA ...... 1 pcs
      D1, D2 = 1N914 (Silicon diode) ............................. 2 pcs
      D3, BD = 1N4007 (Silicon diode) ............................ 5 pcs
      LED1 ~ LED11 = 3mm, Red, Yel, Grn (For indicator) ......... 11 pcs
   4. Others :      X1 = 32.768 kHz (Clock Crystal oscillator) ................. 1 pcs
      Optional IC socket for 18-pins (use 20-pins) ............... 1 pcs
      Optional terminal connector CON1 ~ CON4 = 2 pin (power) .... 4 pcs
      S1 ~S2 = Miniature push button (Push on) ................... 2 pcs
      TR1 = Miniature transformer, P-220V/S-12V, 100 mA .......... 1 pcs
      RL1 = 12V Power Relay (output 220V-AC/3A) .................. 1 pcs

E. FIRMWARE

        First firmware design, I use static clock design, create by : Myke Predko. I already built his static clock design, and the time was precisely accurate. By change some routine to fit the above purpose, the firmware could be done. But the firmware in ASM type. 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.

        For this timer algorythm, I make the sequence like these :

  • Real time clock run using TMR0 interrupt timer 1 sec. (modulo 32)
  • There are 7 states made by Function Select button consecutively roll over, ie;
    • State 1 - Normal Clock operation, just display the hours and minutes in interval 2 sec.
    • State 2 - Setting Clock hour, display only clock hour number part
    • State 3 - Setting Clock minute, display clock minute number part
    • State 4 - Setting Time-On set, display hour number part
    • State 5 - Setting Time-On set, display minute number part
    • State 6 - Setting Time-Off set, display hour number part
    • State 7 - Setting Time-Off set, display minute number part
  • Each state pair indicates by 2 output leds
  • Minute or hour number count up by pressing increment button
  • Clock setting to set the real time clock
  • Time-On setting to set the time when relay output on
  • Time-Off setting to set the time when relay output off
  • Number are show in BCD format in 2-digits
        After power on, the state goes to normal operation. This run the clock (RTC). 2 leds indicator are blink for 1 Hz in turns. Output number indicator will display the hour count or minute count for 2 Hz in turns (ie; 12:45 - will showed 0001-0010 and 2 sec later 0100-0101). Each time Function Select button is pressed, state change consecutively in order. Each state displayed the hour count or minute count number. In these state, increment button can be used to change the count number to match the time set. Then pressed the Function Select button will roll over to state 1 again (normal operation). That's all ...!!! Very simple, isn't it ...???



Here is the firmware : Timer controller (Timer.asm, Timer84.hex, Timer628.hex).

        I used 24 hours timer with satisfy enough, but after a year or two then the time late a few minutes. I make a new improvement to the firmware, using one sec. bresenham algorithm from Roman Black. The new firmware use a higher x'tal clock, using 4 MHz clock. This is more reliable I think. Then I make 2 of them to used. The new timer still in an experiment time limit now.

Here is the firmware using one sec. algorithm (Timers.asm, Timers.hex). This time I use PIC16F628/A type.

F. PROTOTYPE

        I got an old tv fm booster power supply, not used anymore. This box has a perfect transformer (220V to 12V, 100mA power about 1 Watt) and also the box too. So I used it to mount all the rest part in it. Here are my prototypes controller board looks like:










  Too easily mounting the leds indicator, I put all to a small piece of PCB then screw it to the box, with caps cover. Experiment running using 2 - AA 1.5V type battery, but then change later to maxell - micro lithium battery CR1220 - 3V battery. It can run well.






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