6
Design and Implementation of a Microprocessor-Based Interrupt-Driven Control for an Irrigation System Mr. Azzouz Benzekri Prof. Larbi Refoufi University of Boumerdes Algeria University of Boumerdes Algeria Faculty of Engineering Dept of Electrical Engineering [email protected] Faculty of Engineering Dept of Electrical Engineering [email protected] Abstract - This paper presents the design and implementation of an interrupt-driven microprocessor-based irrigation system. It is targeted towards users of automated irrigation systems, in order to improve the irrigation water management and frost protection of crops. To achieve this goal, we developed a procedure integrating the agrohydrolological aspect of irrigation with the microprocessing aspects. The system uses soil water potential measurements to control the amount of water to apply to the field. The firmware enables the system to continuously measure in situ via the input interface, soil moisture content and climatic parameters. Also, it performs math and other user- defined functions and outputs commands to drive appropriate actuators (solenoid valves, pump motors). A Delphi-based friendly graphical user interface (G.U.I) was developed to interact with the controller and display the overall irrigation system status. Full circuit and program codes are implemented to verify system operation. I. INTRODUCTION Irrigation – an artificial application of water to the soil – is an agriculture practice that goes back thousands of years in human history. Prior to the introduction of modern irrigation systems, all the agricultural land was irrigated by traditional flood and furrow irrigation methods. Methods that are economical, if water resources are abundant; this was the case in the past when the world’s population was small and most of it rural and the industry almost inexistent. The prediction is that by 2025, one quarter of the world’s population will face severe watershortage [1]. Also, because agriculture is the main consumer of fresh water, increasing irrigation efficiency seems to be the practical way to save water. With the proliferation of powerful and low cost controllers - microprocessors and microcontrollers – and the availability of different type of transducers, the soil moisture potential conditions along with on field weather data can be integrated in a real-time control system to continuously “visualize” what goes in the soil profile at the root zone. If optimum conditions are maintained the product will be of better quality. It is demonstrated with a simple circuit and software how a microprocessor-based control system is able to manage all the electric equipments that constitutes an irrigation system. This paper presents the design and implementation work of an automated irrigation management system built around a Z80 microprocessor. The controller consists of the microprocessing unit, which contains the Z80 microprocessor (CPU) a RAM and an EPROM, four programmable peripheral interface adapters (PPIs), one Z80PIO, a UART (to link the controller to a PC), an eight- channel 8-bit ADC, a 16 key keypad, several actuators and numerical displays. A simplified block diagram of the interrupt-driven microprocessor-based system is shown in fig. 1. The remainder of this paper is organized as follows. In section 2, we provide a brief description of irrigation scheduling. Section 3 discusses the design system approach. In section 4 we describe the system hardware. Section 5 presents the flowcharts summarizing both the firmware and the software application programs of the system. The paper terminates with a conclusion which discusses several possible directions for continued research into the development of intelligent irrigation scheduling systems for real-time applications. II. IRRIGATION SCHEDULING To maximize returns from irrigation development and from water application, there is a need to properly schedule irrigation. Irrigation scheduling methodologies based on sound scientific practice are gaining greater importance, as fresh water is becoming limited [2], [3]. Irrigation scheduling is a planning and decision-making activity used by the farm manager to improve water use efficiency and raise yields, and in turn will lead to higher Fig. 1 The Interrupt-Driven Microprocessor-Based Irrigation System Block Diagram. 3 7 8 C D E F A B 4 6 1 PIO and PPI I/O Z80 Microprocessor Storage Media RAM & EPROM 8255 PPI USART RS232 ADC Sensors Motors Pumps Valves 8255 PPIs 5 2 0 9 68 1-4244-0324-3/06/$20.00 '2006 IEEE

[IEEE 2006 1ST IEEE International Conference on E-Learning in Industrial Electronics - Hammamet, Tunisia (2006.12.18-2006.12.20)] 2006 1ST IEEE International Conference on E-Learning

  • Upload
    larbi

  • View
    214

  • Download
    1

Embed Size (px)

Citation preview

Design and Implementation of a Microprocessor-BasedInterrupt-Driven Control for an Irrigation System

Mr. Azzouz Benzekri Prof. Larbi Refoufi University of Boumerdes Algeria University of Boumerdes Algeria

Faculty of Engineering Dept of Electrical Engineering [email protected]

Faculty of Engineering Dept of Electrical Engineering

[email protected]

Abstract - This paper presents the design and implementationof an interrupt-driven microprocessor-based irrigationsystem. It is targeted towards users of automated irrigationsystems, in order to improve the irrigation water managementand frost protection of crops. To achieve this goal, wedeveloped a procedure integrating the agrohydrolologicalaspect of irrigation with the microprocessing aspects. Thesystem uses soil water potential measurements to control theamount of water to apply to the field.

