Sei sulla pagina 1di 46

MINI PROJECT REPORT on ONLINE DEVICE CONTROLLER Submitted in partial fulfillment of the requirements for the award of the

degree of BACHELOR OF TECHNOLOGY in ELECTRONICS ENGINEERING of the COCHIN UNIVERSITY OF SCIENCE AND TECHNOLOGY by AGIL FRANCIS HARRY JOSE M JIM CHERIAN under the guidance of Mr. LIJU PHILIP Lecturer, Electronics Engineering, College of Engineering Chenga nnur DEPARTMENT OF ELECTRONICS ENGINEERING, COLLEGE OF ENGINEERING, CHENGANNUR, KERAL A - 689121. September 2001

Online Device Controller ACKNOWLEDGEMENT This is the age of the Internet and the World Wide Web is becoming a part of the life of the common man of our country. In this scenario, we have tried to imple ment the control of hardware through Internet, a really challenging project. Thi s project would not have been successfully materialized had it not been for the several people who have directly and indirectly helped us. We are extremely inde bted to all of them and we wholeheartedly thank everyone for their valuable supp ort. We are extremely grateful to Mr. P Prathapachandran Nair, our Principal for providing us with good facilities and a proper environment for developing our p roject. We thank Mr. Jyothiraj V P, Head of the Department, Department of Electr onics Engineering for the support and appreciation. We are also grateful to Mr. C V AnilKumar, our Project Co-ordinator for all the guidance. Our guide Mr. Liju Philip has been a real help to us during the entire course of our project and w e are highly obliged to him for his valuable suggestions, appraisal and guidance . We also thank Mr.Gopakumar C, Lecturer and Project Lab In Charge, and Mr. Sudh in Jacob, Lecturer for the constant support and encouragement for our project. W e are also greatly indebted to Mr. Riyas A, Electronics Engineer, Rubber Board o f India, Kottayam for his critical suggestions and technical advice. And several of our seniors for their wonderful help rendered and powerful suggestions in th e initial phase of our project, and all our friends, both of Electronics and Com puter Engineering branches, who have been a great help. We are also very thankfu l to all those unknown and unseen people who helped us with valuable information through several discussion boards over the Internet. We truly admire our parent s for their constant encouragement and enduring support which was inevitable for the success of our ventures. Last, but not the least, we are thankful to each o ther in this project group for being cooperative, patient and hardworking for th e successful completion of this project. Above all, we thank God Almighty for th e ever-abiding kind blessings. 1

Online Device Controller ABSTRACT The Online Device Controller (ODC) is a multi-channel hardware administration sys tem that has been developed to enable the control of equipments and appliances f rom any part of the world, through the Internet. The concept of ODC is a relativ ely new one, and makes use of Common Gateway interface (CGI), a very powerful te chnique that was hitherto used solely for e-mail, database access and other soft p urposes involving dynamic web page content. But, through this project we have ma de an attempt to bring a very powerful but often unknown and underutilised aspec t of CGI; the same technique used to manipulate our e-mail accounts can equally well be applied to access the parallel port of the web server, and control hardw are through it. Our project, the Online Device Controller allows a remote user to login to the Web server and control the devices connected to the server. Also provided is the fe ature to control the same devices locally, through a Cordless Telephone. The present product offers the facility to remotely control an ON/OFF device and an Intensity Variable load, through the Internet, and locally through a Cordles s telephone and is a product of paramount significance in office, industrial and household applications. 2

Online Device Controller CONTENTS INTRODUCTION REVIEW The World Wide Web Common Gateway Interface Parallel Port Ba sics DTMF Dialing System Microcontrollers The Triac THE PROJECT Block Diagram Ha rdware details Software details Flow Charts Working of the System Result and Dis cussion CONCLUSION AND FUTURE SCOPE REFERENCES 4 5 6 9 15 22 24 26 29 30 31 34 3 5 41 42 43 44 3

Online Device Controller INTRODUCTION With the advent of technology, the world has shrunk to a global village. Man has been looking forward to realise the automation of every process, taking place a round him. But his dream, to extend his control to devices from anywhere in the world still remains unfulfilled. Our project envisages the control of equipments from a remote location through the Internet, or an Intranet. Local control is a lso available through a dedicated PC and a Cordless Phone Unit. This project is suited for Office Automation and Home Automation. The concept can equally well b e extended to Industrial applications where direct human access is restricted. T hrough this project, we strive to make this dream come true Salient Features Remote access to dedicated devices from anywhere in the world through the Intern et. Wide application in industrial, office and domestic automation. Secure and r eliable. Remote control from local station is available. Power regulation Facili ty to read the current status of the device is incorporated 4

Online Device Controller Review 5

Online Device Controller The World Wide Web The World Wide Web is the collection of all browsers, servers, files, and browse raccessible services available through the Internet. Conceived in 1989 by a comp uter scientist named Tim Berners-Lee, its original purpose was to facilitate com munication between research scientists. The Web was designed in such a way that documents located on one computer on the Internet could provide links to documen ts located on other computer on the Internet. A browser is the users window to the Web, providing the capability to view Web do cuments and access Web-based services and applications. The most popular browser s are Netscapes Navigator and Microsofts Internet Explorer. Both browsers are desc endants of the Mosaic browser developed at the National Center for Supercomputin g Applications (NCSA). Mosaics slick graphical user interface (GUI) transformed t he Web from a research tool to the global publishing medium that it has become t oday. Todays Web browsers extend Mosaics GUI features with multimedia capabilities and w ith browser programming languages such as Java and JavaScript. In order to publi sh a document on the Web, it must be made available to a Web server. Web servers retrieve Web documents in response to browser requests and forward the document s to the requesting browsers via the Internet. Web servers also provide gateways that enable browsers to access Web-related applications as well as other Intern et services, such as Gopher and Wide Area Information Search (WAIS). The earliest Web servers were developed by CERN and NCSA. These servers were the mainstay of the Web throughout its earlier years. Lately, Commercial Web server s, developed by Netscape, Microsoft, and other companies, have become increasing ly popular on the Web. These servers are designed for higher performance and to facilitate the development of complex Web applications. 6

