CHAPTER 1 INTRODUCTION

1

1.1 BACKGROUND
Embedded system is an intelligent system that has the capability of processing, monitoring and controlling. It may comprise of Sensors, Microcontrollers, FPGA, ASIC, etc. It typically has a specialized function with programs stored on ROM. Examples of embedded systems are automatic environmental systems, security systems, and entertainment systems. An added feature in any embedded system is its ability to communicate. The communication can be via Bluetooth, WI-FI, GSM, or Ethernet cables. The TCP/IP protocol is a widely used standard for modern digital communication. A weather station is a facility with instruments and equipment to make weather observations by monitoring atmospheric conditions. The project we have undertaken is “IP based Weather Station (Mausam Parisuchak)”. It includes the three concepts we discussed earlier viz. embedded systems, TCP/IP communication, and weather station. It provides real time data of weather in remote/inaccessible locations through a wireless /wired connection.

1.2 NEED OF THE PROJECT
Nepal being a mountianous country it is difficult to build some development infrastructures. One of the biggest mountain ranges of the world, The Himalayas, lies in Nepal. Various organisation like ACAP, ICIMOD, and many other NGOs and GOs are working to solve this problem through sustainable tourism and natural disaster mitigation (eg:- bursting of glacier lakes, avalanche, etc). The existing weather data collection technology in Nepal is backward for example in Godawari ICIMOD is implementing data loggers which collect data and logged into the magnetic hard disk which is swept at a frequency of 48 hrs manually. Our National Meteorological Department (NMD) has manual data collection process. Sometimes this may result in the problem of unavailability of weather data at the time of necessity. Our project “IP based weather station” can play a vital by addressing to these problems and providing data which can be used for monitoring various activities. 2

1.3 OBJECTIVE
Main objective of our project is to make internet/ip enabled embedded device serving as advanced remote data logger which can be accessed remotely via workstation. Our internet enabled device “alias: Mausam Parisuchak” will be interfaced with various sensors like temperature sensor, humidity sensor.

This project finds its application in various fields like Weather Forecasting Department, organizations like ICIMOD (International Center for Integrated Mountain Development), ACAP (Annapurna Conservation Area Project), etc which works on remote monitoring and development of the mountainous areas. Looking at the benefits of its technical efficiency and practical implementation along with its coverage of course materials like Telecommunication, Instrumentation, Electronic Circuits, we selected this project as our final year project. On completion of this project, our module will be used by ICIMOD at Godawari for its practical implementation.

1.4 OUTLINE OF THE PROJECT
The system designed in our project applied to monitor weather data from the remote field. The weather data is then communicated or transmitted to the central server through an Ethernet connection. The server is a web and database server which holds all the past data transmitted by the system and also servers web pages to the public internet users. The sensors we have decided to use are the Temperature and Light Dependent Sensors. They are connected to the PIC18F4620 microcontroller.

3

The PIC18F4620 microcontroller is used as a computer and the ENC28J60 is used to connect the microcontroller to a LAN. The LCD display and the serial port interface provide more functionality to the overall system. The LCD displays the current and any new IP address of the Ethernet chip. The serial connection is used rarely in our system like to configure our module (e.g. to change the IP address). It can also be used for debugging purposes. Thus serial connection is not so compulsory section in our project.

Fig1.1: Simplified Diagram of Component Interconnections 4

CHAPTER 2 LITERATURE REVIEW

5

The LM35 generates a higher output voltage than thermocouples and may not require that the output voltage be amplified.1 Temperature sensor The LM35 is an integrated circuit sensor that can be used to measure temperature with an electrical output proportional to the temperature (in oC). and precise inherent calibration make interfacing to readout or control circuitry especially easy. as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling.1. linear output. The sensor circuitry is sealed and not subject to oxidation.2. 6 .1 Sensors 2. etc.1.1 HARDWARE COMPONENT OVERVIEW Our project comprises of following hardware components: • Sensors o Temperature o LDR • • • • • • PIC18F4620 microcontroller ENC28J60 Ethernet chip Magnetic Ethernet jack RS232 Serial port LCD LAN connectivity 2. The LM35's low output impedance. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin.1.

Fig 2.1: LM35 connection circuit Features • • • • • • • • • • • Calibrated directly in ° Celsius (Centigrade) Linear + 10.1 Ohm for 1 mA load 7 . 0.08°C in still air Nonlinearity only ±¼°C typical Low impedance output.5°C accuracy guaranteeable (at +25°C) Rated for full -55° to +150°C range Suitable for remote applications Low cost due to wafer-level trimming Operates from 4 to 30 volts Less than 60 µA current drain Low self-heating.0 mV/°C scale factor 0. 0.

3: Characterstics curve of LDR Fig2.1. It is made of a high-resistance semiconductor. Fig 2.2 LDR Fig2. thereby lowering resistance. If light falling on the device is of high enough frequency. photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band.4: Typical Application circuit 8 .2 LDR (Light Dependent Resistor) Light Dependent Resistor (LDR) also known as photoresistor is an electronic component whose resistance changes with the incident light intensity.1. The resulting free electron (and its hole partner) conduct electricity.2. The resistance of LDR may be 5000 ohm in daylight and 20000000 ohm in dark condition.