The firmware enables the system to continuously measurein situ via the input interface, soil moisture content andclimatic parameters. Also, it performs math and other user-defined functions and outputs commands to drive appropriateactuators (solenoid valves, pump motors). A Delphi-basedfriendly graphical user interface (G.U.I) was developed tointeract with the controller and display the overall irrigationsystem status.

Full circuit and program codes are implemented to verifysystem operation.

I. INTRODUCTION

Irrigation – an artificial application of water to the soil –is an agriculture practice that goes back thousands of yearsin human history. Prior to the introduction of modernirrigation systems, all the agricultural land was irrigated bytraditional flood and furrow irrigation methods. Methodsthat are economical, if water resources are abundant; thiswas the case in the past when the world’s population wassmall and most of it rural and the industry almost inexistent.

The prediction is that by 2025, one quarter of theworld’s population will face severe watershortage [1]. Also,because agriculture is the main consumer of fresh water,increasing irrigation efficiency seems to be the practicalway to save water.

With the proliferation of powerful and low costcontrollers - microprocessors and microcontrollers – and theavailability of different type of transducers, the soil moisturepotential conditions along with on field weather data can beintegrated in a real-time control system to continuously“visualize” what goes in the soil profile at the root zone. Ifoptimum conditions are maintained the product will be ofbetter quality.

It is demonstrated with a simple circuit and softwarehow a microprocessor-based control system is able tomanage all the electric equipments that constitutes anirrigation system.

This paper presents the design and implementationwork of an automated irrigation management system builtaround a Z80 microprocessor. The controller consists of themicroprocessing unit, which contains the Z80microprocessor (CPU) a RAM and an EPROM, fourprogrammable peripheral interface adapters (PPIs), oneZ80PIO, a UART (to link the controller to a PC), an eight-

channel 8-bit ADC, a 16 key keypad, several actuators andnumerical displays. A simplified block diagram of theinterrupt-driven microprocessor-based system is shown infig. 1.

The remainder of this paper is organized as follows. Insection 2, we provide a brief description of irrigationscheduling. Section 3 discusses the design system approach.In section 4 we describe the system hardware. Section 5presents the flowcharts summarizing both the firmware andthe software application programs of the system. The paperterminates with a conclusion which discusses severalpossible directions for continued research into thedevelopment of intelligent irrigation scheduling systems forreal-time applications.

II. IRRIGATION SCHEDULING

To maximize returns from irrigation development andfrom water application, there is a need to properly scheduleirrigation. Irrigation scheduling methodologies based onsound scientific practice are gaining greater importance, asfresh water is becoming limited [2], [3].

Irrigation scheduling is a planning and decision-makingactivity used by the farm manager to improve water useefficiency and raise yields, and in turn will lead to higher

Fig. 1 The Interrupt-Driven Microprocessor-Based Irrigation SystemBlock Diagram.

3

7 8 CDEFA B

4 61

PIO and PPI I/O

Z80Microprocessor

StorageMediaRAM

&EPROM

8255 PPI USART

RS232ADC

SensorsMotorsPumpsValves

8255 PPIs

520

9

681-4244-0324-3/06/$20.00 '2006 IEEE

income and provoke a positive effect on the quality of soiland ground water. This decision-making processdetermines when and how much water to apply to agrowing crop to meet specific management objectives [4].

A common method that growers use to determine whentheir crops need watering is by observing the amount oftime elapsed since the last irrigation cycle. Also, mostpeople tend to overirrigate believing that applying morewater will increase yields. In fact, over-irrigation can bedetrimental to plants and cause environmental problems.Excessive use of water leads to a range of environmentalproblems such waterlogging, nutrient leaching, groundwater pollution and salinization. In addition water, energyand labor are wasted away.

The solution is to automate the irrigation watermanagement process to decide when to irrigate the cropand how much water to apply. The automation involvesmonitoring soil moisture at different depths and climateconditions and applies water at an appropriate time basedon an informed and intelligent decision.

III. IRRIGATION SYSTEM DESIGN APPROACH

In order to automate the system operation, it isnecessary to use a closed loop system mechanism. Theclosed loop controller requires the acquisition of soil waterstatus and weather data parameters, such as temperature,wind speed, rainfall level, and humidity. The level ofmoisture in the root zone is compared against the desiredlevel and a decision based on this comparison is made as towhether the irrigation should take place or not.

A. Anticipatory Approach