Online Device Controller Because the Web uses the Internet as its communication medium, it must follow Internet communication protocols. The Internets Transmissi on Control Protocol (TCP) and Internet Protocol (IP) enable worldwide connectivi ty between browsers and servers. In addition to using the TCP/IP protocols for c ommunication across the Internet, the Web also uses its own protocol, called the HyperText Transfer Protocol (HTTP), for exchanges between browsers and servers. The HyperText Transfer Protocol (HTTP) HTTP is the protocol used for communication between browsers and web servers. HT TP uses a request/response model of communication. A browser establishes a conne ction with a server and sends URL requests to the server. The server processes t he browsers request and sends a response back to the browser. A browser connects with the Web server by establishing a TCP connection at port 80 of the server. (This is the default port until another is specified in the UR L) This port is the default address at which web servers listen for browser reques ts. Once a connection has been established a browser sends a request to the serv er. This request specifies a request method, the URL of the document, program or other resource being requested, the HTTP version being used by the browser, and other information related to the request. Several request methods are available. GET, HEAD, and POST are the most commonly used ones. The GET method is used to retrieve the information contained at the specified UR L. This method may also be used to submit data collected in an HTML form or to i nvoke a Common Gateway Interface (CGI) program. When the server processes a GET request, it delivers the requested information (if it can be found). The server inserts at the 7

Online Device Controller front of the information an HTTP header that provides d ata about the server, identifies any errors that occurred in processing the requ est, and describes the type of information being returned as a result. The HEAD method is similar to the GET method except that when a Web server proce sses a HEAD request, it only returns the HTTP header data and not the informatio n that was the object of the request. The HEAD method is used to retrieve the in formation about a URL without actually obtaining the information addressed by th e URL. The POST method is used to inform the server that the information appended to th e request is to be sent to the specified URL. The POST method is typically used to send form data and other information to Common Gateway Interface (CGI) progra ms. The Web server responds to a POST request by sending back header data follow ed by any information generated by the CGI program as the result of processing t he request. The current version of HTTP is HTTP 1.1. It incorporates performance, security a nd other improvements to the original HTTP 1. A new version of HTTP, referred to as HTTP-NG, is currently being defined. (The NG stands for Next Generation.) The goal of HTTP-NG is to simplify the HTTP protocol and make it more extensible. Hyper Text Markup Language The Hyper Text Markup Language, or HTML, originally developed by Tim Berners Lee at CERN is the lingua franca of the Web. It is used to create Web pages and use s ordinary ASCII text files to represent Web pages. The files consist of the tex t to be displayed and the tags that specify how the text is to be displayed. The use of tags to define the elements of a Web document is referred to as marku p. A tag is usually enclosed in angle brackets, and most tags come in pairs, wit h an opening and a closing tag. The closing tag is the same as the opening tag b ut starts with a 8

Online Device Controller forward slash. For example, the following line from an HTML file shows the text of a title between the appropriate title tags. <TITLE>W elcome to the Control Menu of Online Device Controller</TITLE> A browser interprets these tags and displays only the text within the tags appro priately. There are different tags used to identify headings, paragraphs or hype rlinks and also, to insert images, forms, multimedia objects etc. Common Gateway Interface (CGI) The Common Gateway Interface (CGI) is a standard that specifies how external grams may be used by Web servers. Programs that adhere to the Common Gateway erface standard are referred to as CGI programs. CGI programs may be used to cess data submitted with forms, to perform database searches, and to support er types of Web applications such as clickable image maps. pro Int pro oth

Where HTML gives the World Wide Web its look, CGI makes it functional. It is a Co mmon Gateway between the web server and applications that can be useful to the se rver, but doesnt run as a part of it. In technical terms, a gateway is an interfa ce or an application that allows two systems to pass information between them. T he CGI does the same function in the context of a Web server and Web client (Web browser). The server does not know Perl or C. But by means of CGI, it can handl e requests from clients or visitors to the Web page, allow execution of the requir ed application programs and pass the results back. In fact, CGI is the only way the server can communicate with these other applications, such as a database or even the parallel port of the machine. A browser request for the URL of a CGI program comes about as the result of a us er clicking a link or submitted a form. The browser uses HTTP to make the reques t. When a Web server receives the request, the Web server executes the CGI progr am and 9

Online Device Controller also passes it any data that was submitted by the brows er. When the CGI program performs its processing, it usually generates data in t he form a Web page, which it returns via the Web server to the requesting browse r. The CGI standard specifies how data may be passed from Web servers to CGI progra ms and how data should be returned from CGI programs to the web server. Working of CGI CGI programs also referred to as CGI scripts are the external programs, which ar e a standard interface for communication between Web servers and external progra ms. The CGI specification identifies how data is to be passed from a Web server to a CGI program and back. The following points summarise how CGI works A browser requests a CGI program by specifying the CGI programs URL. The request arises as the result of the user submitting a form or clicking a link. The brows er may insert into the URL a query string or extra path information When a Web server receives a URL request it determines whether the URL refers to CGI program, Most Web servers identify CGI programs by the path in which they a re 10

