Design and Development of Microcontroller Based Programmable Timer for Supply Control Md. Shahzamal, Mohammad Abu Sayid Haque, Md. Nasrul Haque Mia, Md. Anzan-Uz-Zaman, Sardar Masud Rana, Mahbubul Hoq, Fahmida Akter, Farhana Hafiz, Mahmudul Hasan NUCLEAR ELECTRONICS DIVISION NOVEMBER 2013 INSTITUTE OF ELECTRONICS ATOMIC ENERGY RESEARCH ESTABLISHMENT SAVAR, GPO BOX 3787, DHAKA-1349, BANGLADESH evsjv `k cigvyy kw³ Kwgkb BANGLADESH ATOMIC ENERGY COMMISSION
Edited by: Mahbubul Hoq Yasmeen Maula Mohammod Abu Sayid Haque Published by: Institute of Electronics Atomic Energy Research Establishment Ganakbari, Savar, Dhaka Bangladesh Atomic Energy Commission Printed by: Scientific Information Unit Atomic Energy Research Establishment Ganakbari, Savar, Dhaka Bangladesh Atomic Energy Commission
Design and Development of Microcontroller Based Programmable Timer for Supply Control *Md. Shahzamal 1, Mohammad Abu Sayid Haque 1,, Md. Nasrul Haque Mia 1,Md. Anzan-Uz-Zaman 1, Sardar Masud Rana 1, Mahbubul Hoq 1, Fahmida Akter 1, Farhana Hafiz 1, Mahmudul Hasan 2 1 Institute of Electronics, Atomic Energy Research Establishment, Savar, Dhaka, Bangladesh 2 Atomic Energy Research Establishment, Savar, Dhaka, Bangladesh Abstract: Timers are frequently used in the industries to run process/operation with predefined time interval. The most popular type of timer is the programmable timer that has various facilities to configure the timer by users. However, it is expensive to build such timer using ICs and discrete components. Moreover, when programmable timer is used for laboratory instruments, it is expected to be flexible to handle. Microcontroller has the potential to solve these constraints. In this development work, we have developed a microcontroller based programmable timer with digital display system that can be configured to connect the AC main line to the instruments for a specific time interval. This device can function in two modes: manual mode and programmable mode. In the programmable mode, the device connects AC main line to the power outlet for a set interval. The device has been designed and tested in the laboratory. Keywords: Timer, Microcontroller, A. C supply and Display System. I. INTRODUCTION Timers that schedule an event according to a predefined time value in the future are an integral part of many real-time embedded systems, similar to setting an alarm clock. They find applications in the control of sequential functions of industrial machinery at varying time intervals, in the laboratory to power instruments for a specific time and perform processes for a specific duration. Usually, two kind of timer are frequently used in various applications such as mechanical and electronic timers. Electronics timers are manufactured today to meet the complex function of industries. The Electronic timer consists of a crystal controlled stable oscillator, sequencing logic circuits, driving circuits and a digital display system with a facility depends on the application for connecting the output to individual machinery/system to control the operation at pre-determined time interval. ---------------------------------------- *Corresponding Author: Md. Shahzamal, Scientific Officer Institute of Electronics, AERE, Savar, Dhaka, Bangladesh E-mail: zamal.iebaecbd@gamil.com, Phone: 88-027788250, Mob: 880191295235. Page 1 of 7
The timers which can be configured to set time interval is called programmable timer. The programmable timer is usually designed with different functions that would be flexible to customize by the users. To build such timer, many ICs and components are required. Therefore, manufacturing cost prohibit deploying programmable timer in many applications. Moreover, when programmable timer is used in laboratory, it should be sophisticated. In this development work, we have developed a microcontroller based programmable timer with digital display system. It works in two modes: manual mode and programmable mode. In manual mode, it can function like switch board. In the programmable mode, user can set the time how long AC main line could be connected to the power outlet. Then, it is disconnected automatically. The time is set for hours, minutes and seconds i.e. the time format is HH:MM: SS. Therefore, the maximum time would be 99h: 59m: 59s. The remaining time is shown on the display system designed with six seven-segment LEDs. This paper is organized as follows. In the section-ii, we have discussed about hardwire designing and software developing. We have presented timing performance in the section-iii and section-iv concludes our development work. II. DESIGN AND DEVELOPMENT Figure-1 shows the functional unit of the developed system. The first block is the switching unit that is used to change the operation mode of the system. It can change the system form manual mode to programmable mode. In the programmable mode, the system requires power supply to operate the circuit. This is done in the programmable circuit enable unit. Then, the time interval that the AC supply is continued is set through the push switches. The microcontroller receives the value of time and process to prepare the 16-bit timer that is integrated with the microcontroller. Finally, the relay circuit is energized for the predefined time. As a result, the AC main line connects to the power outlet. The remaining time is presented continuously on the LEDs based seven segment display system. The system can be reset pushing the timer start switch. Figure-2 shows the circuit diagram of the developed system. The working principle of the system is described in the following paragraphs. Figure-1: Functional Diagram of the Developed System. Page 2 of 7
A. Switching Options A two way contact switch has been used to change the operation mode. One wire is connected to the input of the switch. But, one connection is permanently connected in the both modes. When it is in the position of manual mode, the circuit connection to the socket is established with another manual contact switch. Figure-2: Circuit Diagram of the Developed System. B. Power Supply When the two way contact switch is connected to the programmable mode, the circuit is powered with a power supply that enables the programmable mode operation. This is constructed with a step down transform and a bridge rectifier. The output of the rectifiers is filtered with a combination of capacitor and resister. This produces a positive DC voltage with small amount of ripple. This voltage is passed through a regulator IC-7812 and +12V is derived from the output. The IC-7812 is protected with a reverse connected diode. The output voltage is filtered using a small capacitor. This +12V is used to operate relay. This output again is fed to input of IC-7805 and +5 V is obtained as output. This voltage is supplied to operate the microcontroller. C. Microcontroller PIC-16F72 Most of the task of the developed programmable timer is done using the microcontroller PIC-16F72. It has 2K x 14 words of FLASH Program Memory and 128 x 8 bytes of Data Memory (RAM) [3]. The operating frequency could be up to 20 MHz. It has three I/O ports named PORTA, PORTB and PORTC. PORTA is a 6-bit wide, bi-directional port. PORTB and PORTC are also a bi-directional, but 8-bit wide. Some pins for these I/O ports are multiplexed with an alternate function for the peripheral features on the device. In general, Page 3 of 7
when a peripheral is enabled, the pin may not be used as a general purpose I/O pin. The microcontroller has three timers: two 8-bit timers and one 16-bit timer. These timers can work counter as well when external clock is supplied to the respective pins while timers operate with the internal oscillator. D. Timer Operation Controller The operation of the programmable timer is controlled through the four pins of PORTB (RB7, RB6, RB5 and RB4). These pins have an interrupt-on-change feature. Only pins configured as inputs can cause this interrupt to occur. The input pins (of RB7:RB4) are compared with the old value latched on the last read of PORTB. The mismatch outputs of RB7:RB4 are OR d together to generate the RB Port Change Interrupt with flag bit RBIF (INTCON <0>). A mismatch condition will continue to set flag bit RBIF. Reading PORTB will end the mismatch condition and allow flag bit RBIF to be cleared. We have connected four push switches to enter the instructions to the microcontroller, as shown in figure-3. Switch-1 connected with RB4 is the set/reset switch. When the switch is pressed, the operation of entering time begins or reset entering time. The switch-2 is used to select which digit will be incremented. SW-3 is used to increment the value of the digit selected by the SW-2. If the digit is incremented above the maximum value for that digit, then it resets to zero again. SW-4 starts timer and displaying remaining time. After pushing this switch, the program transfer to timer configuration subroutine and start timer operation. We have developed a subroutine, named scanning switches and actions, to perform these operations. The follow chart is shown in the figure-4. This subroutine is executed with RB Port Change Interrupt. It also includes the de-bounce steps to avoid the unnecessary interrupt. This program receives the value of time interval and necessary instruction to start timing. Figure-3: Operation Controlling Switches. Figure-4:Flow Chart for Actions of Switches. Page 4 of 7
E. Timer Configuration The Timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (TMR1H and TMR1L), which are readable and writable. The TMR1 Register pair (TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. The TMR1 Interrupt, if enabled, is generated on overflow, which is latched in interrupt flag bit TMR1IF (PIR1<0>). This interrupt can be enabled/disabled by setting/clearing TMR1 interrupt enable bit TMR1IE (PIE1<0>). In this system, we have configured timer to generate signal after every half second. Further, we have used this signal to generate tick every second. As the operating frequency of the designed circuit is 4 MHz, each instruction cycle is equal to 1 us. We have also set 1: 8 presale values that divide the clock by 8. Therefore, to generate timer overflow after every half second the number of increments would be, = 62500 Thus, the timer will rolls over after half second if it starts to increment from 65553-62500= 3035=0BDB. This is done reloading TMR1L with DB and RMR1H with 0B. Figure-5 shows the flowchart for fixing remaining time. After every overflow, TMR1 Register pair rewrites. A noticing signal is produced to decrement the least significant digit. Next digits are adjusted after every decrement. The updated value is presented on the display system. Figure-5: Remaining Time Calculation Flowchart. Figure-6: Relay Driving Circuit F. Relay Driving Circuit The AC line is controlled through a relay based circuit as shown in figure-6. The microcontroller set high pin RB3 to connect AC to the outlet. The RB3 provide the bias current to the driving transistor and energized the relay to establish connection. This pin is kept high until every digit of remaining time becomes zero. A LED diode has been connected to show the status of the timer. The rectifier diode avoids the unwanted firing of relay. Page 5 of 7
G. Display System The time setup is monitored observing the entered digit on the display. The display system also shows the remaining time. The display system has been constructed using seven segment LEDs. A register memory is assigned to control the glow of LEDs for each segment. The register value is found out through different subroutines. The controlling subroutine selects the appropriate pattern for each digit to be displayed. Each digit is displayed applying time division technique. One segment is powered for a fixed interval and then turn off to power other segments. However, the data bus is common for all segments. III. RESULT AND DISCUSSION The system has two parts: 1) Designing Hardware Circuit and 2) Designing required Software. The system has been designed and tested successfully in the laboratory. The developed system is very cheap and flexible. The maximum time that can be set is 99H: 59M: 59S. As the time setting is independent of the ability of the timer of microcontroller, the system can be run for the maximum time perfectly. The picture-1 shows our developed board. The timing accuracy has been presented in the following Table-1. Table-1: Comparison of timing with standard watch. Observation No. Set time for the Timer Time passed in the standard watch Differences In Seconds 01 00:05:00 00:04:58-02 02 00:20:00 00:10:02 +02 03 00:30:00 00:20:00 00 04 00:40:00 00:40:00 00 05 00:50:00 00:50:01 +01 06 01:00:00 01:00:00 00 Picture-1: Developed Programmable Timer. Figure-7: PCB for the Developed System Page 6 of 7
IV. CONCLUSSION We have successfully developed a prototype of a programmable timer. The developed system is very useful to run an instrument for a specific time interval. The timing is very precise as the system has been developed by the microcontroller. The performance of the system depends on the loads in many cases. The programmable timer has limited functions. In future, the system would be upgraded adding new functions such as periodic ON/OFF. REFERENCES [1] Electronic Industrial Timers, www.dcmsme.gov.in/publications/pmryprof/it/ch8.pdf [2] Jonathan Gana KOLO and Umar Suleiman DAUDA, Development of a Simple Programmable Control Timer, Leonardo Journal of Sciences, Issue 12, January-June 2008, p. 175-186. [3] Data Sheet of Pic-16F72, ww1.microchip.com/downloads/en/devicedoc/39597b.pdf [4] Introduction to Embedded Programming - Timers, www.scriptoriumdesigns.com/embedded/timers.php [5] Y. K. Woo, Timer and Timer Services, www.csie.dyu.edu.tw/~swang/rtos/l11.pdf [6] Mitesh P. Parikh, programmable timer for appliances, www.electronicsforu.com/efylinux/circuit/.../ci-01-prog-timer.pdf [7] A Digital Timer Implementation using 7 Segment Displays, www.users.cecs.anu.edu.au/~salman.durrani/_teaching/tb5.pdf Page 7 of 7