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 programmer, El-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