Online Device Controller located or by the file name extensions. For example, al l files in the path /cgi-bin/ or with the extensions .CGI or .PL could be CGI pr ograms. When a Web server identifies a request for a CGI program it executes the CGI pro gram as a separate process and passes any data included in the URL of the progra m. The CGI program performs its processing and then returns its output to the Web s erver. The conventions defined by the CGI specification determine how CGI progra ms receive data from and return data to Web servers. Getting Data from the Web Server When a CGI program is executed, one of its first tasks is to determine what data was passed to it by the Web Server. This data may be passed in the following wa ys: Command-line Arguments Environment Variables The programs standard input stream Command-line arguments and the standard input stream are supported by almost all programming languages. Environment variables are less commonly used outside the Web applications. 11

Online Device Controller Environment Variables Environment Variables are the primary mechanism by which web servers communicate with CGI programs. All CGI programs can receive data from Web Servers via envir onment variables. Environment variables are variables that are external to a programs execution. Th ey are used to define the environment in which a program executes. The following table identifies some commonly used environment variables defined by CGI versio n 1.1. Environment Variable AUTH_TYPE Description The authentication scheme used to validate the user requesting access to a Web p age. CONTENT_LENGTH The number of characters that have been passed via standard input. CONTENT_TYPE The MIME type associated with the data variable via standard input PATH_INFO The extra path information added to the URL of the CGI program 12

Online Device Controller PATH_TRANSLATED The full path name that was translated from the URL by the Web server. QUERY_STRING REMOTE_ADDR The query string portio n of the URL. The IP address of the host associated with the requesting browser REMOTE_HOST The name of the host associated with the requesting browser. REMOTE_ USER The name of the user associated with the requesting browser. REQUEST_METHOD The method associated with the browser request: GET, POST, HEAD and so on. SCRI PT_NAME SERVER_NAME SERVER_PORT The path and name of the CGI program. The name o f the Web server host. The HTTP port number (usually 80) used by the Web server. SERVER_PROTOCOL The name and version of the protocol used by the requesting bro wser to submit the request. These environment variables are available to all CGI programs regardless of whet her the CGI program was executed as the result of a command line argument based query, a form submission, or the clicking of a hyperlink. Many programming langu ages provide special mechanisms for accessing environment variables. For example , C provides the getenv( ) library function and Perl provides the $ENV array. Reading Query String Data When data is passed to a CGI program via the QUERY_STRING environment variable, the data is encoded using the following conventions. These coding conventions ar e referred to as URL coding. 13

Online Device Controller Spaces are replaced by plus (+) signs. Other characters may be replaced by character codes of the form %xx (with the xx being replaced by two hexadecimal digits). For example, %2a is used to encode a plus sign. CGI programs must decode the data passed via the QUERY_STRING variable. This is accomplished by replacing plus signs with spaces, and sequences of the form %xx with their character equivalent. This decoding is known as URL decoding. Sending Data back to the Web Server A CGI program returns data to the requesting browser via the Web server. In all cases, it returns the data by writing it to the standard output stream. The outp ut of the CGI program must begin with a header line, followed by a blank line, a nd ten by the data to be displayed by the browser. The header line usually consi sts of a Content-type header that specifies the MIME type of the data returned b y the CGI program. In most cases, the MIME type will be text/html, as shown in t he following example. Content type: text/html <HTML> <HEAD> <TITLE>Online Device Controller-- Request Confirmation </TITLE> </HEAD> <BODY> <H1>Hi Your request h as been processed. Please wait for the Control Menu to load in a few seconds. </H 1> </BODY> </HTML> 14

Online Device Controller Parallel Port Basics A PC Parallel Port (Printer Port) is an inexpensive and yet powerful platform fo r implementing projects dealing with the control of real world peripherals. The printer port provides eight TTL outputs, five inputs and four bidirectional lead s and it provides a very simple means to use the PC interrupt structure. The Par allel Port is the most commonly used port for interfacing home made projects. Th is port will allow the input of up to 9 bits or the output of 12 bits at any one given time, thus requiring minimal external circuitry to implement many simpler tasks. The port is composed of 4 control lines, 5 status lines and 8 data lines . Its found commonly on the back of the PC as a D-Type 25 Pin female connector. There may also be a D-Type 25 pin male connector. This will be a serial RS-232 port and thus, is a totally incompatible port. Newer Parallel Ports are standardi zed under the IEEE 1284 standard first released in 1994. This standard defines 5 modes of operation, which are as follows, 1. Compatibility Mode. 2. Nibble Mode . 3. Byte Mode. 4. EPP Mode (Enhanced Parallel Port). 5. ECP Mode (Extended Capa bilities Port). The most widely used mode is the Compatibility mode or "Centroni cs Mode" as it is commonly known, which can only send data in the forward direct ion at a typical speed of 50 Kbytes per second but can be as high as 150+ Kbytes a second. 15

Online Device Controller Port Assignments Each printer port consists of three port addresses; Data, Status and Control por t. These addresses are in sequential order. That is, if the Data port is at addr ess 0x0378, the corresponding Status port is at 0x0379 and the Control port is a t 0x037A. Address Notes Used for parallel ports which were incorporated into video cards and now, commonly an option for Ports controlled by BIOS. Doesnt support ECP addresses. Us ual Address for LPT 1 Usual Address for LPT 2 Port Addresses 3BCh 3BFh 378h 37Fh 278h 27Fh Please refer to the figures titled Pin Assignments and Port Assignments. These t wo figures illustrate the pin assignments on the 25-pin connector and the bit as signments on the three ports. Hardware Properties The "Pin Outs" of the D-Type 25 Pin connector and the Centronics 34 Pin connecto r are as shown in the table. The D-Type 25 pin connector is the most common conn ector found on the Parallel Port of the computer, while the Centronics Connector is commonly found on printers. The IEEE 1284 standard however specifies 3 different connectors for use with the Parallel Port. The first one, 1284 Type A is the D-Type 25 connector found on t he back of most computers. The 2nd is the 1284 Type B which is the 36 pin Centro nics Connector found on most printers. IEEE 1284 Type C however, is a 36 conduct or connector like the Centronics, but smaller. This connector is claimed to have a better clip latch, better 16

