Design and Construction of Microcontroller-Based Water Flow ...

10 downloads 34383 Views 533KB Size Report
Design and Construction of Microcontroller-Based Water Flow. Control System ... This type of control is often called a process control system. Process control is ...
2011 International Conference on Circuits, System and Simulation IPCSIT vol.7 (2011) © (2011) IACSIT Press, Singapore

Design and Construction of Microcontroller-Based Water Flow Control System Thwe Mu Han1, Ohn Mar Myaing 2 1 2

Computer University (Taunggyi), Myanmar Computer University (Magway), Myanmar

Abstract. Flow control is a technology resource for the fluid handling industry's critical disciplines of control, containment and measurement. It covers products, processes, and services for efficient, reliable, and cost-effective control and delivery of fluids in a variety of industries. There are many flow control mechanisms. In this system, automatic water flow control system is implemented and can be used as process control system. As sensing unit, photo interrupter and slotted disk are used to produce pulse train for frequency input of the microcontroller. The sensor signal is counted as frequency and converted to the flow rate by using the software program in PIC. This flow rate is compared to the setpoint value. The PIC16F628 can control the water valve by using DC motor to vary the water flow rate based on this comparison. This system is implemented by MPASM assembly language. This system can be applied at the turbine inlet to control the water flow rate. Two Kaplan type turbines have been constructed. To operate the turbine, the required head and discharge rate are measured. Turbine testing is made under two different heads.

1. Introduction Automatic control has played a vital role in the advance of engineering and science. It is essential in such industrial operations as controlling pressure, temperature, humidity, viscosity and flow in the process industries. The first significant work in automatic control was James Watt's centrifugal governor for the speed control of a stream engine in the eighteenth century. Other significant works in the early stages of development of control theory were due to Minorsky, Hazen, and Nyquist, among many others. In 1922, Minorsky worked on automatic controllers for steering ships and showed how stability could be determined from the differential equations describing the system. In 1932, Nyquist developed a relatively simple procedure for determining the stability of closed-loop systems on the basis of open-loop response to steadystate sinusoidal inputs. In 1934, Hazen, who introduced the term servomechanisms for position control systems, discussed the design of relay servomechanisms capable of closely following a changing input. Automatic control system is one that makes the required adjustments automatically, without human aid. It is common to separate control system descriptions into two broad categories – process control and servomechanisms – depending upon how the value of the physical variable is expected to behave in time. In many instances, the objective of a control system is to force a physical variable to remain constant in time and equal to some desired value. This type of control is often called a process control system. Process control is encountered, in automated manufacturing operations, such as in the chemical and petrochemical industries where temperatures, flow rates, levels, and so on are forced to maintain constant values. Such control is often also called regulation and the desired value is called the setpoint. Another type of control system objective is to force a physical variable to change in time, but in a precisely prescribed manner. That is, the physical variable will be forced to follow or track some target value as it changes in time. The term servomechanism is frequently used to describe such control by reference to a historical approach to providing the control. A common example of this kind of control system is in industrial robot arm motion, where the arm must follow a specific path in space as a function of time. 304

2. Construction of the Water Flow Control System 2.1. Peripheral Interface Controller (PIC 16F628) PIC controllers are a family of small RISC (Reduced Instruction Set Computer) controllers used in embedded applications. PIC controllers are produced by the company "Microchip". The newcomer PIC from Microchip Technology was developed in the late 1980s and was marketed with the two similar versions- a PROM-based version and an EPROM version. An attraction of the plastic OTP version was that it was very cheap. The EPROM version, as in all microcontrollers, is relatively expensive. This is because of the expense of the ceramic body needed to be formed around the quartz UV transparent window which is used to erase the memory. PIC microcontrollers are grouped by the size of their instruction word. The three current PIC microcontroller families are: 1. Base-line : 12-bit Instruction Word Length 2. Mid –Range : 14-bit Instruction Word Length 3. High-End : 16-bit Instruction Word Length Focuses on the Mid-Range devices are also referred to as the PIC 16CXX MCU family. The 16F62X microcontrollers are flash devices and have 18 pins and data EEPROM just like the 16F84, but they have more functions. Notably there is an on board oscillator so an external crystal is not required. This frees up two pins for extra I/O. The 16F62X in fact can use 16 of its 18 pins as I/O. PIC16F62X devices have special features to reduce external components, thus reducing system cost enhancing system reliability and reducing power consumption. The PIC16F62X have enhanced core features, eight-level deep stack, and multiple internal and external interrupt sources. Other features of the 16F62X also include: • • •

An analogue comparator module with two analogue comparators and an on-chip voltage reference module. Timer 1, a 16-bit timer/counter module with external crystal/clock capability and Timer2, an 8bit timer/counter with prescaler and postscaler. Capture, Compare and Pulse Width Modulation modes.

2.2 Implementation of the System In this system, the rate of water flow will be maintained at the desired value 25 liter per minute. This is done by adjusting a valve that controls water. Valve is connected to the DC motor shaft. DC motor can be operated on 12 volts dc. The motor is driven by driver IC TA7291P. This IC has four modes – stop, brake, clockwise (CW), counterclockwise (CCW). IC pin No. 5 and 6 get input commands from PIC 16F628. These commands are manipulated values from the controller and are applied to correct the deviation of the measured value from a desired value. When water flows through the pipe, measured value is made by an optocoupler with a slotted disk that provides a pulse train proportional to water flow. This pulse train is fed into PIC pin No.12 as a frequency input. These input frequencies within a precise range are converted into flow rate by the program.