2. AVR but we opted for PIC family of microcontroller. C.2. D. 2. It has 13 ten bits ADC channels which makes it easy for us to interface the sensors. 3. We specifically choose PIC18f4620 because 1. B. They are A. Port A.1. It has large number of I/O pins. E.5: Pin Configuration of PIC18F4620 The PIC18f4620 has 5-ports. It has high memory space. It has built in ADC consumption during operation.2 Microcontroller (PIC18f4620) We could have used different microcontroller such as 8051. B. It has the following advantages 1. All these ports are in digital I/O besides A6 9 . C. It is developed using nanoWatt TECHNOLOGY that reduces power Fig2. D are of 8-bits in length but port E is of only 4-bits length.

can be regarded as a peripheral device.USART 13 channels 75 instruction Table 2.and A7. 1 is set to low the data memory of microcontroller will be reset.E1.1: Features of PIC18f4620 There are three types of memory in PIC18 Enhanced microcontroller devices: •Program Memory •Data RAM •Data EEPROM As Harvard architecture devices.A1. The oscillator is connected to these pins.D.B1.B4. The analog input pins are in A0. The serial port data to the computer is transmitted from C6 and received form C7. The data EEPROM.B2.A3.A2.E2.A5. 10 .)4kb 1kb Ports A.C. for practical purposes. If pin no.B3.B0.E0.E MSSP. since it is addressed and accessed through a set of control registers.B. the data and program memories use separate busses. this allows for concurrent access of the two memory spaces. The serial data to the Ethernet chip is transmitted from C5 and received from C4. Features Operating frequency Program memory Temporary data memory(Ram) Permanent data memory(EEPROM) I/O Ports Serial communication 10-bits A/D Module Instruction sets PIC18F4620 DC upto 40MHz 64kb (Approx.

Each Register in the data memory has a 12-bit address. Program Memory PIC18 microcontrollers implement a 21-bit program counter. The data memory contains Special Function Registers (SFRs) and General Purpose Registers (GPRs). allowing up to 4096 bytes of datamemory.6: Memory Organisation ii. PIC18F4620 device implement all 16 banks. The Reset vector address is at 0000h and the interrupt vector addresses are at 0008h and 0018h. Indirect or Indexed Addressing modes. GPRs are used for data storage and scratchpad operations in the user’s application. The memory space is divided into as many as 16 banks that contain 256 bytes each. therefore. Fig2. Writing or erasing program memory will cease instruction fetches until the operation is complete.i. 11 . The program memory cannot be accessed during the write or erase. An internal programming timer terminates program memory. Data Memory The data memory in PIC18 devices is implemented as static RAM. Accessing a location between the upper boundary of the physically implemented memory and the 2-Mbyte address will return all ‘0’s (a NOP instruction). PIC18F4620 have 64Kbytes of Flash memory and can store up to 32. The entire data memory may be accessed by Direct. SFRs start at the top of data memory (FFFh) and extend downward to occupy the top half of Bank 15 (F80h to FFFh). code cannot execute. These registers are implemented as static RAM. which is capable of addressing a 2Mbyte program memory space.768 single-word instructions. PIC18 devices have two interrupt vectors. The Special Function Registers (SFRs) are registers used by the CPU and peripheral modules for controlling the desired operation of the device.

The write time is controlled by an on-chip timer. with data rates of up to 10Mb/s. The EEPROM is readable and writable during normal operation. It incorporates a number of packet filtering schemes to limit incoming packets. A byte write automatically erases the location and writes the new data (erase-before-write). two pulse transformers and a few passive components are all that is required to connect a microcontroller to a 10Mbps Ethernet network. the 12 . If it is connected to an automatic duplex negotiation enabled network switch or Ethernet controller.3 specifications. It also provides an internal DMA module for fast data throughput and hardware assisted IP checksum calculations. The ENC28J60 is a stand-alone Ethernet controller with an industry standard Serial Peripheral Interface (SPI). The ENC28J60 does not support automatic duplex negotiation. Communication with the host controller is implemented via two interrupt pins and the SPI.3 Ethernet chip (ENC28J60) There are many Ethernet chip in the markets but we choose ENC28J60 because it is produced from the same manufacturer as the PIC. Data EEPROM The data EEPROM is a nonvolatile memory array separate from the data RAM and program memory that is used for long-term storage of program data. The ENC28J60 meets all of the IEEE 802. It is not directly mapped in either the register file or program memory space but is indirectly addressed through the Special Function Registers (SFRs).The ENC28J60 is designed to operate at 25MHz with a crystal connected to the OSC1 and OSC2 pins. 2. It is designed to serve as an Ethernet network interface for any controller equipped with SPI. With the ENC28J60. it will vary with voltage and temperature as well as from chip to chip. The EEPROM data memory is rated for high erase/write cycle endurance.iii.1. Two dedicated pins are used for LED link and network activity indication. Thus it is easier for us to interface the two chips from microchip.

7: Detail Overview of ENC28J60 13 . Supports one 10BASE-T port with automatic polarity detection and correction 4. Programmable automatic retransmit on collision 6. To communicate in Full-Duplex mode. the ENC28J60 and the remote node (switch. Programmable automatic rejection of erroneous packets 8.3 compatible Ethernet controller 2.3.ENC28J60 will be detected as a half-duplex device. 2.2 Ethernet Controller Block Diagram Fig2.3. router or Ethernet controller) must be manually configured for full-duplex operation.1. Programmable padding and CRC generation 7. Supports Full and Half-Duplex modes 5.1. SPI Interface with speeds up to 10Mb/s 2. IEEE 802.1 Ethernet Controller Features: 1. Receiver and collision squelch circuit 3.

A dual port RAM buffer for received and transmitted data packets. 3. The device also contains other support blocks. Control Registers which are used to control and monitor the ENC28J60.The ENC28J60 consists of seven major functional blocks: 1. 4. The bus interface that interprets data and commands received via the SPI interface. transmit and receive blocks. Fig2.3 compliant MAC logic. such as the oscillator. An SPI interface that serves as a communication channel between the host controller and the ENC28J60. The MAC (Medium Access Control) module that implements IEEE 802. The PHY (Physical Layer) module that encodes and decodes the analog data that is present on the twisted pair interface. An arbiter to control the access to the RAM buffer when requests are made from DMA. 7.8: Pin Configuration of ENC28J60 14 . on-chip voltage regulator. 2. 6. level translators to provide 5V tolerant I/Os and system control logic. 5.

The PHY registers are used for configuration. There are three types of memory in the ENC28J60: •Control Registers •Ethernet Buffer •PHY Registers The control registers’ memory contains Control Registers (CRs). The registers are not directly accessible through the SPI interface. The Ethernet buffer memory can only be accessed via the read buffer memory and write buffer memory. These are used for configuration. they can only be accessed through the Media Independent Interface (MII) implemented in the MAC. control and status retrieval of the PHY module.9: Typical Application Circuit of Ethernet Chip All memory in the ENC28J60 is implemented as static RAM. 15 . control and status retrieval of the ENC28J60. The sizes of the memory areas are programmable by the host controller using the SPI interface.Fig2.The Ethernet buffer contains transmit and receive memory used by the Ethernet controller in a single memory space. The Control Registers are directly read and written to by the SPI interface.

ESTAT. Control Registers The Control Registers provide the main interface between the host controller and the on-chip Ethernet controller logic. Writing to these registers controls the operation of the interface. while reading the registers allows the host controller to monitor operations. ECON2 and ECON1. 16 . The Control Register memory is partitioned into four banks. The last five locations (1Bh to 1Fh) of all banks point to a common set of registers: EIE. Each bank is 32bytes long and addressed by a 5-bit address value. These are key registers used in controlling and monitoring the operation of the device.Fig 2.10: Memory Organization of ENC28J60 i. EIR.

17 . their contents should be ignored when read. Ethernet Buffers The Ethernet buffer contains transmit and receive memory used by the Ethernet controller. however. iii. access is accomplished through a special set of MAC control registers that implement a Media Independent Interface for Management (MIIM). only 9 locaions are implemented. The entire buffer is 8Kbytes. the PHY registers are not directly accessible through the SPI control interface. divided into separate receive and transmit buffer spaces. All PHY registers are 16 bits in width. Unlike the control registers or the buffer memory. There are a total of 32 PHY addresses. All reserved locations should be written as ‘0’. The sizes and locations of ransmit and receive memory are fully programmable by the host controller using the SPI interface. Writes to unimplemented locations are ignored and any attempts to read these locations will return ‘0’. PHY Registers The PHY registers provide configuration and control of he PHY module.ii. as well as status information about its operation. Instead.

12: Schematics of Magnetic Ethernet Jack 18 .4Magnetic Ethernet jack Magnetic Ethernet jack is a single port shielded RJ45 connector with integrated 10/100 magnetic.1.2. Fig 2.11: Magnetic Ethernet Jack Fig2.

Network equipment (such as routers and switches) often have serial ports for configuration. Throughout most of the history of personal computers.1. scientific analysis. Serial ports are still used in these areas as they are simple.5 Serial port interfacing A serial port is a serial communication physical interface through which information transfers in or out one bit at a time (contrast parallel port). 2. and USB all send data as a serial stream. data transfer through serial ports connected the computer to devices such as terminals and various peripherals. Serial ports can also be found in industrial automation systems. the term "serial port" usually identifies hardware more or less compliant to the RS-232 standard. intended to interface with a modem or with a similar communication device. cheap and allow interoperability between devices.2.13: Serial (RS232) Port Interface Pin Out and Signal 19 . FireWire. Such interfaces are Ethernet.5.1 Serial (RS232) port interface pin out and signal RS232 DB9 pinout Fig 2.1. and some industrial and consumer products.

C. It includes a Charge Pump. also includes two receivers and two transmitters in the same package. MAX232 is a RS232 level converter. one for the receive line and one for the transmit line is not required. Necessity of two chips.5. As we have already covered. Therefore the first step to connecting a device to the RS-232 port is to transform the RS232 levels back into 0 and 5 Volts.1.9 pin# Pin 3 Pin 2 Pin 7 Pin 8 Pin 6 Pin 5 Pin 1 Pin 4 Pin 9 Abbreviation TD RD RTS CTS ` DSR SG CD DTR RI Full Name Transmit Data Receive Data Request To Send Clear To Send Data Set Ready Signal Ground Carrier Detect Data Terminal Ready Ring Indicator Table 2. which generates +10V and -10V from a single 5V supply. This is handy in many cases when we only want to use the Transmit and Receive data Lines.2: Showing the RS232 pin configuration and signals 2. This I. this is done by RS-232 Level Converters. 20 .2 RS-232 Level Converters Almost all digital devices which we use require either TTL or CMOS logic levels.

The large values of capacitors are not only bulky. Therefore other devices are available which use smaller capacitors and even some with inbuilt capacitors.14: Pin configuration of MAX232 Fig 2. but also expensive.15: Typical MAX-232 circuit However all this convenience comes at a price. There are also many variations of these devices.Fig 2. but compared with the price of designing a new power supply it is very cheap. 21 .

7 LAN connectivity Our device can be connected to a LAN either through a wired Ethernet cable or through a wireless Wi-Fi access point/transmitter.1.1. flat display device made up of any number of color or monochrome pixels arrayed in front of a light source or reflector PIN NO. 2.2 SOFTWARE COMPONENT OVERVIEW Our project comprises of following software components: • TCP/IP Stack 22 .6 LCD A liquid crystal display (LCD) is a thin.2.3: Pin connections of LCD 2. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 SYMBOL Vss Vcc Vee RS R/W E DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 LED + LED - FUNCTIONS 0 volts 5 volts Low=instruction code input High=data input High=data read Low=data write High to low =Enable signal Data bus line Table 2.

Internet Software based on this model is divided into multiple layers.• • • • C language Web/Database server PHP Proteus simulation software 2.1 TCP/IP STACK Many TCP/IP implementations follow a software architecture referred to as the “TCP/IP Reference model”.2.16: Comparing our TCP/IP Model with the TCP/IP Reference Model 23 . TCP/IP Reference Model Our TCP/IP Model Fig2. where layers are stacked on top of each other (thus the name “TCP/IP Stack”) and each layer accesses services from one or more layers directly below it.

67. To identify an individual computer on the Internet. Unlike the TCP/IP reference model. The code implementing each layer resides in a separate source file.2. 3. A network address.. MAC (Media Access Control Layer): The Ethernet hardware doesn't understand IP addresses. while the services and APIs (Application Programming Interfaces) are defined through header/include files. A system address.45. 1.Like the TCP/IP reference model. while ARPTask manages the services of the Address Resolution Protocol (ARP) layer. A subnet address. 2. An additional major departure from traditional TCP/IP Stack implementation is the addition of two new modules: “StackTask” and “ARPTask”. 2. StackTask manages the operations of the stack and all of its modules. but they must occupy a total of four bytes. The size of these fields varies. The current version of the Internet Protocol (IPv4) uses a four-byte number. it has its own addressing scheme based on a unique six-byte address for each network adaptor manufactured. many of the layers in our TCP/IP Stack directly access one or more layers which are not directly below it.g. which uniquely identifies an organization.1. a. is made primarily on the amount of overhead and whether a given service needs intelligent processing before it can be passed to the next layer or not. This address consists of three parts. (e. expressed in dotted decimal notation. A decision as to when a layer would bypass its adjacent module for the services it needs. this is generally called the media access and control (MAC) address. 24 . depending on the size of the organization.8). our TCP/IP Stack divides the TCP/IP Stack into multiple layers. which identifies a single node on that subnet.1 Stack Modules Following are some of the stack modules and API used. it must have a unique address. which identifies a subnet within that organization. 123.

For example. c.b. if you ask a router to forward a datagram to an address it can't reach. and then uses HTTP to send a request. e. whereas connectionless applications use user datagram protocol (UDP). It closes the connection between those two nodes as well. ICMP (Internet Control Message Protocol) ICMP is an adjunct to IP that gives all nodes on the network the ability to perform simple diagnostics and return error messages. f. HTTP is refreshingly simple: 25 . there is a split: connection-oriented applications use transmission control protocol (TCP). An IP packet is known as a "datagram”. Above these. ARP & ARPTASK (Address Resolution Protocol) The IP-to-hardware address translation protocol is called address resolution protocol (ARP). To fetch a Web document. ICMP messages are contained within the data field of a IP datagram using IP protocol number. It handles the network failure. A node sends a subnet broadcast containing the IP address that is to be resolved. and the node that matches that IP address sends a response with its hardware address. IP (Internet Protocol) The first software layer above the network drivers is IP and its partner ICMP. HTTP (Hyper Text Transmission Protocol) HyperText Transfer Protocol (HTTP) simply involves an exchange of text messages followed by the transfer of Web data down a TCP connection. TCP (Transmission Control Protocol) TCP helps to do several jobs at once. Compared to TCP. the browser opens a TCP connection to server port 80. It initiates a connection between two nodes and sends data bidirectionally between those two nodes. network datagram loss. d. it will return an ICMP "destination unreachable" message.

4: Request For Comment The complete list of Internet RFCs and the associated documents are available on many Internet web sites.rfc-editor.org/rfcs and www.faqs. graphical data) is then sent down the same connection. Table2. the information (document text.the request and response are one or more lines of text. each terminated by the newline (carriage return. the one used to fetch documents is the get method. line feed) characters. Interested readers are referred to www. If the request is successful.org as starting points. 26 . HTTP commands are called methods. which is closed on completion.

Components of the C language such as comment definition. variable definition. operator’s usage. The peripheral routines that are provided include both those designed to use the hardware peripherals and those that implement a peripheral interface using general purpose I/O lines. function declaration. _asm _endasm Auto Break Case Char Const Continue Default Do Double Return Extern Far Float For Goto If Int Long Near Ram Volatile While Short Signed Sizeof Static Struct Switch Typedef Union Unsigned Void Else Enum Table 2. Some of the keywords used in the MCC18 language are shown in table.5: Keywords of MCC18 The processor-specific library files contain definitions that may vary across individual members of the PIC18 family.2 “C” language with MCC18 compiler The C language compiler/linker used by us was the MCC18 of microchip. Software Peripheral Library.2. structures. The IDE used by us was the MPLAB of microchip. 27 . pointers.2. program control statements. The functions included in the processor-specific libraries include Hardware Peripheral Functions and. arrays. This includes all of the peripheral routines and the Special Function Register (SFR) definitions. constants definition. and unions are similar to the ANSI C standards. strings.

It occupies more memory space. multi-user SQL database management system (DBMS). The MySQL server and official libraries are mostly implemented in ANSI C/ANSI C++. Web/Database server MySQL is a multithreaded. MAMP. MySQL is popular for web applications and acts as the database component of the LAMP. such as ASP or ColdFusion. and WAMP platforms (Linux/Mac/Windows-Apache-MySQLPHP/Perl/Python). which is often combined with MySQL 28 .3. 2. It is inconvenient for time critical applications. Libraries for accessing MySQL databases are available in all major programming languages with language-specific APIs.Advantages of C language in embedded systems: 1. and for open-source bug tracking tools like Bugzilla. It has many built in functions Disadvantages of C language in embedded systems: 1. The basic program runs as a server providing multi-user access to a number of databases.2. In addition. an ODBC interface called MyODBC allows additional programming languages that support the ODBC interface to communicate with a MySQL database. It is easier to code and requires less effort. Its popularity for use with web applications is closely tied to the popularity of PHP and Ruby on Rails. 2. 2.

The PHP program takes input from a file or stream containing text and special PHP instructions and outputs another stream of data for display. of doing this are the following:  if the request identifies a file stored on disk. The task of such an information server is to respond to requests (in the case of web servers. run the command and return its output 29 .2. There are eight data types in PHP which facilitates the programmer are: Integer. Boolean. it can also be used for command-line scripting and client-side GUI applications. In addition. requests from client web browsers) by returning output. for the server. Object.  if the request identifies an executable command and possibly arguments.4 PHP (PHP: Hypertext Preprocessor) PHP is a widely-used general-purpose server side scripting language that is especially suited for Dynamic Web development and can be embedded into HTML. the server analyzes what the request asks for. Null. PHP primarily acts as a filter. Each time a request is received. However. taking PHP code as its input and creating Web pages as output. The PHP Group also provides the complete source code for users to build. String. CGI The Common Gateway Interface (CGI) is a standard protocol for interfacing external application software with an information server. and returns the appropriate output. Double.2. commonly a web server. answers to many questions can often be found by doing a simple internet search. The two simplest ways. Resource PHP has a formal development manual that is maintained by the free software community. customize and extend for their own use. return the contents of that file. PHP generally runs on a web server. PHP can be deployed on most web servers and on almost every operating system and platform free of charge. Array.

CGI defines a standard way of doing the second. and how the command can pass back extra information about the output (such as the type) in the form of headers. Output from the program is collected by the Web server. Finally the required graphical representation of the data can be displayed interactively in the website. the corresponding program is called. These CGI variables can be accessed by CGI scripts running in web/database server. with any data that the client sent as input. It defines how information about the server and the request is passed to the command in the form of arguments and environment variables. The information regarding physical parameters is sensed from the sensor. This is received by microcontroller and is stored in CGI variables. augmented with appropriate headers as defined by the CGI spec. 30 . Whenever a request to a matching URL is received. The data are stored in the MySQL database. and sent back to the client.

there is no need for them to wait until a physical prototype exists.labcenter. In this software we simulated most of our project circuits and codes including the ENC28J60 and PIC18F4620 interconnection and the C language code. flexible and parallel development of both the system hardware and the system firmware. Proteus VSM for PIC18 contains everything we need to develop. Proteus consists of 2 major software parts.2. Its demo version can be downloaded from www. quality and flexibility throughout the design process. The unique nature of schematic based microcontroller simulation with Proteus facilitates rapid. In larger organisations where the two roles are seperated.2.uk for free. The Proteus Design Suite is wholly unique in offering the ability to co-simulate both high and low-level micro-controller code in the context of a mixed-mode SPICE circuit simulation. If one person designs both the hardware and the software then that person benefits as the hardware design may be changed just as easily as the software design.5 Proteus: Simulation Software Proteus is circuit simulation software. In short. They are ISIS and ARES. Proteus VSM improves efficiency. 31 . test and virtually prototype our embedded system designs based around the Microchip Technologies PIC18. the software designers can begin work as soon as the schematic is completed. ISIS is a simulation package whereas ARES is a PCB making package.co.

CHAPTER 3 METHODOLOGY 32 .

de/mbhp_burner.1 HARDWARE DESIGN IMPLEMENTATION 3. It was really great to find the programmer circuit working fine. etc.3.HEX file in the PIC we used the provided P18 software. 33 . ADC port programming. We did some basic programs like LED blinking. We searched for various programmers circuits and designed in breadboard.html) For loading the . LCD display. Then we stepped toward sensor interfacing and Ethernet interfacing.1 PIC Programmer Circuit Fig3.ucapps.1. which worked fine. Then we started to deal with PIC18F4620.1: Complete Circuit Diagram of the PIC18 Programmer (Ref: http://www. Finally we got above circuit. But all circuits failed.

2: Sensor Interfacing with PIC18F4620 LM 35 is connected to the analog port of the PIC18F4620 microcontroller. The PIC18F4620 then changes the analog data to 10 bits and stores it in it’s registers ADRESH:ADRESL which will contain the value of the last completed conversion. As we know the PIC18F4620 has 13 analog pins which can also function as digital I/O. Only then is the data from the sensor considered to be valid.2 Sensor interfacing Fig3.1. Before the sensor is connected to one of these pins. 34 . the PIC18F4620 must first be configured to accept analog data on the specified pins.3.

The LCD we used in this project was JHD162A series from ETC corporation. The LCD could be used in 4 bit or 8 bit mode.3 LCD interfacing Fig3. The 4 bit mode saves pins in the microcontroller but requires more processing time and makes the pic18f4620 slower for other functions. 35 .1.3: LCD Interfacing with PIC18F4620 The MCC18 functions are designed to allow the control of a Hitachi HD44780 LCD controller using I/O pins from a PIC18 microcontroller.3. Thus we used the 8 bit mode. We used the LCD to display the IP address of the microcontroller and the current sensor value.

while(1) { while( ! PORTAbits.1.4: Serial Interfacing with PIC18F4620 The PIC18F4620 has 2 serial ports modules the USART (Universal synchronous and asynchronous receiver and transmitter) and the MSSP (master synchronous serial port) module.RA0 ). } 36 . 25 ).h> void main(void) { // configure USART OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH.h> #include <usart.4 RS-232 interfacing Fig3. // value } CloseUSART(). We used the USART module for interfacing with the RS232 port of the computer. //write value of PORTD if(PORTD == 0x80) // check for termination break. The computer is used only for debugging purposes and is not totally necessary for operation of the weather box. #include <p18f4620. //wait for RA0 high WriteUSART( PORTD ).3.

5 Ethernet chip interfacing Fig3. with data rates of up to 10Mb/s.3. 37 .5: Interfacing ethernet chip Communication with the host controller is implemented via two interrupt pins and the SPI. Two dedicated pins are used for LED link and network activity indication.1. The following pins are also used: SCK = Serial Clock SI SO = Serial In = Serial Out INT = Interrupt (general) WOL = Interrupt (Wake On LAN) The INT and WOL pins are used to interrupt the microcontroller from the ethernet chip. The INT pin of the ethernet chip is conencted to the INT0 of PIC18F4620 and the WOL pin is connected to the INT1 pin of PIC18F4620.

6: Schematic Diagram of PIC Interfacing (Designed using Proteus v. 38 .3V CMOS level. 3.We performed level conversion because the microcontroller operates at 5V TTL level while the ethernet chip operates at 3.7. The green LED signifies that a network conenction is available and the red led indicates that the network is ready to accept and transmit messages and packets. The level conversion was done using 74HCT08 (quad AND gate). The sensor is connected to the ANO and AN1 pins. The LCD and the computer connected through the RS 232 is not needed for the operation of the device.1.6 Complete Circuit Design Fig3. The ethernet chip is connected to the ethernet cable by a RJ45 with magnetics included and a ferrite bead to reduce high frequency EM interference.1) The 2 LEDs are added in the ENC28J60 for debugging purposes.

2 SOFTWARE DESIGN IMPLEMENTATION 3. It is important to note that Stack Manager is not an integral part of our TCP/IP Stack. it polls the MAC layer for valid data packets. This module is implemented by the source file “StackTsk. In order to relieve the main application from the burden of managing the individual modules. 39 . the main application must call the StackTask( ) function periodically. when given processing time. It is written so that the main application does not have to manage stack modules. to ensure that all incoming packets are handled on time. it decodes it and routes it to the appropriate module for further processing.2.1 TCP/IP Implementation Our stack is a collection of different modules. our TCP/IP Stack uses a special application layer module known as “StackTask”. LCD. it must be initialized by calling the StackInit( ) function. regardless of main application logic. in addition to its own work such as RS-232. This task of managing stack modules remains the same. or the Stack Manager. Once StackInit( ) is called. Some modules (such as IP. and Sensor interfacing.3. UDP and ICMP) must be called when a corresponding packet is received. along with any time-out and error condition handling. This function initializes the Stack Manager variables and individual modules in the correct order. Any application utilizing our stack must perform certain steps to ensure that modules are called at the appropriate times. When one is received. Before the Stack Manager task can be put to work. StackTask is implemented as a cooperative task. TCP.c”.

ARP. If a data packet received then Get data packet protocol type If packet type is IP then Fetch IP header of packet Get IP packet type If IP packet type is ICMP then Call ICMP module Else if IP packet type is TCP then Call TCP module Else if IP packet type is UDP then Call UDP module Else Handle not supported protocol End If End If Else if packet type is ARP then Call ARP module End If Thus the protocols supported by our project are MAC. The FTP.The exact steps used by StackTask are shown in the algorithm below. IP. DHCP and other protocols such as SLIP are not supported. and HTTP. UDP. TCP. 40 . The absence of DHCP implementation in our project causes the IP address of the microcontroller to be fixed and unable to be changed by the network server. ICMP.

Then the SM enters in the MAC module.For example the stack manager operations concerning the ICMP packets transmission and reception is shown and described below. Again frame type is checked. then SM is changed to ICMP (say). Then the frame type is checked if that of ARP or IP.7: Flow chart of TCP/IP Implementation (For ICMP only) First of all SM is set to idle. If IP then status is changed to ICMP and SM enters into ICMP module. to handle the ICMP task. If SM=ICMP. then the SM enters ICMP module. If frame type is ICMP (say). 41 . The status of SM gets changed to either ARP or IP. SM=ARP SM=TCP SM= Stack Manager FT = Frame Type Fig 3.

2Web/Database Server Our module is an IP enabled device. Now if a public IP if provided to it. “status. For our demonstration purpose we assign IP of our module to be 192. There was code in that very same page which would read the CGI page.2. Firstly we read the whole contents of the file and stored it in a string. Also connecting these two via a lab link cable or the cross wire cable.168.X. where X is any value in between 1 to 255 but not equal to 5). 42 .11. retrieve the data.168.168.5 and the IP of the central web/database server was assigned to be 192. Also any hacker wanting to crash our system can generate large no of requests that our module cannot handle.11. The page “status. the readings were retrieved and stored in variables for further processing. But being an eight bit microcontroller it would not be able to serve thousands of possible requests from the public domain. it can definitely be accessed through the internet.2 (192. taking into consideration of the token we have kept.cgi” in our module was written in such a way that we have kept certain tokens that would help to extract the required readings from the total contents of file. The first problem of repeated query to our module at a constant interval was solved using the META tag in the PHP page which sends a request to our module. store it in a managed way. the essence of a Web/database server is inevitable. both connected to same router. Now for our demonstration purpose we called our page at an interval of one minute. The second problem of retrieving of data was done using the string operation. META tag was in such a way that it recursively called the page itself.11. In order to address this problem and to manage readings of different weather variables. with data transfer rate set to be 10Mbps in half duplex mode equally worked. Then using few string operations.cgi”.3. Now the challenging task was to send a request to our module at a constant interval. and show a graphical representation of data according to the request at the time of request. stored in our module.

‘date( )’. For that we use the built in function of PHP. So. Before storing we also need to consider the time at which the reading has been taken.Third problem was to store the retrieved value in a manageable way. at the place where our module is kept for monitoring. Last but not least we need to represent those data in the graphical format. At that very instant we would read the last 60 rows of data from the main table in order to calculate the average value of the readings of that particular hour and then store it in the new table where the minute field is not present as it was in the main table. which in turns leads to calculate the average reading of that day from the ‘hour’ table and store in the day table where field are only ‘year’. In the similar manner two more tables for month and year were also maintained. Here for each reading to be plotted we need to average 525600(=365*24*60) readings because we were taking readings at an interval of one minute. if we were to average the data at the fly time (request time). 43 . ‘month’ and ‘day’ including the weather variables. weather variables. We were storing the retrieved data. Let’s say a user requested to view the average temperature on a yearly basis in order to have an idea of impact of global warming. Here users can send requests to view the plot in an hourly basis or daily basis as well. in such a way that ‘year’. Usage of the function was to be done in proper consent. it would be definitely be an idiotic task. the value of hour to be 00 indicated the change of day. This finally led us to have proper data which is to be used to show the proper graph as requested by user in the public domain. The value of minute to be 00 indicates that the hour has been incremented by one. ‘day’. we were checking the values of the ‘date’ parameters. And along with the weather readings. ‘hour’ and ‘minute’ were also the field of table. Similarly. these were also stored in the table. The main challenging task was to represent the data as according to the user request. Now in order to address this problem what we did was we created five tables. The sample of user interface and the graph plotted using random data for temperature is as shown in the ‘fig e’ and ‘fig f’ respectively. For the purpose of plotting of graph we use gd_2 library of PHP. When the data was being written in the main table. For that as mentioned we use MySQL database. From this function we extracted all these fields and stored it in different variables. ‘month’.

CHAPTER 4 EPILOGUE 44 .

1 PROJECT TIMELINE The project passed through all the phases: Research. Design (Simulation and Hardware).25 8.75 4.etc.buffers.25 6.47 10 38. TOTAL MODULE COST 6 Wi-Fi transreceiver From ICIMOD 1 7 PV panels From CES.2 PROJECT COST ANALYSIS s/n 1 2 3 4 5 6 Hardware requirements Sensors a.1: Financial Details of Hardware Requirements for single module (1$=63 NRS) 45 .00 7.50 0.22 ENC28J60 J1006FOIT PIC18F4620 HD7740 family Resistors. Temperature Sensor b.50 0.47 Total $ 1. The Gantt chart of our project is shown below.75 4.1: Gantt chart: “IP Based Weather Station: Mausam Parisuchak” 2007-2008 4.25 6.00 7. OCT Events / Time Research & Analysis Sponsorship Material Order Simulation 7Design Hardware Design Testing & Maintenance Documentation (115) OCT (1530) NOV (115) NOV (1530) DEC (115) DEC (1530) JAN (115) JAN (1530) FEB (115) Fig4. LDR Ethernet Controller RJ45 JACK Microcontroller LCD Miscellaneous Specifications LM35 Quantity 1 1 1 1 1 1 Rate $ 1.1 4.IOE 1 Table 4.25 8. Testing and Maintenance and Documentation. Analysis.

Thus the total weather module cost is approximately 2.NRs.400 /. 46 .

4. This is what incorporated in our project. In the industrial plants as well.4 APPLICATIONS OF THE PROJECT With the advancement of today’s technology only logging of data is not sufficient. With the addition of many weather sensors. it can give the data of various parameters. Solar Panel can be added on our module so that it can behave as independent unit and can be mounted in the remote area without any external power supply. But the availability of data in the usable form for the real time application is most important. In botanical studies for example in the green house the regular monitoring of data is an important and tidious task and with aid of our project this can be done quite easily and efficiently. Where sensing and recording of data are done automatically and also that the data are tabulated properly in modern database system () which further enhances the usability of data recorded. our project can be used to monitor different physical parameters which in turns help to analyse the performance to different 47 . With the feature of real time avialability our aim is to provide the unmanned weather station.3 FUTURE ENHANCEMENTS This project is flexible and efficient for the proper remote monitoring of the remote area. Temperature and humidity monitoring in airport is also an important and critical task where too our project can be utilized. 4. It also provides references for futher experiments as data are kept in the managed way in the modern databse. and thus can be implemented as Advanced Remote Data Logger.

is even more difficult. then to construct a paved road. Next step in our project was to select the adequate hardware. Since PIC18F series was unfamiliar to our friends and seniors as well. Also the cost of attaining each component was far too behind our budget as we need to get more than one complete set of components. This was the problem we faced when we chose to implement a web server in a microcontroller. Time was another important factor. Small variations of weather parameters for small period can contain vital information thus implementing our project help to address those types of cases as well. And also that we cannot complain the manufacturer if we received any damaged piece.sophisticated machines and also predefined premitive measures can be carried out to prevent disasters. Some major components of our project were not avialable in the local market so we needed to get them from the manufacturers abroad. For the solution of this problem we decided to search for the places where our project could be implemented and that we could get mutual benifits. We also need to work hard on getting appropriate programmers. but if there is no road. Knowing different weather parameters of climate of Snowy Mountain is an essential factor for development of mountain tourism in the country like Nepal.5 PROBLEMS FACED Where there is a gravel road. it is easy to be paved. 4. because in course of our working process the probability of getting components damaged cannot be ignored. We need to order components by keeping adequate time margin that we have enough time for succesful completion of our project. For days we searched in the library for a similar project being undertaken by our seniors but could not get a single one. Here we receive the nightmare of problems. With dedicated hard work and 48 . ICIMOD was the organisation toward whom we should be grateful for reliefing us from entangling in such a mess by providing us supports and encouragements.

3V to 5V logic shifter. we also need to consider high frequency design as well. we have to take care of voltage level conversion in our design which is taken care by using AND gate as 3. For this we used ferrite bead. On the course of hardware design we faced various problems.3 V and PIC18F4620 at 5V. For days we get frustrated as our task use to be done on the simulation but not on the hardware. But eventually we got one. On successful completion of the design on Proteus Simulation we implemented the design in the hardware. decoupling capacitors. 49 . Since our Ethernet chip worked at 3.searching procedures we were able to accumulate a couple programmer circuits schematics but could not get a working one on our table. But to get the relevent and reliable simulation software which provide the facility of simulating our components and that to free was really a tough job. twisted pair cable. proper alignement of active and passive components etc. The code for microcontroller was to be written using C language. But newer release of proteus solved our problem. Directly testing our codes on the hardware module could result in the devastating effects.Thus we can say gradual debugging and reconnenting components taking in account of knowledge gain in the course of instrumentation II really become a fruitfull. Since we need to work at higher frequency 20 MHz. Though simulation helps in providing a dirction to a project but never is an exact relica of overall project. But the working environment of MPLAB was quite different and we do need to work hard to get familiarize with. So we need to have proper simulation software for that purpose.

Finally the support of ICIMOD is also highly appreciated. It provides real time data of weather in remote/inaccessible locations through a wireless /wired connection. We would also like to thank the teachers and our supervisors for providing us the needed support. It includes the 3 concepts: embedded systems.6 CONCLUSION The project entitled “IP based weather station: MAUSAM PARISUCHAK” undertaken by us consists of 3 major portions: the sensors. We would like to thank all those who have supported us. The module built in our project acts as a web server and displays the sensor data in the form of web pages. and a weather station. TCP/IP communication. 50 .4. This module finds its practical implementation in the remote mountainous area of Nepal which can provide data through the internet either by a series of microwave links or satellite links. and the Ethernet chip which is used to connect to a LAN. the microcontroller.

Microprocessors and Interfacing by Douglas V Hall and many more blogs 51 .labcenter.uk 3. www. TCP/IP lean.co. www.microchip.REFERENCES 1.Web servers for Embedded Systems by Jeremy Bentham 4.com 2.

ANNEX Fig a: Snapshot of Simulation on Proteus 52 .

Fig b: Snapshot of C Programming in MPLAB IDE 53 .

Fig c: Snapshot of the Project Work done in ProtoBoard 54 .

Fig d: Snapshot of the PIC Programmer built in ProtoBoard 55 .

Note: this graph is created from random data 56 .Fig e: Interface designed in PHP for the public domain users Fig f: Graph designed in PHP for public domain users as per request.

Fig g: Our module in PCB 57 .

Sign up to vote on this title
UsefulNot useful