Online Device Controller electrical properties and is easier to assemble. 1284 T ype C connectors are yet to be implemented in present day applications. Pin No (DType 25) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 - 25 Pin No (Centronics) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 32 31 36 19 - 30 SPP Signal nStrobe Data 0 Data 1 Data 2 Data 3 Data 4 Data 5 Data 6 Data 7 nAck Busy Paper-Out Paper End Select nAuto-Linefeed nError/ nFault nInitialise nSelec t-Printer nSelect-In Ground Direction In/Out In/Out Out Out Out Out Out Out Out Out In In In In In/Out In In /Out In/Out GND Register Control Data Data Data Data Data Data Data Data Status Status Status St atus Control Status Control Control Hardware Inverted Yes Yes Yes Yes Pin Assignments of the D-Type 25 Pin Parallel Port Connector Software Registers - Standard Parallel Port (SPP) Port Assignments 17

Online Device Controller The base address, usually called the Data Port or Data Register is simply used f or outputting data on the Parallel Ports data lines (Pins 2-9). This register i s normally a write only port. If we read from the port, we should get the last b yte sent. However if the port is bi-directional, then Read and Write Operations can be performed on the Data Register and we can receive data on this address. T he Status Port (Base address + 1) is a read only port. Any data written to this port will be ignored. The Status Port is made up of 5 input lines (Pins 10,11,12 ,13 & 15), an IRQ status bit and two reserved bits. There are five status leads from the printer. (BUSY, /ACK, PE (Paper Empty), SELECT, /ERROR). These are avai lable at the 5 most significant bits of the Status port. Of these, the BUSY pin is hardware-inverted and typically this bit is inverted in the software applicat ion program to comply with the True Positive Logic. The Control Port (Base address + 2) was intended as a write only port. When a pr inter is attached to the Parallel Port, four "controls" are used. These are Stro be, Auto Linefeed, Initialize and Select Printer, all of which are inverted exce pt Initialize. However these four outputs can also be used for inputs. If the co mputer has placed a pin high (e.g. +5v) and the device wanted to take it low, we would effectively short out the port, causing a conflict on that pin. Therefore these lines are "open collector" outputs (or open drain for CMOS devices). This means that it has two states: - a low state (0 V) and a high impedance state (o pen circuit). Normally the Printer Card will have internal pull-up resistors, but as we expect , not all will. Some may just have open collector outputs, while others may even have normal totem pole outputs. In order to make the device work correctly on a s many Printer Ports as possible, we can use an external resistor as well. If th ere is already an internal resistor, then it will act in Parallel with it, or if they are Totem pole outputs, the resistor will act as a load. An external 4.7k resistor can be used to pull the pin high. 18

Online Device Controller The 4 pins of the Control Port can be used for bi-directional data transfer. How ever the Control Port must be set to xxxx0100 to be able to read data, that is a ll pins to be +5v at the port so that it can be pulled down to GND (logic 0). Bi ts 4 & 5 are internal controls. Bit 4 will enable the IRQ. In the Standard & Bidirectional (SPP) Mode of the Parallel port, Bit 5 will enable the Bi-directiona l port. In this case, we can use the 8 Data bits (DATA0-7) for input also. This mode is only possible if the card of the PC supports the feature. Bits 6 & 7 are reserved. At a minimum, there are 12 outputs; eight on the Data Port and four on the lower nibble of the Control Port. There are five inputs, on the highest five bits of the Status Port. Three output bits on the Control Port and one input on the Stat us Port are inverted by the hardware, but this is easily handled by using the Ex clusive-OR function to selectively invert bits. Using the Parallel Ports IRQ A hardware interrupt is a capability where a hardware event causes the software to stop whatever it is doing and to be redirected to a function to handle the in terrupt. When done, the program picks up where it left off. Aside from losing ti me in executing the interrupt service routine, the operation of the main program remains unaffected by the interrupt. Interrupts are good when interfacing monit oring devices where we dont know when it is going to be activated. Indeed, its more efficient to have an interrupt request rather than have the software poll the ports regularly to see if something has changed. The same technique may be a dapted to exerting interrupts directly on the ISA bus. The Parallel Ports inter rupt request is normally IRQ5 or IRQ7 but may be something else if these are in use. It may also be possible that the interrupts are totally disabled on the car d, if the card was only used for printing. The Parallel Port interrupt can be di sabled and enabled using bit 4 of the control register, Enable IRQ Via Ack Line. 19

Online Device Controller Once enabled, an interrupt will occur upon a low to hig h transition (rising edge) of the /ACK. Interrupt Handler Table The original 8088 PC design provided for up to 256 interrupts (0x00 - 0xff). Thi s includes both hardware and software interrupts. Each of these 256 interrupt ty pes has four bytes in a table beginning at memory location 0x00000. These 1024 b ytes (256x4) constitute the Interrupt Vector Table. These four bytes contain the address of where the PC is to go to when an interrupt occurs. Most of the table is loaded when we boot up the machine. The table may be added to or entries mod ified when various applications are run. The eight hardware interrupts beginning at INT 0x08 were reserved by IBM for interrupt expansion, commonly known as IRQ 0 - IRQ7; IRQ 0 corresponds to INT 8; IRQ 1 corresponds to INT 9, etc. Typically , the Parallel Port uses the Interrupt Request IRQ7. Modifying the Interrupt Handler Table Assume, we are going to use IRQ 7. When an IRQ 7 interrupt occurs, our program m ust proceed to our Interrupt Service Routine, a function that we define. For thi s, we must first modify the interrupt handler table. Initially we must read the present value in the table, save it, perform the required operations and restore the original value when our ISR terminates. Masking The programmer can mask or temporarily disable specific interrupts. In the prese nt context, we must set the interrupt mask such that IRQ 7 is enabled. Port 0x21 is associated with the interrupt mask. To enable a particular IRQ (say, IRQ 7), write a zero to that bit location. However, the other bits must not be altered. Prior to exiting from the 20