305

+5V

12

2 RB4

RB6

RB5

10K

E

RB2 RB3

RA2

V+

PIC16F628

LIQUID CRYSTAL DISPLAY

RA6

RA7

0V

11

7

12

8

13

9

+5V

14

14

D4

INPUT FREQUENCY

D5 D6 D7

1

3

5

MOTOR DRIVER IC

4 0.1uF 5

15

16

0.1uF

RA1

4MHz

RA0

6

R/W

RB1

Vee

RB0

RA5 / MCLR

Limit SW R

RS

6

Vss

PIC16F628

10K

RA3 0.1uF

Limit SW L

4

11

LCD

4.7K

4.7K

+5V

10

Vdd

10K

330ohm

22K

+5V INPUT FREQUENCY

10p

10p

DC MOTOR

TA7291P

+5V +12V

FLOW IN

DC motor

SENSOR FLOW VALVE

Fig. 1: Complete Circuit Diagram of the System

Fig. 2: Block Diagram of the Water Flow Control System

When a control system is implemented to regulate the desired value, we describe the resulting system as a closed-loop control system. The difference between the set point value and the measured flow rate which is proportional to the input frequency is called error. After operation on the error, the controller outputs control action as the input of the driver IC TA7291P to drive the error toward zero. The complete circuit diagram of water flow control system is shown in Figure 1. Block diagram of water flow control system is shown in Figure 2. As the flow rate is under 27 L/min, the valve is opened. Control valve uses a DC motor to open or close it. Dc motor is to set the position for the flow valve. The motor is proportional, which means that it can position the valve in any position between fully opened and fully closed. The basic principle of operation for this type of motor is that its shaft will turn as long as power is applied to the motor, and the shaft will remain in position anytime power is disconnected In this system, the valve is turned in 90° to be fully opened or fully closed, two limit switches are placed 90° to each other to protect the motor damage.

2.3. Software Implementation In Figure 1, the output signal from optocoupler is used as frequency input via RB6 pin. As shown in Figure 3, ports and LCD are initialized. Decimal 10 is loaded into MEASURERATE register for frequency measurement and 5 is loaded into BLNKCNT register for motor control interval. In Figure 4, the contents of MEASURERATE are decremented. If the result is zero, MEASURERATE reloads decimal 10 and frequency measurement starts. As shown in Figure 5, Timer1 is off and prepared for initialization. The Timer0 module is assigned with prescale value of 1:128. After Timer1 module is configured, Timer1 is on. Decimal 25 is loaded into SLOWIT register to measure the clock pulses during 25 cycles of Timer0. Timer0 has overflowed and then the contents of SLOWIT register are decremented. If the result is zero, Timer1 is off and the conversion of frequency to flow rate starts. Since the Timer0 module is 8-bit timer/counter and prescaler is assigned with 128, total time is 0.8 sec for counting period. Pulses from the sensing unit are counted within 0.8 sec and the measured clock pulses which are directly proportional to the flow rate are loaded into Timer1 register. Timer1 register is 16-bit timer/counter. Thus, TIMEMSB register is used for the value greater than 65535.

306

START

MEASURE

MAIN

DECREASE MEASURERATE

CMCON = 07 MEASURERATE = 10 BLNKCNT = 5

MEASURE FLOW RATE

MEASURED RATE = 0 ?

SET RB0 to RB5, RA0, RA1 as OUTPUT PRESCALER = 128

MEASURED FLAG = 1 ?

DELAY = 0.026 ms

CALCULATE ERROR

N

N

Y MEASURERATE = 10 SET MEASURED FLAG

Y

MEASURE FREQUENCY

RESET MEASURED FLAG

INITIALIZE LCD

CONVERT FREQUENCY TO FLOW RATE

DELAY = 0.026 ms

DISPAY ERROR VALUE on LCD LINE 2 DISPLAY FLOW RATE ON LCD LINE 1

DISPLAY "WATER FLOWMETER" CONTROL VALVE

RETURN

MAIN

Fig. 3: Flow Chart of the System

Fig. 4: Flow Chart for Measurement of Water Flow Rate

The counting values from Timer1 are loaded into REGA register as dividend. Assuming that one liter per minute is equal to 25 counts per second, 25 is loaded into REGB register as divisor. The quotient is the measured flow rate expressed with liter per minute and displayed on LCD line1. Error calculation starts. The measured flow rate subtracts the set point flow rate 25 L/min and error value is shown on LCD line2. As shown in Figure 6, if the error value is less than 2, motor stops and the valve holds its position at this time. If not, motor control interval is decremented. If the result is zero, BLNKCNT register reloads 5 and valve control starts. If the error value is negative, left limit switch is checked. If the switch is off, motor will rotate in counterclockwise and a delay time of 10ms is executed for motor rotating time. If the error value is positive, right limit switch is checked. If the switch is off, motor will rotate in clockwise direction and delay time of 10ms is executed. Control A

MEASURE FREQUENCY

Error Value