It is known that it takes some time for water to infiltratethrough the soil, hence using a simple “on-off” controllerwould result in a waste of water past the root zone. By the

time the water reaches the root zone, the system is triggeredto stop irrigation, but the soil above the root zone beingsaturated, water will continue to flow below the root zone.

To overcome this problem, we applied an anticipatorycontrol technique. This latter requires at least two soilmoisture probes to properly control the water flow front.

The approach used to design the interrupt-drivenmicroprocessor-based irrigation system is based on thecritical elements listed above and the anticipatory technique.The whole process is summarized in the flow graph diagramdepicted in fig. 2.

B. Interrupt-Driven Mechanism

A microprocessor is of no interest by itself. It must beconnected to memory and input/output (I/O) devices tocarry out computing and application functions.

The Z80 microprocessor identifies peripherals either asmemory-mapped I/O or as I/O mapped I/O. We opted forthe latter as it reduces hardware connections and uses lessmemory for program codes.

One of the major problems encountered in the datatransfer between the processor and the peripheral device isthe large difference in operating speed. The mechanism canbe controlled either by the processor or by the device. Thisgives rise to several approaches to synchronizing the CPUand the external devices.

In the microprocessor-controlled mode, the transfer cantake place conditionally or unconditionally. The conditionaldata transfer requires some form of handshaking. Also, itkeeps the CPU waiting in a polling loop doing nothingexcept wasting time waiting for the device to be ready fordata transfer. In the unconditional data transfer, the deviceis assumed to be always ready to accept data.

The approach used in this work is one of the mostinteresting device-initiated approaches. It is the interrupt-driven I/O devices. It uses a mixture of hardware andsoftware techniques. It involves the I/O device to send asignal to one of the microprocessor’s interrupt lines toinform it that the device requires an immediate service. Theadvantage of this technique is that the microprocessor canperform other tasks rather than waiting in a polling loop.

IV. HARDWARE DESIGN

The controller system built around the Z80 CPUcontains one RAM, one EPROM, a Z80PIO, four 8255programmable peripheral interface devices, one 8-channel8-bit ADC a hexadecimal keypad and numerical displays.The microprocessor executes the firmware program toactivate irrigation control. The RAM device is used as ascratch memory for stack and intermediate computationalresults. The EPROM contains all the instruction codes forsystem operation.

The keypad provides the user the selection of optionsand /or data entry. The four 8255 chips and the Z80PIOprovide a total of 14 input/output ports to communicate withthe outside world. In order to communicate with the hostcomputer, an 8251 universal asynchronous receivertransmitter (UART) is used to link serially the controller tothe PC via the serial port. The several seven-segmentdisplays and L.E.Ds are provided to display the numerousparameter values and status.

Measure soil moisture withupper and lower probes

Start

Does soilmonitoring indicates

it’s time to irrigate ?

Are climaticconditions suitable

for irrigation?

Irrigation

Delay irrigation

Yes

No

No

Yes

Fig. 2. Real-time irrigation scheduling flow graph based on soilMoisture and climatic parameters

69

Fig. 3-b. The Microprocessing Unit

Fig. 4. Part of the data acquisition unit

A. The Microprocessing Unit

The microprocessing unit consists of a Z80microprocessor chip, two unidirectional and one bi-directional buffer driver chips for the address and databuses respectively. The CPU is driven by a clockconstructed around a 4-Mhz crystal oscillator. Glue logic isused to generate the necessary signals. Also, included inthis unit are two 3-to-8 decoders (74LS138) for memoryand I/O devices. For execution, the microprocessor—based

system uses a system memory including a RAM and anEPROM. The RAM is used as a scratch memory to storeintermediate results and also as a system stack. The EPROMmapped starting 0000h stores the system’s firmwareprogram. Fig. 3 depicts the microprocessing unit.

B. The Data Acquisition Unit

The data acquisition unit is built around the 8-bit ADC0808. The device has 8 multiplexed analog channels, out ofwhich any one can be select at one time. Data acquisitionrequires both hardware and software. Fig. 4 shows how theADC is connected to the Z80. The data lines are connecteddirectly to the microprocessor’ data bus. This facility ismade possible by the fact that the ADC 0808 has tri-statedoutput data lines. The end-of-conversion (EOC) outputsignal of the ADC is used to drive an edge-triggered D flip-flop, the output of which is used to interrupt themicroprocessor via the priority encoder, fig. 5.