Online Device Controller program, the user should return the system to its origi nal state; by setting the altered bit (bit 7) of the interrupt mask to logic one and restoring the interrupt vector. If the IRQ Enable output is at logic one, a n interrupt occurs on a negative going transition on the /ACK input. Thus, in ad dition to setting the mask to entertain interrupts from IRQ 7, we must also set IRQ Enable to a logic one. Interrupt Service Routine Disable any further interrupts. Set Interrupt Mask to disable IRQ 7 interrupts. Set a variable such that in returning to the main program there is an indication that an interrupt has occurred. Indicate to the PC that the interrupt was proce ssed Enable all interrupts. Execute the required tasks of the ISR Disable all in terrupts Set Interrupt Mask to enable IRQ 7 interrupts. Enable all interrupts. 21

Online Device Controller DTMF Dialing System To speed up the dialing procedure and to make it more reliable, the DTMF dialing system is used. In this system, digits are transmitted as two tones simultaneou sly. This explains the name "Dual Tone Multi Frequency". It is also known as DTM F dialing or mf dialing. The tone frequencies are selected to avoid harmonic int erference from speech signals. There are eight frequencies defined in the DTMF s ystem: four in a low frequency group (679-941 Hz) and four in a high frequency g roup (1209-1633Hz). A valid digit is defined as one of the low frequency group together with one ton e out of the high frequency group. In total, there are sixteen combinations poss ible but we use only the digits 0-9. The maximum dialing speed with a DTMF syste m is typically 7 digits per second, i.e., a tone burst of 70 ms. With the pulse dialing system, the speed varies between 1.1 to 0.56 digits per second. The DTMF is therefore ten times faster. The major application for DTMF is low speed data transfer. Generation of DTMF 1209 Hz 1 697 Hz 770 Hz 852 Hz 941 Hz 4 7 * 1336 Hz 2 5 8 0 1477 Hz 3 6 9 # 1633 Hz A B C D 22

Online Device Controller Two tunable oscillators, one for the low frequency grou p and one for the high frequency group can be used to generate DTMF tones as sho wn in the figure above. However, due to accurate frequency demand, ICs were put together with a crystal oscillator and two synthesisers, which generate the DTMF tone digitally. Althoug h, it cannot synthesize the exact DTMF frequency, an inexpensive crystal has tur ned out to be the most popular type of DTMF synthesizer clock that generates a f requency of 3579545Hz and can be divided down to the DTMF frequencies with only a small error. Tone Details The exchange will use standard DTMF frequencies for the calling number on the li ne. The duration of the digit shall be 50 ms each. Interface to the Telephone Line The DTMF tones generated by the DTMF dialer must applied to the telephone line r especting the AAC and DC requirements of the PTT. Most bipolar DTMF dialers inco rporate an on chip line interface. This approach results in very simple and effi cient circuit designs. The DTMF dialer is powered from the speech circuit periph eral supply point. The DTMF tones are transmitted to the telephone line via the speech circuit line interface. The mute signal generated by the DTMF dialer, con trols the speech circuit and determines when to transmit speech and DTMF signals . The switch over from speech mode to dialing mode can be realized without notic eable audible clicks. If the speech circuit passes part of the signals on its DTMF input to the earpie ce output, a confidence tone will be introduced. This approach is called the com mon line interface architecture because both the speech and dialing parts of tel ephone are connected to the by the same interface. If an appropriate speech circ uit is not available for interfacing the CMOS DTMF dialer to the telephone line, a separate line interface for the dialer must be used. This requires a large nu mber of discrete components. 23

Online Device Controller Microcontrollers The Microcontroller is another branch in the evolution of microprocessor technol ogy. Instead of focusing upon larger word widths & address space, the emphasis h ere has been upon exceedingly fast real-time control. It has focused upon the in tegration of the facilities needed to support fast control into a single chip. I ts on chip resources provide an integrated approach to a variety of real-time co ntrol tasks. Features The MCS51 architecture consists, of the following features: Eight-bit CPU with r egisters A (Accumulator) and B Sixteen-bit Program Counter (PC) and Data Pointer (DPTR) Eight-bit Program Status Word (PSW) Eight-bit Stack Pointer (SP) Interna l ROM (8051) or EPROM (8751) or EEPROM (8951) Internal RAM of 128 bytes o o o Fo ur Register Banks each containing eight registers Sixteen bytes, which may be ad dressed at the bit level Eighty bytes of general-purpose data memory Thirty-two input/output pins arranged as four 8-bit Ports: P0-P3 Two 16-bit Time r/Counters: T0 and T1 Full duplex Serial Data Receiver/Transmitter: SBUF Control registers: TCON, TMOD, SCON, PCON, IP, and IE Two external and three Interrupt sources Oscillator and Clock circuits 24

