group 4 report

61
i Abstract This report includes the first and second chapters of the final project report on Digital Communication and Computer Networking Embedded Systems designing. The first chapter consists of an introduction to the project. The basic review about the project and main steps which will be carried out to solve the problem is also embodied in it. Furthermore it describes the resources and required tentative budget. The second chapter of this report includes the progress of the project and the theoretical knowledge and the practical experiences we have achieved during the works. This chapter consists of the designing of the module with details step to step.

Upload: sameera-chaminga

Post on 08-Nov-2015

14 views

Category:

Documents


0 download

DESCRIPTION

Project report

TRANSCRIPT

  • i

    Abstract

    This report includes the first and second chapters of the final project report on Digital

    Communication and Computer Networking Embedded Systems designing.

    The first chapter consists of an introduction to the project. The basic review about the project and

    main steps which will be carried out to solve the problem is also embodied in it. Furthermore it

    describes the resources and required tentative budget.

    The second chapter of this report includes the progress of the project and the theoretical

    knowledge and the practical experiences we have achieved during the works. This chapter

    consists of the designing of the module with details step to step.

  • ii

    Preface

    Remote accessing for non pc devices is can be found very beneficial as it can be used to remote

    monitoring and remote controlling the device. But at the same time it can be found difficult as

    they havent any inbuilt structure which is supporting for networking capability. This would be

    rather straitened task for non pc devices which are not having RS 232 interfaces. But some non

    pc devices are coming with RS 232 interfaces which are used to controlling and modifying

    functions.

    This report points out the necessity of an external device which will functioning as a networking

    enable device on behalf of non pc devices and a brief analysis in designing of such a product and

    its feasibilities. The next chapter discusses about designing of an external module using sbc65ec

    microchip. It consists of necessary steps and commands.

  • iii

    Acknowledgements

    As an undergraduate, completing a final year project successfully will be a great pleasure. It will

    be a great opportunity to gather practical experience in industry.

    Therefore firstly our sincere gratitude must be goes to Dr.Jayasundare for guiding us as our

    supervisor and also for Mr.U.N.Weerapperuma as the core supervisor of our project in

    conducting us with his busy daily routine.

    Then our gratitude must be extended to Dr. K.Gunawickrama, final year project coordinator for

    offering this great opportunity in completing an undergraduate project.

    Also our sincere gratitude must be extended to Dr. P. D. C.Perera for valuable assistance in

    accomplishing our project goals.

    Also we would be fond of extend our praise for colleagues for their encouragement.

    Finally, all the mentioned & unmentioned people who contribute to complete my training

    successfully are sincerely appreciated and thanked.

  • iv

    Contents

    Preface ...................................................................................................................................... ii

    Acknowledgements .................................................................................................................. iii

    Contents ................................................................................................................................... iv

    Acronyms ................................................................................................................................. vi

    List of Tables ......................................................................................................................... viii

    List of Figures.......................................................................................................................... ix

    Chapter 01 .................................................................................................................................1

    Introduction .............................................................................................................................1

    1.1 Background of the problem ................................................................................................1

    1.2 Problem Statement .............................................................................................................3

    1.3 Objectives and scope .........................................................................................................3

    1.4 Research Methodology ......................................................................................................5

    1.5 Resources required and tentative budget ............................................................................6

    1.6 Time plan ..........................................................................................................................7

    Chapter 02 .................................................................................................................................8

    2.1 Selecting the chip and advantageous ..................................................................................8

    2.1.1 Features .......................................................................................................................8

    2.1.2 Main components of the module ..................................................................................9

    2.2 The steps of the project up to the first progress ................................................................ 12

    2.2.1 Testing the module .................................................................................................... 12

    2.2.2 Configure the web server step1 .................................................................................. 15

    2.3 Testing the program ......................................................................................................... 18

    2.4 Selecting a non-pc device................................................................................................. 18

    2.4.1 Universal Asynchronous Receiver/Transmitter (UART) ............................................ 20

    2.4.2 The components used for built the power meter ......................................................... 21

    2.4.3 Ratings ...................................................................................................................... 22

    2.4.4 Measuring the voltage of single phase power line ...................................................... 23

    2.5 Development of the database and web applications .......................................................... 25

  • v

    2.5.1 Mysql database .......................................................................................................... 26

    2.5.2 Php code in web client ............................................................................................... 27

    2.5.4 Web pages ................................................................................................................. 28

    2.6 Results ............................................................................................................................. 30

    Chapter 3 ................................................................................................................................. 34

    3.1 Conclusions ..................................................................................................................... 34

    3.1.1 Future Development .................................................................................................. 35

    References................................................................................................................................ 37

    Appendix A .............................................................................................................................. 38

    Part1: Developing firmware ................................................................................................... 38

    1.1 HTTPEXEC.C ............................................................................................................. 38

    1.2 HTTP.C ....................................................................................................................... 39

    1.3 CMD.C ........................................................................................................................ 40

    Part 2: C program code of power monitoring device .............................................................. 44

    Appendix B .............................................................................................................................. 46

    B.1 Serial data transmission [13]

    .............................................................................................. 46

    B.1.1 Asynchronous and Synchronous Communications .................................................... 46

    B.1.2 Bit Rate and Baud Rate ............................................................................................. 48

    B.1.3 Word Formats ........................................................................................................... 48

    B.1.4 Sending Bits ............................................................................................................. 48

    B.2 COM PORT configuration on PC .................................................................................... 50

  • vi

    Acronyms

    ASCII

    American Standard Code for Information Interchange

    HTML Hyper-Text Markup Language

    HTTP Hyper-Text Transfer Protocol

    IC Integrated Circuit

    ICSP In-Circuit Serial Programming

    IDE Integrated Development Environment

    IEEE Institute of Electrical and Electronics Engineers

    IP Internet Protocol

    ISO International Standards Organization

    MCC16 Microchip C compiler for 16 series PICs

    MCU Microcontroller Unit

    NIC Network Interface Controller

    OSI Open Systems Interconnect

    RFC Request for comments

    RM Reference Model

    RX Receive / Receiver

    SPI Serial Peripheral Interface

    TCP Transmission Control Protocol

    TX Transmit / Transmitter

    ESDNC Embedded serial data-network converter

  • vii

    LAN Local Area Network

    FTP File Transfer Protocol

    ICMP Internet Control Message Protocol

    TFTP Trivial File Transfer Protocol

    SMTP Simple Mail Transfer Protocol

    POP3 Post Office Protocol version 3

    API Application programming Interface

    ICSP In-Circuit Serial Programming

    IDE Integrated Development Environment

    ICD In-Circuit Debugging

    PIC Peripheral Interface Controllers

    RFC Request for comments

    TCP Transfer Control Protocol

    UDP User Datagram Protocol

    HTTP Hyper Text Transfer Protocol

    BMS Building Management System

  • viii

    List of Tables

    Table 1.1: Resources required and tentative budget ... 5

    Table 1.2: Time plan for the project..7

  • ix

    List of Figures Figure 1.1: Local area network of an industrial environment .......................................................2

    Figure 1.2: implementing the embedded system converter in the industrial LAN .........................3

    Figure 2.1: SBC65EC Module .....................................................................................................9

    Figure 2.2: The testing environment .......................................................................................... 12

    Figure 2.3: Setting up the parameters of the HyperTerminal of PC A ........................................ 13

    Figure 2.4: Sending characters from Hyperterminal ................................................................... 14

    Figure 2.5: Capturing the data packets from Wireshark ............................................................. 14

    Figure 2.6: Embedded system converter .................................................................................... 15

    Figure 2.7: The Network Bootloader ......................................................................................... 16

    Figure 2.8: The newly designed web page ................................................................................. 17

    Figure 2.9: Testing the program ................................................................................................ 18

    Figure 2.10: Circuit diagram of the power meter ....................................................................... 19

    Figure 2.11: Implemented power meter ..................................................................................... 22

    Figure 2.12: Block diagram of the voltage measuring process of the single phase power line .... 23

    Figure 2.13: Circuit diagram for the connectivity of the transformers ........................................ 24

    Figure 2.14: Power monitoring from remote computer .............................................................. 25

    Figure 2.15: Deploying database/web server ............................................................................. 26

    Figure 2.16: Mysql database ...................................................................................................... 26

    Figure 2.17: Home Page ............................................................................................................ 28

    Figure 2.18: Data displaying page ............................................................................................. 29

    Figure 2.19: Contact Page ......................................................................................................... 29

    Figure 2.20: Data received from the power meter ...................................................................... 30

    Figure 2.21: Real time power measured by the power meter ...................................................... 31

    Figure 2.22: Data capturing of Wireshark .................................................................................. 31

    Figure 2.24: Retrieved data from the Mysql database ................................................................ 33

    Figure 2.25: Monitoring the power consumption through the web ............................................. 33

    Figure 3.1: Power monitoring system of the Department of Electrical & Information

    Engineering ............................................................................................................................... 35

    Figure B.1: Synchronous transmission ...................................................................................... 47

    Figure B.2: Asynchronous transmission .................................................................................... 47

    Figure B.3: To determine when to send data and read received data, the transmitter and receiver

    each use a clock that is typically 16 times the bit rate ................................................................ 49

    Figure B.4: COM Port Properties .............................................................................................. 51

    Figure B.5: Set the COM1 Properties ........................................................................................ 52

  • 1

    Chapter 01

    Introduction

    Generally computers are independent units and they cannot exchange information with

    other computers near or far without having a special technique. But these computers have local

    interfaces such as USB or RS-232 to communicate with printers or other devices close at hand.

    Networking technology is a popular way, used in homes, offices and factories which

    allow sharing resources and information efficiently among interconnected PCs and devices.

    Without such a networking property exchanging information will become more complicated and

    time consuming. Now even network security became more significant providing confidentiality

    for transmitting data with networking techniques.

    Remote access is one of an advantage in networking computers. Remote access allows

    accessing to PCs, files from any Internet-connected computer in the world. Remote access can be

    developed in LANs (Local Area Network) and also through Internet. Developing such an

    application in system is more advantageous for remote monitoring and remote controlling. This

    project is developing an embedded system module (Ethernet data- Serial data converter) for

    remote monitoring purpose.

    1.1 Background of the problem

    Nowadays networking computers has become a necessity for exchanging data among a

    set of computers. Generally networking computers in a small area (ex: within an organization) is

    referred as a LAN. LANs can be connecting to the internet through a router as it has the ability to

    facilitate the routing capability for data. Within a LAN the data exchanging is done by using

    Ethernet technology. The terms such as Switches, CSMA/CD and half and full duplex are

    coming with Ethernet technology.

    Eventually the development in Ethernet technology has became a new milestone in

    industrial applications. That is by connecting industrial devices to a network people took the

    advantage in remote controlling and remote monitoring of the devices. By doing this labor cost

    can be reduced and the flexibility in controlling applications has increased. The LANs used

    within an industry is using industrial Ethernet technology and as the name implies it carries bit

  • 2

    different features rather than a common Ethernet application. Figure 1.1 shows the industrial

    Local area network of an industrial environment.

    Figure 1.1: Local area network of an industrial environment

    But the problem is many of devices used in factories (We call as non-pc devices) cannot

    be connected to a network directly because these devices do not have an installed TCP/IP stack

    on their memory and no RJ45 port (Ethernet port). Therefore obviously they cannot perform any

    of the function which will be supported for networking capability. But fortunately these kinds of

    devices have RS232 serial interfaces. These interfaces are build-in units and they are supposed to

    use for configuration purposes in the device. Technicians connect laptops or PCs to the device by

    using these interfaces and do the configurations or modifications to the device.

    But developments in technology have made it possible for embedded systems to

    communicate in networks as well as on the Internet. This kind of embedded system [3] has

    computer intelligence and is dedicated to performing a single task, or a group of related tasks. As

    an example embedded systems can be used for perform monitoring and control functions such as

    gathering and reporting sensor readings or controlling motors and switches. Then the information

    can be send through the network by getting necessary networking functions.

    These embedded system features and network capability can be used for remote

    accessing for non-pc devices. In this project this an embedded system converter between RS232

    interfaces and RJ45 interface is developed. This feature will upgrade the position of non-pc

    Power Meters

    (Non-pc devices)

    ? Ethernet

    interface

    Serial

    interface

    Power meter

    (Non-PC device)

    Firewall

    Server

    Router

    PC3 PC2 PC1

    Switch

  • 3

    devices. Then the non-pc devices can be connected to the Ethernet network through the

    embedded system converter. Then they can be monitored, controlled and modified by remote

    logging to the device. Non-pc devices such as power meters, generators, motors and factory

    modules can be used more effectively if they can be remote accessed. After developing the

    embedded system converter it will be implemented as shown in figure 1.2.

    Figure 1.2: implementing the embedded system converter in the industrial LAN

    1.2 Problem Statement

    Developing, networking capability in non-pc devices which can be found very beneficial.

    But implementing such an application can be found as difficult because they have not inbuilt

    structure. Also developing such an application in non-pc devices will be need high cost. It will

    change the basic structure of the device. Basically this kind of implementation cannot be done to

    existing devices.

    1.3 Objectives and scope

    The objective of this project is to develop a compact, integrated web enable solution for

    any non-pc devices with serial capability. Non-pc devices dont have the networking capability

    or installed TCP/IP stack in the devices. Therefore to enable the networking capability in a non-

    pc device there has to be a separate device.

    Power Meters

    (Non-pc devices)

    ? Ethernet

    interface

    Serial

    interface

    Embedded system converter

    Power meter

    (Non-PC device)

    Embedded System

    Converter

    Firewall

    Server

    Router

    PC3 PC2 PC1

    Switch

  • 4

    Thousands of existing devices that dont support Ethernet have an RS232 serial interface.

    This serial interface can be used to gather the output or the measurement reading of the device.

    As an example in a power meter, the power meter reading. These data are transmitted as bits in

    digital format. The purpose of creating this embedded Ethernet module (serial-to-Ethernet

    Bridge), is to communicate with devices having RS232 serial interface in an Ethernet network.

    This module connects to the non-pc devices serial interface and to an Ethernet network.

    Computers anywhere in the network can then exchange data with the device. After being

    configured, the module sends received serial data on the network in TCP segments and sends

    data received in TCP segments to the devices serial interface.

    With the embedded Ethernet module, it can be used with any electronic product for

    applications such as:

    Remote diagnostics and upgrades.

    Asset tracking and replenishment.

    Automation and control.

    Power management.

    Remote collaboration.

    Personalized content delivery.

    This system comprises of Ethernet Controller, Microcontroller and associated interfacing

    circuitry. By incorporating this device to a product, users can quickly and easily gain serial to

    Ethernet networking capability as a standard feature. Therefore equipment can be accessed and

    controlled over the Internet.

    The development of the embedded Ethernet module will contain the following:

    To study and research on the technology of embedded system design.

    To study and research about various microcontroller architectures.

    To study and research about the external EEPROM technology.

    To study and research about the TCP/IP stack.

    To study and research about security of network infrastructure including encryption

    methods.

  • 5

    To study about the commands, this can be sent to the target board via UDP messages or

    the HTTP GET.

    To learn programming using C language.

    To study on how to interface Ethernet Controllers.

    To research and study about the embedded design for power requirements.

    To design the database program for the user.

    To research on future developments in this area.

    All the processing of the system flow is done by the Microcontroller and the RS232 interface

    is used for receiving data from the user device. This system can be easily expanded and

    customized based on the users requirements.

    1.4 Research Methodology

    An embedded microchip is required by the project. Therefore a Modtronix sbc65ec

    microchip [1] is selected as it was the most suitable, efficient and affordable microchip that has

    been found. It is further explained in below paragraph why this microchip has been chosen. But

    the problem is this specified chip is not available in the local market. Therefore in order to

    achieve the target it has to be imported from abroad.

    This microcontroller is included 32 general purpose user programmable I/O ports and

    also this is included 12 users programmable, 10 bit Analog to Digital converters. Microcontroller

    can be used RJ45 connector with built in LEDs to indicate link and activity status. And also

    microcontroller can be used RS232 interface via 3 pin connector. The SER3S6FT serial port

    cable can be used to connect to the serial port of a target DTE device. Target device is sent bit

    values through RS232 serial port to module and then module is processed and converted bit

    values to IP packets using TCP/IP stack. Microcontroller is Full TCP state machine and also it is

    modular Design. Free Modtronix TCP/IP stack is recompiled in order to deliver the MAC, IP,

    ARP, ICMP, TCP, UDP, HTTP, FTP, DHCP, NetBIOS, and DNS. TCP and UDP are supported

    to socket. It is expected to program the micro controller with C language using the MPLAB

    IDE tool, and further it is expected to implement a web server for remote monitoring. Web

    application is totally developed with HTML.

  • 6

    Then Web Server is implemented a HTTP Web Server supporting CGI commands and it

    is capable of creating Dynamic Web Pages. This can be used to display port values, analog input

    values and other real time information on web pages. CGI commands are accepted via the HTTP

    GET command. These commands can for example be used for setting the state of port pins.[2]

    The firmware has to be written in C, and can be compiled with the Hi Tech or Microchip

    MPLAB C18 compilers. If there are errors exist in the program, then the program has to be

    debugged and compiled again. This process is continued until program is corrected. Then the

    module is to be simulated using PROTEUS simulating tool. After that the microcontroller is to

    be programmed in a using program development kit with WINPIC tool. Then module circuit is to

    be developed based on the successfulness of the previous steps. Then MySQL database is used to

    save past time information of microcontroller board. These stored data is used to make a decision

    and analysis the system.

    1.5 Resources required and tentative budget

    Item Required Quantity Price per

    item ($)

    Total price

    Microcontroller PIC18F6621 1 - -

    Ethernet Controller RTL8019AS 1 - -

    Serial port Cable 1 - -

    SBC65EC Module with Serial 1 76.18 76.18

    TCP/IP stack 1 - -

    PICkit2 Programmer 1 27 27

    PGM2KIT Adapter 1 16 16

    DC Power adapter (7-35v) 1 10 10

    Expansion boards 2 3 6

    CAT 5E Network cable 3 1.5 4.5

    4-port Switch 1 30 30

    Table 1.1: Resources required and tentative budget

  • 7

    1.6 Time plan

    Table 1.2: Time plan for the project

  • 8

    Chapter 02

    2.1 Selecting the chip and advantageous

    The SBC65EC is a cheap module compared to other modules in the market. And also it

    possesses interesting features which will be helpful for the project aspects. The SBC65EC is a

    single board computer with 10Mbs Ethernet and RS232 interface. It can be added to any

    10/100Mbs Ethernet network. It is assembled with a PIC18F6621 CPU and supplied with the

    Modtronix Free TCP/IP stack (a modified version of the free Microchip TCP/IP stack) written in

    C, that can be compiled with the Hi Tech or Microchip PIC18 C compilers. And the TCP/IP

    stack can be downloaded through modtronix product page. Typical applications include HTTP

    Web servers, Mail clients, Ethernet to RS232 interface converter, Ethernet to RS485 interface

    converters, Remote control via Web Server, Protocol Bridge applications - Ethernet to USART,

    CAN, I2C, SPI etc. The most interesting advantage of the module is it doesnt need any kind of

    programming tool to program the module. The module can be configured directly through a PC

    without using a special programming tool.[2]

    2.1.1 Features

    Module can be easily upgrade or expand it with any of the other MixroX products.

    Has 32 general purpose user programmable I/O, of which 12 can be configured as 10 bit

    Analog Inputs.

    Can be used as a daughter board to Ethernet enables any product.

    Diode protected 2.1mm power connector for standard DC transformer. Center is positive.

    64KBytes FLASH, 3840 Bytes SRAM and pluggable EEPROM. Default TCP/IP stack

    uses less than half the available memory, which leaved heaps of code space for custom

    code.

    Wide operating voltage range from 7-35V.

    Default operating frequency of 40MHz, software configurable low power mode that runs

    at 10MHz.

    RJ45 connector with two built in LEDs. Green LED is for link indication, yellow LED is

    for activity.

  • 9

    Assembled with 10BaseT Ethernet and RS232 interface with +- 15kV ESD protection.

    RS232 interface via 3 pin Molex type connector or Daughter Board connector.

    Has a 40 pin Daughter Board connector.

    Assembled with brand name, quality components.

    Has an ICSP (In Circuit Serial Programming) connector (ICPC1 type) - CPU can be

    programmed and debugged in circuit.

    Is designed to run with the freely available Modtronix TCP/IP stack that features:

    Includes MAC, IP, ARP, ICMP, TCP, UDP, HTTP, FTP, DHCP, IP Gleaning, MPFS

    Socket support for TCP and UDP

    Portable across PIC18 MCUs

    Out-of-box support for Microchip C18 and Hi-Tech PICC-18 compilers

    RTOS independent

    Full TCP state machine

    Modular Design

    2.1.2 Main components of the module

    Figure 2.1: SBC65EC Module

    Serial port

    Ethernet port

    (RJ45)

    PIC18F6621 CPU

    EEPROM

    RTL8019AS

    Ethernet Controller

    ISCP connector

    Power connector

    Analog and

    Digital I/O pins

    Analog and

    Digital I/O pins

  • 10

    RTL8019AS Ethernet Controller

    The RTL8019AS is a highly integrated Ethernet Controller which offers a simple

    solution to implement a Plug and Play NE2000 compatible adapter with full-duplex and power

    down features. The full-duplex function enables simultaneously transmission and reception on

    the twisted-pair link to a full-duplex Ethernet switching hub. This feature not only increases

    the channel bandwidth from 10 to 20 Mbps but also avoids the performance degrading

    problem due to the channel contention characteristics of the Ethernet CSMA/CD

    protocol.[4]

    PIC18F6621 CPU

    This is the central processing unit of the module with 64KB program memory and

    1024bytes internal data EEPROM.[2]

    External EEPROM

    The SBC65EC board has an 8 pin IC socket for mounting a serial EEPROM, like the

    24LC256 (32Kbytes) or 24LC512 (64 Kbytes) chips. Depending on the SBC65EC variant, an

    EEPROM might be fitted. The standard SBC65EC board is fitted with a 24LC256 EEPROM and

    the PIC programmed with the Modtronix TCP/IP stack (modified Microchip TCP/IP stack) that

    uses the external EEPROM for storing configuration data and web pages. The 24LC256 has

    32Kbytes of non volatile memory, which is large enough for several web pages, including some

    small pictures. If this is not large enough, a larger 24LC512 chip can be fitted that can hold twice

    as much data.[2]

    Power connector

    This is the connector point of external DC power to the main board. The operating

    voltage range is from 7 30V. In the project the operating voltage is kept in 12V.

    Ethernet (RJ45)

    The SBC65EC has a 10Mbs Ethernet port. The RJ45 connector meets IEEE 802.3

    standards and FCC mechanical requirements. The RJ45 connector has two built in LEDs, a green

    LED for link indication, and a yellow LED for activity.[2]

  • 11

    RS232

    The SBC65EC has a USART interface with +- 15kV ESD protection. The USART

    signals are available via a 3 pin Molex type connector or the Daughter Board connector. Four

    solder jumpers (SJ1 to SJ4) on the back of the board are used to configure if the USART signals

    are RS232 or TTL voltage levels see circuit diagram at end of document for details.

    At delivery solder jumpers SJ3 and SJ4 are made, which configures the USART signals

    for RS232 voltage levels. By making solder jumpers SJ1 and SJ2, and opening SJ3 and SJ4, the

    USART pins can be configured for TTL signal levels.[2]

    ISCP connector

    The SBC65EC has an ICSP (In Circuit Serial Programming) connector (ICPC1 type).

    This enables the PIC to be programmed and debugged in circuit.[2]

    Analog and Digital I/O pins

    The SBC65EC has 32 I/O pins available for general purpose user I/O. Each of these pins can

    be configured separately to be inputs or outputs. Digital inputs and outputs are 0 to 5V. Inputs

    are 3V tolerant, and outputs can be made 3V tolerant by adding a series resistor (assuming 3V

    input will have clamping diodes). The SBC65EC can be configured to have between 1 to 12

    analog inputs. Each channel has a 10 bit resolution. [2]

    An interesting feature of the module is the embedded server in the device. It can be used for

    remote login to the module as a web client. A remote user can log on to the web server and

    retrieve data from the module. If the industrial LAN is connected to the internet users from the

    internet can be also log on the module. Therefore the user has the power to adjust variables

    potentially from anywhere in the world.

    However, the main disadvantages of using an embedded system to host a web server, rather

    than a PC are the limited processing power and memory size. Nevertheless, with the rapid

    increase of silicon density and ongoing microprocessor / microcontroller technology, it is

    foreseeable that these problems can be overcome although there would be significant impact on

    the price of the overall product, when using a high specification system.

  • 12

    Since the microchip TCP/IP stack is written in C, a C compiler must be used to convert the

    program to machine code. Fortunately, there is a free student edition of the microchip C compiler

    for the 18 series of PIC (a.k.a. MCC18). The only differences to a C compiler for the PC are the

    additional library functions.

    Not all the functions usually available are present

    Some of the functions that are present have more limited functionality than their

    counterparts on PC C compilers

    Data-types must be handled correctly, especially when data-passing between functions,

    e.g. when comparing a string, two variables must be passed strcmp(str1,str2); and not

    strcmp(str1,teststring);

    2.2 The steps of the project up to the first progress

    2.2.1 Testing the module

    Figure 2.2: The testing environment

    The purpose of this test is verifying that the module is working properly and it converts

    the serial data into Ethernet data packets and vice versa. If the module is working properly, the

    data send by the PC A should be captured by Wireshark [5] in PC B. In the testing environment

    PC B and module will have been assigned to IP addresses in a same network.

    The PC A connected to the RS232 interface of the embedded system converter and it is

    running a HyperTerminal[6] program ( HyperTerminal is a program which can be used to

    connect to other computers, Telnet sites and host computers, using either a modem or Ethernet

    PC A

    Hyperterminal

    PC B

    Wireshark

    Embedded

    system

    converter

  • 13

    connection). The PC B connected to the Ethernet (RJ45) interface and it is running Wireshark

    (Wireshark is an open-source packet analyzer. It used for network troubleshooting, analysis,

    software and communications protocol development).

    In PC A,by setting up the Hyperterminal parameters as in figure 2.3 ,a connection

    between PC A and module can be established. Then character a send to the PC B by using

    hyperternminal (see figure 2.4). The wireshark program running in PC B captured the data

    packet which was send by PC A (see figure2.5). [7]

    Figure 2.3: Setting up the parameters of the HyperTerminal of PC A

  • 14

    Figure 2.4: Sending characters from Hyperterminal

    Figure 2.5: Capturing the data packets from Wireshark

  • 15

    By analyzing the Wireshark captured UDP packet (see blue line of figure 2.5) it is shown

    that the ASCII value of received data is 61. That is the ASCII value of character a. It means the

    module is working properly. After that the module is mounted on a Vero board and connects a

    female RS232 interface to the module as shown in figure 2.6.

    Figure 2.6: Embedded system converter

    2.2.2 Configure the web server step1

    The module has to be developed so that, it can extract the necessary details from the

    device and display them at the web server. By developing the web server outsiders will be able to

    log on to the web server for information. The module extracts serial data from the device through

    the serial interface, converts them to data packets and sends them via Ethernet interface to the

    network. This is done by three steps.

    1. Develop the program

    The configurations files are located in the firmware on the SBC65EC. The firmware

    consists many header files and three header files are developed so that, it meets our

    requirements. Those header file are HTTPEXEC.C, HTTP.C and CMD.C. The developed C

    codes are in Appendix A-Part1.

  • 16

    2. Update firmware on SBC65EC web server

    Update firmware on SBC65EC web server that is install program into PIC18F6621 micro

    controller can be done with the Modtronix Network Bootloader, no PIC programmer is required.

    To do this downloads the latest version of the firmware (V3.10) from

    www.modtronix.com/products/sbc65ec/firmware and Downlaod and install the Modtronix

    Network Bootloader (V1.06) from www.modtronix.com/soft/netloader/

    The boot loader is in-built software in the module. When the module is connected to a

    network, the firmware updates files can send to the module using the network loader in a PC.

    Through the network loader the developed program was send to the module using default web

    server as shown in figure 2.7. The target IP address is IP address of the SBC65EC web server.

    Web server automatically inserts the relevant programs to the proper memory locations. [8]

    Figure 2.7: The Network Bootloader

  • 17

    3. Web page designing

    After developing the web server, the default web pages are modified as necessary and a

    new web page is designed to display the necessary data. The source code for the default web

    pages contained on the Modtronix SBC65EC Web Server is located in the

    "../src/webpages/default" folder of the downloaded source code. The newly designed web page is

    shown in figure 2.8.

    Figure 2.8: The newly designed web page

    The Modtronix SBC65EC Web Server uses the FSEE File System to store Web pages in

    the external EEPROM. All files making up the web pages have to have the format 8.3 (file name

    no longer than 8 characters and extension no longer than 3 characters), and must be located in a

    single folder. Any file starting with the 'X' character will require the user to be logged in to view

    it, for example "XPAGE.HTM".

    Web files cannot be uploaded to the Modtronix SBC65EC Web Server individually. All

    files have to be compiled into a File System Image, and then this image is uploaded to the target.

    The Modtronix Network Bootloader application is used to create and upload this file to the target

    Ethernet board. The following method is used to upload the File System Image to the target

    board.[9]

  • 18

    Uploading the File System Image with a FTP client

    A FTP client is used to connect to the target board and upload the File System Image.

    The default user name is "admin" and the password is "pw". After connecting to the target board,

    simply upload the entire File System Image file. After doing this, the target will contain the new

    Web pages.

    2.3 Testing the program

    Figure 2.9: Testing the program

    The PC A connected to the RS232 interface of the module and setting up the parameters

    of the HyperTerminal of PC A for serial communication. (See Appendix B) The PC B connected

    to the Ethernet (RJ45) interface. Through PC B connect to the SBC65EC Web Server using the

    internet explorer and browse the newly created web page. Then the serial data can be sent to the

    module by typing some characters in the HyperTerminal of PC A and the newly created web

    page shows the characters sent from PC A. Here, the PC A is used as the serial device instead

    digital power meter.

    2.4 Selecting a non-pc device

    In order to illustrate the mechanism of the converter, a serial input is needed during the

    project. In the 1st progress a PC is used in order to supply a serial input to the converter. But

    during the 2nd

    progress a power meter is suggested to illustrate the serial input for the converter.

    The power meter is supposed to get from CEB. But Galle CEB hasnt any single phase power

    meters. Therefore we have decided to use an oscillator for supply serial input to the converter

    device. But present lab oscillators havent any proper serial output which compatible with our

    PC B

    PC A

    Embedded

    system

    converter

    Ethernet data Serial data

  • 19

    converter device. Finally we decided to develop a device which is supplying serial input for the

    converter.

    The device is act as a single phase power meter because it converts the analog input into

    serial data. The purpose of this converter is supply a serial data to the embedded system

    converter. The power is measured by using a voltage transformer and given to the power meter.

    A microcontroller should be used in the power meter programmed by Micro C. An Analog to

    Digital convertor is needed to convert the analog input to a digital format. Then the digital data is

    supposed to convert to the serial data format according to the MikroC commands. The circuit

    diagram is designed as shown in the figure 2.10.

    Figure 2.10: Circuit diagram of the power meter

    The PIC18F452 is used as the micro controller of the power meter. USART (Universal

    Synchronous Asynchronous Receiver Transmitter) is the implementation technology of the

    power monitoring device.

  • 20

    2.4.1 Universal Asynchronous Receiver/Transmitter (UART)

    The Universal Asynchronous Receiver/Transmitter (UART) controller [10][11] is the key

    component of the serial communications subsystem of a computer. The UART takes bytes of

    data and transmits the individual bits in a sequential fashion. At the destination, a second UART

    re-assembles the bits into complete bytes. Serial transmission is commonly used with modems

    and for non-networked communication between computers, terminals and other devices. There

    are two primary forms of serial transmission: Synchronous and Asynchronous. Depending on the

    modes that are supported by the hardware, the name of the communication sub-system will

    usually include a A if it supports Asynchronous communications, and a S if it supports

    Synchronous communications. Some common acronyms are:

    UART Universal Asynchronous Receiver/Transmitter

    USART Universal Synchronous-Asynchronous Receiver/Transmitter

    Synchronous serial transmission requires that the sender and receiver share a clock with one

    another or that the sender provide a strobe or other timing signal so that the receiver knows when

    to read the next bit of the data. In most forms of serial Synchronous communication, if there is

    no data available at a given instant to transmit, a fill character must be sent instead so that data is

    always being transmitted. Synchronous communication is usually more efficient because only

    data bits are transmitted between sender and receiver, and synchronous communication can be

    more costly if extra wiring and circuits are required to share a clock signal between the sender

    and receiver.

    Asynchronous transmission allows data to be transmitted without the sender having to

    send a clock signal to the receiver. Instead, the sender and receiver must agree on timing

    parameters in advance and special bits are added to each word which is used to synchronize the

    sending and receiving units. When a word is given to the UART for Asynchronous

    transmissions, a bit called the "Start Bit" is added to the beginning of each word that is to be

    transmitted. The Start Bit is used to alert the receiver that a word of data is about to be sent, and

    to force the clock in the receiver into synchronization with the clock in the transmitter.

  • 21

    The most common use of the USART in asynchronous mode is to communicate to a PC

    serial port using the RS-232 protocol. Please note that a driver is required to interface to RS-232

    voltage levels.

    The signals on the USART pins of the microcontroller use logic levels. This means that

    for a five volt supply, the signals will be close to five volts when they are high and close to

    ground when they are low. When communicating with other logic devices, these signals can be

    used directly. In many applications, particularly with asynchronous communications,

    transmission standards such as RS-232 and RS-485 require different voltage levels to be used.

    For example, RS-232 uses a voltage below minus five volts to represent a logic one and a voltage

    above five volts to represent a logic zero.

    The rate at which data is transmitted or received must be always be set using the baud

    rate generator unless the USART is being used in synchronous slave mode. As an example of a

    baud rate calculation, consider the case of a microcontroller operating at 4MHz that is required to

    communicate at 9600 baud with a serial port on a PC. The USART would then be used in

    asynchronous mode. [11]

    The PIC is programmed using a PIC programmer. The mikroC program codes of the

    power meter are in Appendix A-part2. ADCON1 is the analog to digital convertor register. The

    ADCON1 = 0x80 configures which pins should be used to convert the analog inputs to digital

    output. USART_Init(2400) command initialize the serial port. Within the while loop

    ADC_read(1) generate the digital value of the analog signal of the channel one. It is assigned to

    Volt_1 variable. After executing the algorithm, while loop returns the value of the variable

    power. Using Proteous software, the circuit was executed and Proteous PCB layout is taken.

    Then the circuit is implemented. (Figure2.11)

    2.4.2 The components used for built the power meter

    1) PIC18f452 micro controller

    2) MAX232

    3) 10uf capacitor 4

    4) 15uf capacitor 4

    5) 7805 voltage regulator

  • 22

    6) Push button

    7) Serial female jack

    8) Crystal oscillator

    9) LED

    10) Resistor 1k,330,100

    11) 2010 connector 2

    Figure 2.11: Implemented power meter

    2.4.3 Ratings

    Input power: 5V

    Baud rate: 2400

    Input Signals voltage range: 0-5V

    PIC18f452

    MAX232

    8MHz Crystal oscillator

    RS232 Interface

    Current transformer terminals

    (Signal Input)

    Power connector

  • 23

    2.4.4 Measuring the voltage of single phase power line

    Figure 2.12: Block diagram of the voltage measuring process of the single phase power line

    Usually the power line voltage range is 0-230V. But the input of the power meter should

    be 0-5V range. Therefore a voltage transformer [8]

    should be used to reduce the power range.

    When voltage in a circuit is too high to directly apply to measuring instruments, a voltage

    transformer produces a reduced voltage accurately proportional to the voltage in the circuit

    which can be conveniently connected to measuring and recording instruments. When the power

    line voltage is applied to the voltage transformer, it reduces 0-230V range to 0-5V range and

    input to the power meter. The current transformer is used to step down the line current. Input to

    output ratio of the current transformer is 4:1. Then the output of the power meter is serial data

    and it is input to computer through RS232 interface of the PC. The HyperTerminal is set up as

    Appendix B. The baud rate is set to 2400.

    The voltage transformer and current transformer are connected to the power line and

    power meter as figure 2.13. Two full bridge diode rectifiers are used to convert AC to DC. A

    load is connected to the power line and the power meter measures the power consumption of the

    load. To calculate the power Eq. (2.1) is used. The power factor is 0.8 lagging.

    = (2.1)

    Where P=Power (W)

    V= RMS Voltage (V)

    I= RMS Current (A)

    = Power Factor

    Voltage

    Transformer Power Line Power meter

    Computer

    0-230V 0-5V

    Serial Data

  • 24

    Current Transformer

    45.5

    17W

    Load

    D1D4D2

    D3

    D1D4D2

    D3

    CH1

    Power

    Meter

    CH217W

    55.5

    Figure 2.13: Circuit diagram for the connectivity of the transformers

    The power meter outs data periodically as serial data. Period is set to one second. The

    power meter is connected to the computer through RS232 interface. The data receiving to the

    computer can be seen by Mikro C terminal. The data format is string and size is one byte.

    Then the power meter is connected to the embedded system converter though the serial

    interface as the block diagram shown in figure 2.14. The serial data is received to the converter

    converts into UDP packet and sends them to remote database server via Ethernet interface using

    the LAN. Then user can remote log to the web server running on the same server with database

    and he/she can analyze real time data as well as previous data.

    Current Transformer (2.5V)

    230V

    6V

    Voltage

    Transformer

    (300mA)

    20:5

    Power Line

    (230V, 50Hz)

  • 25

    Figure 2.14: Power monitoring from remote computer

    2.5 Development of the database and web applications

    Deploying a database for store target devices past records is a good practice in

    monitoring aspects of the device.It is the final step of the project.

    The client server concept is used as the outputdata gathering statergy in this case.The

    remote machine with the database acts as a client to the web server within the converter module.

    When the embedded system converter attatched to the industrial application continuosly sends

    data to the client machine and client machine will store the data in the database for further

    examination.

    In addition another web server is running in the remote machine in retriving data from

    the database.Any user can log on to the remote web server for observe past records of the target

    industrial application.By logging in to the web server, users will be able to not only retrive past

    records but also obtain a brief idea about performance of the target device with respect to the

    time.

  • 26

    Figure 2.15: Deploying database/web server

    The database was developed by using mysql and web pages were developed by php,html.

    The php code in web client is included mysql queries to store data from the web server in the

    databse. The remote web server php code is included mysql queries to retive data from the

    databse and show them to the user.

    2.5.1 Mysql database

    Figure 2.16: Mysql database

    Power meter Serial data-

    Ethernet data

    Converter

    Remote machine/

    Database /web server

    Remote users

  • 27

    2.5.2 Php code in web client

    Php code in web server

  • 28

    2.5.4 Web pages

    There are three web pages are developed using Macromedia Dreamweaver Dreamweaver MX.

    They are:

    Home page

    Data displaying page

    Contact page

    Figure 2.17 shows the home page. It contents a selection list indicating which floor you want

    to monitor. Though there are four floors, only ground floor has been considered within the

    project scope.

    Figure 2.17: Home Page

    Second page is developed to display data relevant to the selected floor. It displays a real-

    time power consumption graph, current power and total power consumption of the previous

    month. Also it facilitates to select the date or time period which you want to check the power

    consumption. Figure 2.18 shows the second page.

  • 29

    Figure 2.18: Data displaying page

    As shown in figure 2.19 third page is the contact page. It shows the contact details

    regarding to the system. It contains the names, contact numbers and email addresses of the group

    members of the group 4.

    Figure 2.19: Contact Page

  • 30

    2.6 Results

    Electric iron is connected to the power line of the system and the power meter is directly

    connected to the computer. Using the Mikro C terminal the data can be seen as figure 2.20.

    Figure 2.20: Data received from the power meter

    Then the power meter disconnected from the computer and connected to the embedded system

    converter and converter is connected to the computers Ethernet port. By logging to the

    embedded system converter through the web browser, the real time data received to it from the

    power meter can be seen in the web page Group 4. The result is shown in the figure 2.21. The

    value shown in the webpage is the power consumed by the electric iron. Figure 2.20 shows that

    the received values have been changing. The reason is the behavior of the electric iron, which it

    always tries to keep its temperature at a constant value by changing power consumption.

  • 31

    Figure 2.21: Real time power measured by the power meter

    Then another load (a fan) is applied to the system. Wireshark tool is used to capture the data

    received to the database server machine from the converter. The data is received as 1byte UDP

    packets. Captured packet is shown in figure 2.22.

    Figure 2.22: Data capturing of Wireshark

    At the same time another capturing tool is used to capture the receiving UDP packets.

    The tool is SocketTest. The captured data are shown in the SocketTest terminal line by line. One

  • 32

    value send by the power meter is shown by eight lines. Therefore the value is 445.4771 W. (See

    figure 2.23)

    Figure 2.23: Data capturing of SocketTest

    The data are stored in the Mysql database in the central database server. Using the SQL

    query the data stored in the database can be seen as shown in the figure 2.24. The SQL query is

    Select * from outputdata;

    The database has been developed to store the received data in a table. The table consists

    of two columns, which are rcvd_time and value. The data in the database have been varied time

    to time. It because two loads are connected to the system and one load is a variable load. The

    variable load is electric iron. Before power on the loads the received values are zero. First the

    iron is powered on. The power consumption is 445.4771W. Then the fan is powered on without

    switching off the iron. Then the power consumption is 545.4771W. Power consumption of the

    iron is changed time to time to keep it constant temperature. Therefore, the total power

    consumption of both load are vary as shown in the figure 2.24.

  • 33

    Figure 2.24: Retrieved data from the Mysql database

    Remote computer is used to logon to the central database servers web server. All the

    values are displayed in the web page as shown in the figure 2.25.

    Figure 2.25: Monitoring the power consumption through the web

  • 34

    Chapter 3

    3.1 Conclusions

    Implemented embedded system converter has special added features with comparing the

    other such kind of serial to Ethernet converters in the market. The main features are

    User name & password authentication.

    The user who has administrative credential, can remotely logging to the embedded

    system web server and perform the configurations to the PIC18F6621 CPU.

    Data Speed of the serial interface :300 bps to 921,600 bps and Ethernet

    interface:10/100MB

    Low cost

    This project is only focused on remote power measuring and monitoring system using the

    implemented embedded system converter. The system can be easily install on the existing local

    area network an organization and the one who wants to monitor the energy consumption can

    remotely log to the central database server and can monitor real time power consumption as well

    as past data. It is very beneficial showing the real power consumption on a graph and total

    energy for a period of time on the same users screen especially for a production environment.

    As there is a database to store previous data user can simply gets the consumed power at any

    day, any week, any month and any defined period.

    Another advantage is, there is no such kind of embedded system converter in the local

    market and the one who is going to import has to pay high cost per one item and also has to spent

    money for shipping and other expenses. The converter has one serial port and one Ethernet port.

    Therefore you need to install a converter per serial device.

    The application of this embedded system converter is greatly broad. It can be used in

    power management system, electric power net automatic system, transmission and distribution of

    electric power control system, Internet/LAN long-distance visit, industry/factory's automatic

    system, building management system, Super markets, label printer and barcode reader system

    and medical equipment monitoring system with the new features.

  • 35

    3.1.1 Future Development

    As explain above the embedded system converter has broad applications. The project is

    used only one application. That is remote power measuring and monitoring system. But the

    usage of the embedded system converter can be extended by configuring the converter to support

    for label printers, medical equipments, barcode reader and various time of measuring equipments

    used by the industry.

    The remote power monitoring system implemented in the project can be further extended

    as a major portion of a building management system (BMS). A Building Management System is

    a computer-based control system installed in buildings that controls and monitors the buildings

    mechanical and electrical equipment such as power systems, ventilation, lighting, fire systems,

    and security systems. A BMS consists of software and hardware; the software program, usually

    configured in a hierarchical manner, can be proprietary, using such protocols as C-bus, Profibus,

    and so on. Vendors are also producing BMSs that integrate using Internet protocols and open

    standards such as DeviceNet, SOAP, XML, BACnet, LonWorks and Modbus.[14] Figure 3.1

    shows a power monitoring system for the whole labs in the Department of Electrical and

    Information Engineering, Faculty of Engineering, University of Galle.

    Figure 3.1: Power monitoring system of the Department of Electrical & Information Engineering

    LB5 LB6

    LB3

    LAB1 LB2

    LB4

    Heads PC Network Administrators PC

    Other Servers

    Database Server

    Router

    Switch1

    Department of Electrical & Information Engineering

    Power line

    Power line

    Power line

    Power line

    Power line

    Power line

    Power meter 5

    Power meter 3

    Power meter1

    Power meter 6

    Power meter 4

    Power meter 2

    Converter 5

    Converter 3

    Converter 1 Converter 2

    Converter 4

    Converter 6

    Internet

  • 36

    As figure 3.1 shows, the system can be extended to monitor whole labs in the Department

    of Electrical & Information Engineering from one computer. The department head as well can

    monitor the power consumed by each lab from his computer. The network administrator of the

    department is given the administrative credential to configuring and troubleshooting the system.

  • 37

    References

    [1] www.modtronix.com

    [2] http://www.digitale-elektronik.de/shopsystem/sbc65ecr3.pdf

    [3] Embedded Ethernet and Internet Complete, Designing and Programming Small Devices for

    Networking, Jan Axelson, Published by Lakeview Research LLC.

    [4] RTL8019AS Realtek Full-Duplex Ethernet Controller with Plug and Play Function

    (RealPNP), REALTEK SEMICONDUCTOR CORP.

    [5] http://www.wireshark.org/

    [6] http://technet.microsoft.com/en-us/library/bb457166.aspx

    [7] http://www-

    tss.cisco.com/eservice/compass/common/tasks/task_veri_Config_Hyperterminal.htm

    [8]http://www.modtronix.com/products/sbc65ec/websrvr65_v310/mainpage.php?mainpagehtml=

    page_webpages&mainpageName=

    [9]http://www.modtronix.com/products/sbc65ec/websrvr65_v310/mainpage.php?mainpagehtml=

    page_update_webpages&mainpageName=

    [10] http://www.freebsd.org/doc/en/articles/serial-uart/index.html

    [11] http://ww1.microchip.com/downloads/en/DeviceDoc/usart.pdf

    [12] http://en.wikipedia.org/wiki/Transformer

    [13] Serial Port Complete: COM Ports, USB Virtual COM Ports, and Ports for Embedded

    Systems, Second Edition, Jan Axelson, Lakeview Research LLC, Madison, WI 53704.

    [14] http://en.wikipedia.org/wiki/Building_management_system September 8, 2011.

  • 38

    Appendix A

    Part1: Developing firmware

    1.1 HTTPEXEC.C

    #define THIS_IS_HTTPEXEC_MODULE

    #include

    #include "projdefs.h"

    #include "httpexec.h"

    #include "cmd.h"

    #include "debug.h"

    #include "appcfg.h"

    #include "net\stacktsk.h"

    #include "net\http.h"

    #include "net\delay.h"

    #include "net\helpers.h"

    #include "net\security.h" //Security related code

    WORD HTTPGetVar(HTTP_INFO* httpInfo, BYTE* val)

    {

    GETTAG_INFO getTagInfo;

    getTagInfo.tagVal = httpInfo->var.get.tagVal; //Value of

    requested tag

    getTagInfo.tagGroup = httpInfo->var.get.tagGroup; //Group of

    requested tag

    getTagInfo.ref = httpInfo->var.get.varRef; //Current

    callback reference with respect to 'var' variable.

    getTagInfo.val = val;

    //In case requested var not found, set it to NULL character and

    return HTTP_END_OF_VAR

    *val = '\0';

    //Get the current user logged in for this HTTP connection

    getTagInfo.user = HTTPGetCurrentUser(httpInfo);

    cmdGetTag(&getTagInfo);

    return getTagInfo.ref;

  • 39

    }

    #endif

    1.2 HTTP.C

    #define THIS_IS_HTTP_SERVER

    #include

    #include "projdefs.h"

    #include "net\checkcfg.h"

    #include "net\http.h"

    #include "net\fsee.h"

    #include "net\tcp.h"

    #include "cmd.h"

    #include "debug.h"

    #if defined(STACK_USE_HTTP_SERVER)

    void HTTPServer(void)

    {

    BYTE conn;

    //If no activity for 2 minutes, log out

    //if (TickGetDiff16bit(lastActivity) >= ((TICK16)TICKS_PER_SECOND *

    (TICK16)120) ) {

    //Future code might implement an auto logout method again

    //}

    //Process each connection

    for ( conn = 0; conn < MAX_HTTP_CONNECTIONS; conn++ ) {

    HTTPProcess(conn);

    }

    }

    static void HTTPProcess(HTTP_HANDLE h)

    {

    BYTE rqstRes[HTTP_MAX_RESOURCE_NAME_LEN + 1];

    HTTP_COMMAND httpCommand;

    BOOL lbContinue;

    BYTE i; //Temp variable

    HTTP_INFO* ph;

  • 40

    ROM char* romString;

    WORD rxBufPos;

    union

    {

    struct

    {

    unsigned char bHasParameters : 1;

    unsigned char bTemp : 1;

    } bits;

    BYTE val;

    } flags;

    ph = &HCB[h];

    lbContinue = TRUE;

    while( lbContinue )

    {

    lbContinue = FALSE;

    flags.val = 0;

    .

    1.3 CMD.C

    #define THIS_IS_CMD_MODULE

    #include

    #include "projdefs.h"

    #include "cmd.h"

    #include "debug.h"

    #include "appcfg.h"

    #include "lcd2s.h"

    #include "ior5e.h"

    #include "mxd2r.h"

    #include "busser1.h"// edit..............................

    #include "net\stacktsk.h"

    #include "net\udp.h"

    #include "net\helpers.h"

    #include "net\security.h" //Security related code

  • 41

    /////////////////////////////////////////////////

    //General purpose and Port pin variables - they are:

    // - 'a' Used for port a value. a0x will display 1 or 0, a1x will

    display on or off

    // - 'b' Used for port b value.

    // - 'c' Used for port c value.

    // - 'd' Reserved for port d value.

    // - 'e' Reserved for port e value.

    // - 'f' Used for port f value.

    // - 'g' Used for port g value.

    // - 'h' Reserved for port h value.

    // - 'i' Reserved for future use

    // - 'j' Reserved for port h value.

    if ((tagGroup >= VARGROUP_PORTA) && (tagGroup

  • 42

    p = (BYTE *)(&TRISA) + tmp;

    //Requested pin is an output - use LATCH register

    if ( (*p & mask) == 0 )

    {

    p = (BYTE *)(&LATA) + tmp; //Get pointer to LATCH register

    flags |= FLAGS_OUTPUT_PIN;

    }

    //Requested pin is an input - use PORT register

    else

    {

    p = (BYTE *)(&PORTA) + tmp;

    }

    tmp = tagVal & 0xf0;

    //Return "0" or "1"

    if (tmp == 0x00)

    {

    //Set val to '0' or '1' depending on state of pin

    *pGetTagInfo->val = ((*p & mask) == 0) ? '0' : '1';

    pGetTagInfo->ref = HTTP_END_OF_VAR;

    return 1; //One byte was written

    }

    //Return "on" or "off"

    else if (tmp == 0x10)

    {

    pGetTagInfo->ref = cmdGetROMStringVar(ref, pGetTagInfo-

    >val,

    ((*p & mask) == 0) ? HTMLSTR_OFF : HTMLSTR_ON);

    return 1; //One byte was written

    }

    //Return "" depending on if port is configured as

    input or output

    else if ( ((tmp == 0x20) && ((flags & FLAGS_OUTPUT_PIN) == 0))

    ||

    ((tmp == 0x30) && ((flags & FLAGS_OUTPUT_PIN) != 0))

    )

    {

    pGetTagInfo->ref = cmdGetROMStringVar(ref, pGetTagInfo-

    >val,

    ((tagVal & 0x08) == 0) ? HTMLSTR_CMNT_START :

    HTMLSTR_CMNT_END);

    return 1; //One byte was written

  • 43

    }

    //Return "checked" if port configured as output or input

    else if (tmp == 0x40)

    {

    if (tagVal & 0x08) {

    //Return "checked" if port configured as input

    if ( (flags & FLAGS_OUTPUT_PIN) == 0 ) {

    pGetTagInfo->ref = cmdGetROMStringVar(ref,

    pGetTagInfo->val, HTMLSTR_CHECKED);

    return 1; //One byte was written

    }

    }

    else {

    //Return "checked" if port configured as output

    if ( (flags & FLAGS_OUTPUT_PIN) != 0 ) {

    pGetTagInfo->ref = cmdGetROMStringVar(ref,

    pGetTagInfo->val, HTMLSTR_CHECKED);

    return 1; //One byte was written

    }

    }

    }

    //Return "1" if port configured as input, else 0

    else if (tmp == 0x50)

    {

    //Set val to '0' or '1' depending on pin direction

    *pGetTagInfo->val = (flags & FLAGS_OUTPUT_PIN) ? '0' : '1';

    pGetTagInfo->ref = HTTP_END_OF_VAR;

    return 1; //One byte was written

    }

    }

    //custom code apply here, serial input

    else if (tagGroup == 'T')

    {

    BYTE v;

    if (tagVal == 1){

    if (ref == HTTP_START_OF_VAR)

    {

    v = serGetByte();

    }

    if (v==198)

    v='*';

    }

  • 44

    pGetTagInfo->ref = cmdGetStringVar(ref, pGetTagInfo->val,

    &v);

    return 1; //One byte was written

    }

    Part 2: C program code of power monitoring device

    int j;

    float

    z_max,r_max,v_max,i_max,v_sub,i_real,v_rms,i_rms,power,i_final,k,r_ac,z_ac,k1

    ;

    char txt[8];

    void main()

    {

    unsigned int x=0,p=0,y=0,q=0,r=0,z=0;

    ADCON1 = 0x80; // Configure analog inputs and Vref

    TRISA = 0xFF; // PORTA is input

    TRISC = 0xBF; // RC6 output

    Usart_Init(2400);

    while(1)

    {

    int a;

    for(j=0;jz)

    {

    z=x;

    }

    else

    {

    z=z;

    }

    if(y>z)

    {

    z=y;

    }

    else

    {

    z=z;

    }

    z_max=(z*5.0)/1024;

  • 45

    if(zr)

    {

    r=p;

    }

    else

    {

    r=r;

    }

    if(q>r)

    {

    r=q;

    }

    else

    {

    r=r;

    }

    }

    r_max= (r*5.0)/1024.0;

    if(r

  • 46

    }

    Appendix B

    B.1 Serial data transmission [13]

    A serial port is a computer interface that transmits data one bit at a time. Most serial ports

    are bidirectional. It means they can both send and receive data. Transmitting one bit at a time

    might seem inefficient but has advantages, including the ability to use inexpensive cables and

    small connectors. Communicating via serial ports requires three things. Those are computers

    with serial ports, a cable or wireless interface that provides a physical link between the ports, and

    programming to manage the communications.

    Devices with asynchronous serial ports typically contain a hardware component called a

    Universal Asynchronous Transmitter/Receiver (UART). The UART converts between parallel

    and serial data and handles other low-level details of serial communications.

    Often in Embedded systems, serial ports with microcontrollers are used to communicate with

    other embedded systems and PCs. These microcontrollers, which contain CPU and I/O hardware

    such as UARTs. Microcontroller chips can be classified by data-bus width: 8-bit chips have an 8-

    bit data path and are popular in monitoring and control applications.

    A serial port output that functions as a transmitter or driver sends bits one at a time to a serial-

    port input that functions as a receiver, typically on a different computer. The cable between the

    computers typically has a dedicated data path for each direction. Some serial interfaces have a

    single, shared data path for both directions, with the transmitters taking turns.

    B.1.1 Asynchronous and Synchronous Communications

    In a synchronous protocol the interface includes a clock line typically controlled by one

    of the computers and all transmitted bits synchronize to that clock. Each transmitted bit is valid

    at a defined time after a clocks rising or falling edge depending on the protocol.

  • 47

    Figure B.1: Synchronous transmission

    In an asynchronous serial port the interface doesnt include a clock line. Instead, each

    computer provides its own clock to use as a timing reference. The computers must agree on a

    clock frequency and the actual frequencies at each computer must match within a few percent. A

    transmitted Start bit synchronizes the transmitters and receivers clocks.

    Figure B.2: Asynchronous transmission

  • 48

    Therefore basically Synchronous transmission needs a clock line from a centralized

    computer, while asynchronous transmissions require each computer to have its own clock.

    B.1.2 Bit Rate and Baud Rate

    The bit rate is the number of bits per second transmitted or received per unit of time,

    usually expressed as bits per second (bps). Baud rate is the number of possible events, or data

    transitions, per second. The number of characters transmitted per second equals the bit rate

    divided by the number of bits in a word. With 8-N-1 format, a byte of data transmits at 1/10 the

    bit rate because each word contains 10 bits: 1 Start bit, 8 data bits, and 1 Stop bit. So a 9600-bps

    link using 8-N-1 format can transmit 960 data bytes per second.

    To gain access to a port, an application selects a bit rate and other port parameters and

    requests to open, or gain access to, the desired port. To send a byte, the application writes the

    byte to the transmit buffer of the selected port. The UART then sends the data, bit by bit in the

    requested format, adding Stop, Start, and parity bits as needed. In a similar way, the UART

    stores received bytes in a buffer. After receiving a byte, the UART can generate an interrupt to

    notify an application of received data, or software can poll the port to find out if data has arrived.

    B.1.3 Word Formats

    A UART transmits data in chunks often called words. Each word contains a Start bit, data

    bits, an optional parity bit, and one or more Stop bits. The parity bit can provide a basic form of

    error detecting. Most UARTs support multiple word formats. A common format is 8-N-1, where

    the transmitter sends each word as one Start bit, followed by eight data bits and one Stop bit. The

    data bits transmit beginning with bit 0 (the least significant bit, or LSb).

    B.1.4 Sending Bits

    Figure B.2 shows how a byte transmits in 8-N-1 format. When idle, the transmitters

    output is logic 1. To indicate the beginning of a transmission, the transmitter sends logic 0 for

    one bit width. This is the Start bit. After the Start bit, the transmitter sends the 8 data bits in

    sequence, beginning with the LSb. The transmitter then sends a logic 1, which functions as the

    Stop bit. Immediately following the Stop bit or at any time after, the transmitter can send a new

    Start bit to signify the beginning of a new transmitted word.

  • 49

    At the receiving computer, the transition from logic 1 to the Start bits logic 0 indicates

    that a new word is arriving. The transition and the bit rate determine the timing for detecting the

    bits that follow. The receiver attempts to read the logic state of each bit near the middle of the

    bits time period. Reading in the middle of the period helps ensure that the receiver detects the

    bit values correctly even if the transmitting and receiving clocks dont exactly match in

    frequency or phase.

    A UART typically uses a receive clock with a frequency 16 times faster than the highest

    supported bit rate. If the highest bit rate is 9600 bps, the receive clock should be at least 153,600

    bps. As Figure 3 shows, after detecting the transition that signals a Start bit, the UART waits 16

    clock cycles for the Start bit to end, then waits 8 more cycles to read bit zero in the middle of the

    bit. The UART then reads each bit that follows 16 clock cycles after the previous bit. If the

    transmitting and receiving clocks dont match exactly, the receiver will read each new bit closer

    and closer to an edge of the bit. To read all of the bits in a 10-bit word correctly, transmit and

    receive clocks should vary no more than about three percent. With greater variation, by the time

    the receiver tries to read the final bits, the timing may be off by so much that the receiver will

    read the wrong bits and might not detect the Stop bit. The clocks need to stay

    in sync only for the length of a word because each word begins with a new Start bit that

    resynchronizes the clocks.

    Figure B.3: To determine when to send data and read received data, the transmitter and receiver each use

    a clock that is typically 16 times the bit rate

  • 50

    The clocks need to stay in sync only for the length of a word because each word begins with a

    new Start bit that resynchronizes the clocks. Because of the need for accurate timing,

    asynchronous interfaces require stable timing references such as crystal oscillators.

    B.2 COM PORT configuration on PC

    In PCs, applications access most serial ports as COM ports. Other names for COM ports

    are communications port and Com port. For each COM port, an operating-system driver assigns

    a symbolic link name such as COM1, COM2, and so on, which applications use to detect and

    access the port.

    The Windows Device Manager shows information about each COM port. To access the

    Device Manager, right click on My Computer, click Manage, and in the Computer Management

    pane, select Device Manager. Or click Start and select Settings > Control Panel > System >

    Hardware > Device Manager. Or save some clicks by creating a shortcut to the file

    devmgmt.msc in Windows\System32.

    To view a COM port in the Device Manager, click Ports (COM & LPT), right-click a

    COM port, and select Properties. The Properties window has several tabs that display the ports

    property pages. A vendor-provided co-installer can supply custom property pages for vendor-

    specific device properties. The pages shown below are typical. In order to establish a serial

    connection between two PCs, several parameters should be matched and have to be set prior to

    the connection opening etc bit rate. During the testing process, in order to open a serial

    connection between PC A and the module these parameters had been set according to the

    connection type.

    The Port Settings tab displays the default settings for the port. A USB/serial converter

    doesnt use the bit rate, parity, and Stop bits in communications between the PC and the

    converter, but a driver can send these values to a device that uses the settings on its serial port.

    For example, a USB/RS232 converter can set the parameters of its RS232 port to match values

    specified on the PC. The Advanced Settings window enables setting buffer properties and the

    COM-port number. Applications can change the parameters from the default values set in the

    Device Manager.

  • 51

    Figure B.4: COM Port Properties

    In order to establish a serial connection between two PCs, several parameters should be

    matched and have to be set prior to the connection opening etc bit rate. During the testing

    process, in order to open a serial connection between PC A and the module these parameters had

    been set according to the connection type.

  • 52

    Figure B.5: Set the COM1 Properties