The data acquisition includes a hexadecimal keypad fordata entry and functions. The numerical buttons are used fordata entry these are the decimal digit keys (0 .. 9). The letterbuttons (A .. F) are used as function keys. The A buttonignites the automatic mode operation. In this mode, thekeypad relinquishes control to the microprocessor.Depressing button B, instructs the controller that the nexttwo decimal digits stand for the soil moisture threshold. KeyC, instructs the controller that the next digit stands for soiltype. Depressing D, enables the user to enter the duration ofthe irrigation application in the “timer” mode. Finally, key Finitiates the “timer” mode irrigation process.

C. The Interrupting Unit

We have more than one interrupting source to connectto the maskable interrupt line. For the processor to

Fig. 3-a The microprocessing unit

70

Fig. 5. The interrupting unit

T1 O

T1 INR1 IN

R1 O

MAX232

Fig. 6. The digital serial I/O communication interface with the PC’s serial Port

distinguish between them, we prioritized the interrupts. Wehave used an 8-to-3 priority encoder (74LS148) to handlethe three interrupting devices. These are in descendingorder of priority: the STOP button, the START button andthe EOC generated by the ADC and conditioned by the Dflip-flop, fig. 5.

When an interrupting device requests service, one of thethree input lines (I7, I6, or I5) goes low driving the groupsignal output GS low which in turn interrupts themicroprocessor. Once the interrupt is acknowledged, theINTA signal is asserted low enabling the octal latch(74LS573), the code corresponding to the input is placedon data lines D3, D2 and D1 with D0 kept permanently atlogic 0 (the Z80 expects the vector address to be even). The 16-bit vector address is obtained by combining the8 bits from the external hardware as the low-order byte,and the higher-order byte from the interrupt register (set bythe user). This 16-bit value is the address of the memorythat contain the starting address of the interrupt serviceroutine (ISR). This indirect method of getting the ISRaddress is referred to as the vectored interrupt and the arrayof addresses are the interrupt vectors.

D. The Display Unit

The display unit consists of fourteen seven-segmentdisplays (TIL-311). The numerical displays are interfaced tothree 8255 chips configured as output ports via octal bufferchips (74LS244). The remaining indicators , actuators andalarm are interfaced to the 8255 chips configured in the bitset-rest (BSR) mode [5], [6].

E. The Serial Digital Communication Unit

This unit provides a means to the controller tocommunicate serially with the PC. The computer’s RS-232serial port is asynchronous requiring additional handshakingcontrol lines. Also, we must set both ends of the link to thesame baud rate. Fig. 6 shows the typical components used to constructthis unit. On one side the UART is connected to thesystem’s data bus and the synchronizing signals, and on theother side it is connected to the MAX 232 which in turn isconnected to a DB9 connector. TxCLK and RxCLK areconnected to the CD4040 BC baud generator to ensuresynchronism between the PC and the microprocessor-basedsystem. The flip-flop is used as a frequency divider to suitethe UART clock frequency, while the RxRDY drives themicroprocessor’s non-maskable interrupt line to stop theirrigation system upon emergency.

V. FIRMWARE / SOFTWARE PROGRAMS

The physical interconnection of components in amicroprocessor-based system does not indicate its function.It is the firmware, the hard-coded program in the EPROMexecuted by the microprocessor that determines thesystem’s function. Since the system is serially connected toa PC by means of a bi-directional communication link,where field status is continuously sent to the host computerfor storage and display, a Delphi-based software program isdeveloped to interact with the microprocessor-based system.

A. The Controller Firmware Program

The firmware program manages all the communicationsand data manipulations between the microprocessor and theperipherals. It handles the transmission of data to thewindow application G.U.I. Each update is an 8-bit packedcode that is coded by the Delphi-based program, followedby 8 bits of the current value or state.

71

Read data from UART

Initialization of the P.C'sSerial Port

Is It aValid Code ?

No

Execute thecorrespondingProcedure

Yes

Start

Fig. 8. The window application flowchart

implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);beginasm mov dx,03FCh //Initialization of the UART. mov al,10h out dx,al mov dx,03FBh mov al,80h out dx,al mov dx,03F8h

Fig. 9-a Part of the UART initialization program code

200:begin sleep(n); asm mov dx,03f8h // read data in al,dx mov msg,al end; Edit2.Text:=inttostr(msg); if msg = 0 then begin Shape2.Visible := true; Shape1.Visible := false; end else begin Shape1.Visible := true; Shape2.Visible := false; end; sleep(n); end;

Fig. 9-b Part of data read and display program code.

The main program begins with an initialization section,where the hardware is configured and the variables (such assoil type, soil moisture range, wind-speed) are initialized.

The system is designed to have three independentmodes of operation (Timer, Manual and Automatic) to takeinto consideration all possible needs.

In the “Timer” mode, the user enters the desired timeinterval during which he wishes the irrigation will takeplace. The irrigation is however conditioned by certainclimatic parameters. The irrigation terminates when thepredefined time interval has collapsed.