Online Device Controller Programming Model The programming model of the MCS51 shows the MCS51 as a collection of 8 bit and 16 bit registers and 8 bit memory locations. These registers and memory location s can be made to operate using the software instructions that are incorporated a s part of the design. The program instructions have to do with the control of th e registers and digital data paths that are physically contained inside the Micr ocontroller, as well as memory locations that are physically outside the Microco ntroller. To make a Microcomputer a Microcontroller, several special function re gisters must be present. Each register, with the exception of the Program Counte r, has an internal 1-byte address assigned to it. Some registers are both byte a ddressable and bit addressable. That is, the entire byte of data at such registe r addresses may be read or altered, or individual bits may be read or altered. S oftware instructions are generally able to specify a register by its address, it s symbolic name, or both. The 8951 Microcontroller The 8951 is a second-generation Microcontroller belonging to the MCS51 family. C ompared to its predecessors, the 8951 provides a significantly more powerful arc hitecture, a more powerful instruction set, a full serial port and 4KB of intern al EEPROM. Some key product features include sophisticated I/O port capability, 4KB of EEPROM, 128 bytes of internal RAM, two 16-bit Counter-Timers. Because all these I/O devices are fabricated within the 8951, they form part of the program ming model. The 8951 has an 8-bit ALU. It has 32 I/O lines organised as four 8-b it I/O ports. The 8951 can also address external memory if there is not enough i nternal RAM or ROM. When used to address external memory, two ports provide the memory addressing and data lines. 25

Online Device Controller The Triac The Triac is a three terminal, gated npnp device for controlling ac current in e ither direction. Originally designated as a bi-directional triode thyristor, it is more commonly referred to as Triode ac semiconductor (TRIAC). Either positive or negative gate signals may be used to trigger the Triac into c onduction. This characteristic helps to simplify circuit design. The load or mai n current terminals are designated as MT1 and MT2. Usually, MT1 is taken as the point of reference for voltage and current measurements made and the gate termin al. Maximum current and offset voltage ratings are of the order of 40 A and 800 V, respectively. Theory of Operation The n and p semiconductor sections between MT1 and MT2 can be considered as para llel npnp and pnpn switches. The Triac is similar to connecting two SCRs in para llel for bi-directional, or full wave, current conduction. The primary differenc e between parallel SCRs and the equivalent switching sections of the Triac lies in the gate structure and trigger methods. The Triac can be switched to conduction either by gate triggering or by two othe r operating conditions- exceeding the break over voltage rating, or a sharp rise in off-state voltage. These methods of conduction are not employed in normal Tr iac operation but they may be considered as limiting factors in circuit design. As a result, Triacs switched to conduction by either of these mechanisms will no t be damaged, since the Triac merely switches to the on-state condition. In gene ral, the Triac requires no external over voltage protection. However, a snubber network, consisting of a series resistor and capacitor connec ted across the MT1 and MT2 terminals, can be used to protect a Triac from sharp 26

Online Device Controller increases in the off-state voltage. The charging capaci tor momentarily places the voltage across the resistor and the energy contained in the sharply rising portion of the voltage waveform is dissipated in the resis tor. Snubber circuit can also protect the Triac against voltage transients, whic h exceed the break over voltage level. The design of snubber circuits must take into account peak line voltages, load characteristics, and time constant of the RC network must be small when compared to the ac load conduction time. Triac Turn On Methods Triacs may be triggered into conduction by a variety if methods. The particular application will generally dictate the method if triggering to be employed. The gate circuits can be designed for static, zero voltage, or phase switching techn iques. Each method offers specific advantages and disadvantages. Static Switching Triacs employed in static switching circuits offer many advantages over mechanic al switching using relays or manually operated switches. This electronic switchi ng eliminates arcing and contact bounce, both of which are problems with moving physical contacts. These factors result in more reliable operation and virtual e limination of RFI. A resistor is connected to the gate circuit to limit the gate current and is about 100 ohms. Zero-Voltage Switching During zero voltage switching, the Triac conducts for virtually 360 of each cycle , and full power is delivered to the load. The Triac is triggered at approximate ly the 0 and 180 degree points in the ac cycle. During power off periods, the Tr iac is held in a nonconducting state. The ratio of power-on to power-off interva ls determines the average power applied to the load. The power-control time base may consist of intervals of 30 ac 27

Online Device Controller cycles (one half second). If the Triac is switched on f or 15 full cycles during each onehalf-second interval, the average power being a pplied to the load is one-half of full power. Triac zero crossing switching circuits are used in industrial control and relate d applications. Like static switching, zero crossing power switching systems are virtually free of radio frequency interference problems. Another important adva ntage is the inherent differential control capability that exists when gradual c hanges in average power can be applied to a load. Phase Control Switching Triac phase-controlled gate circuits allow conduction of load current during a s pecified portion of each ac half cycle. Simple resistive gate switching circuits can be employed to trigger the Triac for firing angles up to 90 degree in each half cycle. Resistance-capacitance phase shifting networks are used to delay the firing angle up to nearly 180-degree. The performance of phase controlled gate trigger circuits can be greatly improve d by the use of a trigger device. For low voltage levels, the trigger device exh ibits high impedance. Except for a small leakage current, no gate signal is pres ented to the Triac during this time. When the applied voltage is increased to th e break over level, the trigger device suddenly latches into conduction. This pr esents a fast rising trigger signal to the Triac, resulting in reliable turn on of load current. Common trigger devices in use today are the diac, unijunction transistors (UJTs) and special two-transistor configurations usually fabricated as one integrated circuit. 28

Online Device Controller The Project The Project 29

Online Device Controller Block Diagram 30

Online Device Controller Hardware Details The Hardware unit of the system includes the following sections: 1. 2. 3. 4. 5. 6. Microcontroller Card DTMF Decoder Card Relay Based ON/OFF Control Card Triac Based Intensity Control Card Status Reading Card Power Supply Card Microcontroller Card The Microcontroller Card is the most important section of the Online Device Contr oller Hardware. This card is designed so as to provide the facility to control ON /OFF devices and Intensity Variable loads. This Card is divided into the followi ng sub-sections: Parallel Port Input, DTMF Decoder Input, a 4-to-16 Decoder, NOT Gates and Connector for interfacing different Loads. The Microcontroller used is Atmel 89C51. The connections to the various Port pin s of the Microcontroller are as mentioned below: P1.0 to P1.7 Input Port connect ed to the Data bits of the Parallel Port P2.0 to P2.3 Input Port connected to th e BCD Output of DTMF Decoder P3.2 /INT0 Interrupt connected to /STROBE pin (Pin 1) of the PC Parallel Port P3 .3 /INT1 Interrupt connected to the Zero Crossing Detector circuit Output P0.4 to P0.7 Outputs the 4-bit ON/OFF Device Code to the 4-to-16 Decoder P3.1 The gate firing pulse for the Triac. The Delayed Steering Output (Pin 15) of the DT MF Decoder (MM 8870) is used to Interrupt the PC (IRQ 7) through Pin 10 of the P arallel Port. 31

Online Device Controller DTMF Decoder Card This Card makes possible the control of Load through the Cordless Phone. This ca rd includes the DTMF Decoder IC (MM 8870), and a Buffer IC (7407). The DTMF Decoder IC receives the tone input from the Telephone Line connected to the Telephone Exchange from the Base Unit of the Cordless Phone. For each key p ressed, the DTMF tone produced is decoded to the corresponding 4-bit BCD Code by IC MM 8870. The reception of a valid DTMF tone generates a pulse at the Pin 15 of this IC, which is used to interrupt the PC through the Parallel Port pin 10 ( /ACK). Pin 11-14: 4-bit BCD Output Pin 15: Delayed Steering Output A 7407 Buffer IC is also used to drive the Decoder output before sending it to t he Microcontroller Input Port. Relay Based ON/OFF Control Card This Card includes a D Flip-Flop (CD 4013), Optocoupler (MCT2E), Relay Driver Ci rcuit and a 12 V single-pole Relay. The D Flip-Flop is wired as a Toggle Flip-Fl op, the output of which toggles for every rising edge of its Clock input receive d from the Microcontroller Card. The MCT2E provides electrical isolation. Each t ime the device is selected by the Microcontroller, the Load (say, a Bulb) connec ted to the Relay toggles between ON and OFF states. Triac Based Intensity Control Card The Triac Based Intensity Control Card consists of the Zero Crossing Detector Ci rcuit and the Triac Based Intensity Control circuit. The Zero Crossing circuit p rovides the reference signal for the MCU for generating firing pulses. It includ es an Opamp Comparator receiving 12 V AC supply and a 555 Timer IC wired as a Mo noshot. The Triac circuit makes use of MOC 3021, an opto-isolated Triac Driver I C which is connected to the gate of the Triac. The variation in Firing Pulses ge nerated by the MCU, 32

Online Device Controller at the Triac Gate results in proportional Intensity var iation at the Load connected to the Triac. Status Reading Card The Status Reading Circuit consists of a Current Transformer, which senses the c urrent through the Load circuit. The CT produces a very low voltage which is amp lified using an Opamp amplifier (A 741) and after opto isolation through an MCT2E , is fed to the PC parallel port input pin. This circuit can sense whether the L oad is On or OFF. Power Supply Card The Power Supply Card provides the necessary DC voltages +5V, +12V and -12V requ ired to power the various Cards used in the entire Hardware. This uses a CentreT apped Transformer (230/12-0-12). The Power Supply Card uses 7805, 7812 and 7912 Voltage Regulator ICs for proper regulation. To ensure extremely good electrical isolation by the Opto couplers used, the Hardware unit comprises of two similar Power Supply Cards fed by the two secondary of the Transformer. 33

Online Device Controller Software Details The Online Device Controller software section mainly comprises the Web Server Inte rface software (using CGI) and the Microcontroller programs. Web Interface This includes the interface between the hardware to the Internet. This is accomp lished by running a Web Server in a dedicated computer, the parallel port of whi ch is connected to the Online Device Controller Hardware unit. The Web server runn ing is used to execute CGI programs. The Web server serves the homepage of the On line Device Controller Website, when a remote browser requests the homepage at th e given URL or IP address. Initially, a username-password check is done and on s uccess, the present status of devices is available on the Web page as a Control Menu. In the Control Menu, the user can change the status of the appliances as d esired. The new control information is sent to the Web server using a GET method , the Web Server passes this information to the CGI program in the CGI-BIN direc tory, which checks the present status of devices read through the Parallel port with the new control signal received, and outputs an appropriate byte at the Par allel port, after interrupting the 8951 MCU. After a short delay, the new status of devices is again read and the response is sent back to the Web Browser. At p resent, we are offering the Web Interface software that runs on Windows 9x platf orm. For this, we used Xitami, a commonly available Web Server for Windows platf orm. The CGI programs were coded in the C language and the Web pages were designed using an HTML authoring tool. Microcontroller Programs The Microcontroller programs are used to manage the Hardware unit of the Online D evice Controller. Written in the 8051 Assembly language, this includes the progra ms to initiliase the Microcontroller, External Interrupt Service Routines, and p rograms for timing and firing pulse generation. 34

Online Device Controller Flow Charts CGI Program Read the CGI Environment Read the Present Status of Devices from Parallel Port Decode Query-String Store the requested lamp and Fan Modes Interrupt the 8951 MCU and output the new Fan Mode through Parallel Port Is Lamp mode requested = Status Read N Interrupt 8951 MCU and O/P Data through Parallel Port y C 35

Online Device Controller C Insert Delay Read the Present Status of Devices Send valid HTTP Response Header and new Device Status to the Web Browser End MCU Main Program Start Initialize SP Timers, Interrupt Fan Mode Register 8951 Enters into a wait loop, ready to accept interrupts 36

Online Device Controller Parallel Port Interrupt Service Routine (/INT 0) 37