In the “Manual” mode, the farm manager has thefreedom of starting irrigation whenever he feels itnecessary. Depressing the START button starts theirrigation process regardless of the soil moisture andclimatic conditions. The STOP button interrupts andresumes the irrigation process at any moment. This featuremay be of interest to control the peaks of high and lowtemperature. During the frost event, the irrigation systemmay spray crops to warm up the atmosphere. Similarly,irrigation may be applied to protect crops from heat stressby cooling up the crops.

In the “Automatic” mode, the controller continuouslymanages the irrigation system without any intervention ofthe farm manager. The irrigation application is controlledby the actual soil moisture at the root zone and weatherparameters. The data collected from the sensors and the setpoints entered by the grower are processed to determinewhen and how much water to apply. The above data alongwith the system status are sent serially to the PC wherethey are displayed.

The general philosophy of the firmware program isbased on the following premises:- The controller should have a friendly user interface

that simple to use by the irrigator with no particularprofessional qualifications.

- The program should be based on a modular (dedicatedsubroutines) design basis.

The firmware program is developed using assemblylanguage. The flowchart describing the automatic mode isshown in fig. 7.

A. The Windows Application Program

The software is a windows-based developmentenvironment. Borland Delphi is used to create to a friendly

graphical user interface (GUI) with the irrigation system.The program is written to continuously read the data sentby the controller perform some calculations and displaysthe overall irrigation system status on the screen.

To ensure synchronism, each data is preceded by aspecific code. The flowchart summarizing the widowsapplication is shown in figure. 8. A part of the Delphiprogram code is listed in fig. 9. A window application atrun time is depicted in fig.10.

VI. CONCLUSION

In this paper, we presented the design andimplementation of an automated real-time microprocessor-based interrupt-driven for an irrigation system based onmonitoring and control of soil water status in the plant root-zone and weather parameters.. Sensors, microelectronic devices, microprocessortechniques and actuators were used in the acquisition,control, processing and distribution of data and informationto the acquisition in real-time of the parameters involvedin the irrigation process. To improve system performance, an auto-detect faultysensor mechanism (for shorts and opens) is implemented. Future work will focus on the establishment of adatabase from the data acquired by the controller andtransmitted to the PC. These database will be used tocompute the EvapoTranspiration (ET) (based on Penman-Monteith formula) and compare it with the actual soilmoisture to determine system efficiency.

72

VII. REFERENCES

[1] D. Seckler and D.R. Barker, “Water scarcity in the21st century,” International Journal of Waterresources Development. ((5(1/2)) 1999.

[2] G.J. Hoffman, T.A. Howell and K.H. Solomon,“Management of farm irrigation systems”, ASAEMonograph, St. Joseph. M.I. 1990.

[3] M.E. Jensen, “Design and operation of farm irrigationsystems”, ASAE. Monograph, St Joseph. M.I. 1983

[4] R. Testezlaf, F.S. Zazueta and T.H. Yeager, “A real-time control system for greenhouse”, AppliedEngineering. Agric. 3(2). 1997.

[5] G.K. Adam, “Design of a Microprocessor-BasedControl System of a Compression Molding Process,”in Proceedings of the 9th IEEE Inter Conf onEngineering Complex Computer Sys. 2004.

[6] R.S. Gaonkar, The Z80 Microprocessor: Architecture,Interfacing, Programming and Design, Prentice Hall:2001

The Window Application at RunFig. 10. A window application at run time. Irrigation is stopped due to a sensor failure. (Soil Moisture Lower Probe)

Fig. 7. The Automatic Mode Flowchart

1

Is LowerProbe < Threshold ?

Is T°Favorable

Is UpperProbe=Saturation?

Is RainfallLevel Low ?

Is WindSpeed Favorable?

Transfer Data andStatus to the P.C

Return

Yes

Yes

No

No

Is IrrigationON ?

• Stop irrigation- Stop Pump- Stop Valve- Stop Pivot

YesYes

Yes

No

NoNo

Yes

No

Start

Test Sensors ForPossible Failures

Select Channel 0Start ConversionEnable Interrupt

• Read Sequentially Soil and Climatic Factors • Store these Data • Convert to BCD and Display

Return

1

Is T°Sensor Down ?

Is LowerProbe Down?

Is UpperProbe Down ?

Is WindSensor Down

• Set Alarm • Identify Sensor

Is Irrigation ON ?

Stop Irrigation

Yes

Yes

Yes

No

No

No

No

NoYes

Yes

Start Irrigation - Turn Pivot ON - Open Valves - Start Pump

73