Online Device Controller Phone Initialize Port 2 and Read 4 Bit BCD Code from DTMF Decoder Store 4 Bit BCD Code in R5 Is R5=1 Y Output Data to Port 0 N Is R5=2 Y Set Fan Mode to 0 N Is R5=3 Y Set Fan Mode to 1 N Is R5=4 Y Set Fan Mode to 2 N Is R5=5 Y Set Fan Mode to 3 N Reti 38

Online Device Controller Fan Select Lower 3 bits for Mode Selection Is A=00h N Is A=01h N Is A=02h N Is A=03h N Y Set Fan Mode (R6) to 0 Y Set Fan Mode (R6) to 1 Y Set Fan Mode (R6) to 2 Y Set Fan Mode (R6) to 3 Reti Timer 0 Interrupt Service Routine Timer 0 Clear P3.1 Stop Timer 0 Reti 39

Online Device Controller Zero Crossing Detector Interrupt Service Routine (/INT 1) ZCD Is Fan Mode =0 Y N Is Fan Mode =1 Y N Is Fan Mode =2 Y N Is Fan Mode =3 Y N Clear P3.1 Y Set P3.1 Set P3.1 Set P3.1 Initialize Timer 0 to Mode 1 Initialize Timer 0 to Mode 2 Initialize Timer 0 to Mode 3 Loads Count EC78h for a delay of 5ms Loads Count D120h for a delay of 12ms Loads Count BFC8h for a delay of 19ms Clears Overflow Flag, Start Timer Clears Overflow Flag, Start Timer Clears Overflow Flag, Start Timer Reti 40

Online Device Controller Working of the System A typical scheme of the working of the system can be described as follows. A remote user can log in from any location in the world to the homepage of the W eb server through the Internet/Intranet via a Web Browser. This request is proce ssed by the CGI and after security check, the user is presented with the current status of equipments. Now he can control the equipments as required and he can send the information through a form or menu. According to the control informatio n received, the CGI executes the required programs to read/write data to the par allel port (LPT1). Local control is made possible with a Cordless telephone. The PC and phone produ ces their own interrupts. When a key on the keypad is pressed, the arrival of a new valid DTMF tone will interrupt the PC using the PC Parallel port (using IRQ 7). The DTMF tone generated from the telephone line is decoded by the DTMF Decod er which produces the corresponding 4 bit BCD code output which is read by the M icrocontroller. The Microcontroller 89C51 reads the appropriate control signal w hen interrupted by the PC (through /INT0 pin of the Microcontroller). This is pr ocessed and is sent to the output port, and to the devices. ON/OFF devices are c ontrolled through the Relay Based Control circuit and Intensity Variable Loads a re controlled via the Triac Based Circuit. The firing pulse for the Triac is gen erated by the 8951. To synchronize the firing pulse with the AC cycle, a Zero Cr ossing Detector circuit is also used which is connected to another interrupt pin (/INT1) of the Microcontroller. After executing the control signals, the actual status of the equipments are rea d by sensing the load current by means of a Current Transformer, is fed back thr ough Status Reading circuit and is read through the input pins of the PC Paralle l Port. Finally, the remote user will receive back the confirmation message that the sta tus of the devices has been changed as per the control signal sent by him. This completes the cycle of events. 41

Online Device Controller Result and Discussion Through this project, the Online Device Controller we are sure that we have been a ble to accomplish a good task, something which will be useful to the society as a whole. In fact, right from the design to the final implementation, we had gone through several steps, and each of these was completed satisfactorily. After th e initial design of the circuits, these were assembled on the Breadboard and ver ified at the labs. The Microcontroller program was developed using a software si mulator, the Acebus 8051 IDE and the program was loaded into the Microcontroller EPROM. The Web Interface software and DTMF Interrupt Service software were code d in C and were thoroughly verified. The PCBs for the circuits were designed and etched. A user friendly and pleasing Front Panel and Cabinet was designed and o btained. The entire hardware was assembled. The software was checked on real tim e and the entire system was again verified. The final product the Online Device C ontroller is thus made available as a finished product. The approximate cost of t he entire product (on developmental stage) is Rs.3000/-. 42

Online Device Controller Conclusion and Future Scope Thus, the Online Device Controller (ODC) as implemented through our project has e merged as a valuable product useful for several applications, ranging from Indus trial Control applications to Office Administration and even for domestic purpos es. In this world of Convergence, where everything from Cell phones to Palmtops meet the Internet, we feel proud that our project has added a small drop to a bi g ocean. The present system is presented as a general purpose one and can be enhanced by adding several other features specific and relevant to the environment where it is to be installed. This will bring greater and efficient utilization of the sys tem. The project can be very well implemented in Industrial applications if slig htly more complicated Status Reading Circuit and Automatic Control Loop is added . A Telephone based control from Remote locations is also feasible with slight a dditions in hardware and software. The possibilities offered by this system for the future, is limited only by ones imagination. The day is not a distant one, when all devices around us will get l inked to the Internet and thats exactly what we are trying to prove through this project. Imagine controlling all the gadgets of your home from any corner of the world, or switching off the fan above your Office desk, even while you are on a flight to New York. 43

Online Device Controller References Books [1] [2] 2000 Manger, J., The 8051 International [3] Perl , CGI, and JavaScript Complete, BPB Publications, New Delhi, Jason J., The World Wide Web, Mosaic and More, 1994 Ayala, Kenneth Microcontroller: Architecture, Programming & Applications, Penram Publishing (India), Mumbai, 1996

Websites [1] [2] [3] [4] [5] [6] [7] http://www.us-epanorama.net http://www.8052 .com http://www.w3.org http://www.apache.org http://www.intel.com http://www.ace bus.com http://www.google.com 44

Potrebbero piacerti anche