Professional Documents
Culture Documents
Amr
Amr
Akram
Ramadan
Preface
Acknowledgements
First, we would like to thank our supervisor Dr. Gheith Abandah for his kindness and advice throughout the year. The kindly notes and tips from engineer Zyad Al-Khatib were very helpful; thus we give him our deepest gratitude. For Salam and Camelia who started the AMR last year, thank you. Ala, Majed and Faisal for your help, thanks a lot. For all the telephone calls and mobile messages from friends and colleagues, we send them AT+CMGS=Thanks. To Thamer, Lahham and Ali, thanks for the great 4.5 years. Without the encouragement, caring, patience, understanding, and prayers from our mothers, fathers, sisters, and brothers none of this would have come true; we love you all. Finally, to all who helped or just loved, thanks.
II
Abstract
Fixed-Network Automatic Meter Reading (AMR) is the latest advance in the telemetry field. It utilizes already available fixed communication networks (e.g., the cellular network) for exchanging data to minimize cost and human effort. The purpose of this project is to introduce a Fixed-Network AMR design that manages the reading of the electricity meters at the consumers' side. This design is intended to replace the exciting manual methods of gathering data. The approach to the solution for this problem is made with the use of the GSM network and a custom RF solution. Different hardware modules are introduced to help exchange data between a central office and any node in the system (i.e., customer's side). The achieved results of the project are encouraging. Various data was gathered and certain wireless processes were controlled. The GSM and RF communication media were fully utilized by introducing our own GSM and RF protocols. A computer software was developed to run the overall process. The results obtained stand as a proof of concept for the credibility of implementing such AMR system. They also show that even if the initial cost may be relatively high, it is considered cheaper on the long-run. Yet, the results still need further analysis and improvements to be made. Using other chips and advanced microcontrollers can help in gathering more data and control further processes.
III
Table of Contents
I IV 1
2 3 6 6 6 8 9 9
Ch 2: System Infrastructure
2.1 Microchip PIC18C452
2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 Interrupts I/O Ports Addressable USART Master Synchronous Serial Port (MSSP) Timer0 AT Commands M20 Interface SMS with the M20 FM-RTFQ1-433 FM-RTFQ1-433 Basic Operation Adapting the Input Signals Communicating with the ADE7756 Special Features Using the 93C56 EEPROM Adapting Data to and from the 93C56 Line Driver (MAX232) Voltage Regulator (LM317) Open Collector Buffer
10
11 12 13 13 15 16 18 18 19 19 21 21 22 23 23 24 24 25 27 27 28 29 29 29 29
2.2
2.3
RF Modules
2.3.1 2.3.2
2.4
Analog ADE7756
2.4.1 2.4.2 2.4.3 2.4.4
2.5
2.6
Supplementary Hardware
2.6.1 2.6.2 2.6.3
Ch 3: GSM Link
3.1 The PIC and the M20
3.1.1 3.1.2 Hardware Interface AT Command Interface Protocol Main Rules Invalidity Reports An Example
30
31 31 31 36 36 37 37
3.2
Ch 4: RF Link
4.1 Need Another USART Module
4.1.1 4.1.2 4.1.3 The Slave PIC The Master PIC and the Slave PIC How It Works Power Supply Input Data Level Transmitter's Phased Locked Loop (PLL) Hardware Interface How It Works
39
40 40 40 42 43 43 43 44 45 45 45 46
4.2
4.3
4.4
RF Link Protocol
47
48 48 49 50 54 55 55
5.2
Process Controlling
Ch 6: Central Office
6.1 6.2 6.3 What is a Central Office? System Overview System Walkthrough
6.3.1 6.3.2 6.3.3 6.3.4 Initializing the Software Sending Tasks Receiving Tasks Debugging and Troubleshooting
57
58 58 59 60 61 62 64
66
67 67 67 67 68 71
7.2 7.3
Ch 8: Conclusion
8.1 8.2 8.3 Work Done Problems Faced Further Suggestions
73
74 74 75
References Appendix A
A.1 A.2 A.3 NCN Schematic Diagram CCU Schematic Diagram ADE7756 Calibration Schematic Diagram
76 78
79 80 81
VI
Introduction
1.1
1.2
Why AMR?
Electrical energy meter reading has been always done manually by a staff of meter readers who used to visit every meter location periodically and enter the meter reading by hand. These readings were then added to previously read values or what can be called (the customer consumption registry), from which the cost of the consumed energy during the latest cycle (usually a month) can be calculated. This could be either a paper or computerized job. In some cases where consumption rationalization strategies are followed; the consumer is charged for the energy unit proportionally to his/her total consumption. It can be noticed that for this method of meter reading, the previous feature is the only luxury of such a limited system. In addition, many problems usually face the readers job like being unable to reach the meter location, the absence of the property owners at the visit time or simply the human error in recording the meter reading. Various methods were and are developed to overcome the old traditional method limitations, trying to make electricity metering in general and meter reading in particular more accurate, reliable and functional. The new meter-reading methods can be classified into the following categories [1]:
In-Site Meter Reading - Electronic Meter Reading (EMR) - Remote Meter Reading (RMR) Automatic Meter Reading (AMR) - Off-site Meter Reading (OMR) - Mobile AMR - Fixed-network AMR
Mobile AMR
The only human effort in meter reading is the drivers effort in this method. A specialpurpose vehicle is prepared with equipment that can communicate with the meters using relatively high antenna connected to a sensitive radio transceiver. The meter readings are gathered by the vehicle while driving the route only. A computer installed in the vehicle
processes the data received from the meters and can either keep them to be loaded manually at the utility or send them directly to the utility by means of a long-range communication network such as cellular or satellite. It is clear that this method benefits as much as it can from the utility's vehicle capabilities to reduce the losses, size and time limitations of the previous system, however a new disadvantage arises which is the inability of the vehicle to reach the range of the meter transmission in crowded or randomly-built areas.
Fixed-Network AMR
Of all the AMR implementation methods this can be called a "revolutionary method" in the way that it completely eliminates many of the problems or limitations faced in the other systems and opens the door for new functions, applications and developments to be added to the system. Figure 1.1 shows the main structure of the Fixed-Network AMR system.
CCU
(Cell Control Unit)
Electricity Meters
Cell
NCN
(Network Control Node)
Central Office
CCU
(Cell Control Unit)
The systems network components include: Cell Control Unit (CCU) Network Control Node (NCN) Utilitys Host Computer
The CCU is connected directly to one or more electrical meters. It reads meters, processes data for a variety of applications, stores data temporarily and transports the data to the Host Computer when required. The NCN is a regional concentrator and routing device that is installed on high points like power poles or street light arms clearing all the surrounding area. The primary functions of the NCN are data transfer and information routing between CCUs and the utilitys Host Computer. The Host Computer at the Central Office; which manages the collection of data
from the network devices and facilitates the download of any application information to appropriate network devices. It also transfers the data to a database for storage and retrieval [2]. A look at the system as a whole will show that a communication channel between the utility and any meter can be established 24 hours a day. Although this may seem to be very costly initially; significant saving in terms of time, efficiency and accuracy of reading should compensate after the system activation. This statement would look truer after reviewing the coming points which are just some of the Fixed-Network benefits:
Reduction in meter reading staff Improving accuracy and billing efficiency Eliminating the need to access premises Improving off-cycle reads Enabling remote line connection/disconnection process Theft identification Improving outage detection and restoration reporting
Improving reliability Improving distribution system planning Delivery of new services to customers Improving customer satisfaction
That is why our decision was made to utilize the benefits of the Fixed-Network AMR method in our project as will be discussed in the following chapters.
1.3
It is desired to build an automatic electrical-energy meter reading system using the Fixed-Network AMR technology. The new system is intended to be reliable, efficient and cost effective. It should satisfy the local-market special needs but also be flexible, scalable and expandable so that it can be used successfully in any other market or can be easily modified when a system updating plan is proposed. Taking the decision to build a Fixed-Network AMR system immediately divides our problem into subsystem problems. These are:
The Consumer-Side Terminal which consists of the meter itself and the Cell Control Unit (CCU). Problems arise here are the type of meter to be used in the system and the best implementation of the CCU, its structure, functions and the interface between the unit and the meters in its cell. For this purpose all the meters connected directly to a CCU, with the CCU itself, will be considered a Cell. The Network Control Node (NCN). As it serves as a transponder in the system, the type of the link between the NCN and the utilitys Host Computer should be determined taking into consideration what is locally most available and feasible. Another link to be specified is that between the NCN and the CCU. This link should be as cheap as could since it is essential for every cell, however it should cover wide area of cells so that the NCN can serve the maximum number of cells. An NCN with the cells it covers are said to construct a Region. Additional point that should be studied is the protocols between devices in both links and the way the NCN controls the job of CCUs in its region. The Central Office which contains the Host Computer located at the utilitys offices and the database that stores the customers information and consumption history. The billing system can be also considered a part of the whole system as it uses the data gathered by the Host Computer in issuing bills.
1.3.2
Solution Approach
Studying the available resources and approaches, the solution shown in figure 1.2 has been adopted.
NVR
NVR
M20 M20
ADE7756
PIC
ADE7756
PIC
Database
Cell
ADE7756
ADE7756
Central Office
NCN
PIC
Microcontroller
ADE7756
Digital Meter
NVR
M20
93C56 EEPROM
GSM Modem
RF Module
Host Processor
Concisely, an active-energy metering IC (Analog ADE7756) [4] receives two signals proportional to the line voltage and current from which it calculates the consumed energy. This
energy is periodically read, accumulated and stored at a high-performance microcontroller (Microchip PIC18C452) [3]. The RF transmitter (RF RTFQ1) and receiver (RF RRFQ1) [6] provide the window for the CCU to communicate with NCN. Both microcontroller and RF Tx\Rx form a CCU. The CCU can include more components depending on the additional functions added to the system. To enhance the system reliability; a non-volatile EEPROM (93C56) [7] is used to store the meter reading and other important data at a CCU or NCN; and reload the stored data at startup. At the NCN, the utilitys orders to the system are received as Short-Messaging-Service (SMS) messages through a GSM modem (M20 terminal) [5]. A microcontroller analyzes the message and sends the proper commands to all CCUs in its region or to a specific CCU only. Any readings, alerts or reports sent by the CCU are received in the NCN, reshaped to an SMSmessage form and sent again to the Host Computer.
1.4
Glossary
The following table describes some technical terms that are used in this report for clarification.
Term
ADE7756
Description
The ADE7756 active-energy metering IC produced by Analog Devices. It takes the current and voltage signals from the power line and produces digital streams representing the consumed energy and other power-line readings Automatic Meter Reading Cell Control Unit: It is the PIC and RF modules connected to the meters at the consumer side. It communicates with the NCN through the RF modules The CCU and meters connected to it The utility office that contains the Host Computer and any other supplementary devices The MAX232 low-power +5 TIA/EIA-232 dual driver/ receiver. It is used between M20 and the PIC The mainframe computer at the utility that controls the system operations The Siemens M20 Terminal which is the GSM modem of the system Network Control Node: It is a PIC connected to both the M20 and the RF modules. It represents the linking node between the utility's central office and the CCUs The 93C56 non-volatile EEPROM chip used as a storage device for the NCN and the CCU. The PIC18C452 high-performance microcontroller produced by Microchip and works as the heart of every system part The group of CCUs covered by one NCN, with the NCN itself The FM RRFQ1-433 Radio-Frequency FM receiver working at 433 MHz. It is a production of RF Solutions The FM RTFQ1-433 Radio-Frequency FM transmitter working at 433 MHz. It is also produced by RF Solutions Short Messaging Service Serial Peripheral Interface, it is a serial data transfer protocol in which a master device (SPI enabled) communicates with a slave device (SPI enabled) through some data and control lines Addressable Universal Synchronous Asynchronous Receiver Transmitter module in the PIC18C452 microcontroller. It is used to interface the PIC with other terminal equipments like a PC or the M20
AMR CCU
USART
1.5
Symbols Convention
The following symbols are used throughout this report to present the system components.
PIC
PIC18C452
MAX232
RS232/TTL Line Driver
ADE7756
ADE7756
NVR
M20
93C56 EEPROM
M20
RF Module
Host Computer
Electrical Load
1.6
Report Outline
Chapter 1: Introduction. (Akram) Chapter 2: System Infrastructure. In this chapter a detailed illustration of the main components used in the structure of the project is given. The device features that are used in the project are also previewed there. (Ramadan) Chapter 3: GSM Link. The first part of this chapter describes the connection between the M20 and the PIC in the NCN. It also discusses the method in which the SMS message is analyzed in the PIC and how a new message is built and sent to the M20. The rest of this chapter shows the GSM protocol which intends to found a shared language understood by both the PIC and M20 to achieve the systems goal and to insure secure data transfer. (Akram) Chapter 4: RF Link. This chapter deals with the RF-related components in the project, the communication between master and slave PICs in the NCN and the adaptation of the RF Tx and Rx modules. (Akram) Chapter 5: Data Gathering. In chapter 5 we investigate the way in which the ADE7756 digitally calculates energy, as well as the meter data gathering process made by the PIC at the CCU. The Power Factor calculation function is also introduced by the end of this chapter. (Ramadan) Chapter 6: Central Office. This chapter introduces a software program that simulates the Central Office. (Ramadan) Chapter 7: Total System Implementation. The operation of the system as a whole is described here using a detailed example. (Akram) Chapter 8: Conclusion. The final results of the project are shown in the last chapter. Furthermore; suggestions regarding future developments of the project are discussed here. (Akram & Ramadan)
System Infrastructure
Our desired goal is simply to establish a communication link and to gather data. The solution for our problem resides on different hardware components interacting with each other to achieve this goal. This chapter introduces these hardware modules briefly and mentions some of the good features they provide to our system*.
2.1
Microchip PIC18C452
It is simply a highly integrated chip that contains all the components comprising a controller [3]. Typically this includes a CPU, RAM, ROM, I/O ports, Digital Communication Modules, Timers and other integrated components. Unlike a general-purpose computer (which also includes all of these components), a microcontroller is designed for a very specific task; to control a particular system. As a result, the parts can be simplified and reduced, which cuts down on production costs and reduces the need for many computers to implement the system.
RB7 RB6 RB5 RB4 RB3/CCP2 RB2/INT2 RB1/INT1 RB0/INT0 VDD VSS RD7/PSP7 RD6/PSP6 RD5/PSP5 RD4/PSP4 RC7/RX/DT RC6/TX/CK RC5/SDO RC4/SDI/SDA RD3/PSP3 RD2/PSP2
The PIC within our hands is from the PIC18CXXX family. It is a family of high performance, CMOS, fully static, 16-bit MCUs (Microcontroller Units) with integrated analog-to-digital (A/D) converter. All PIC18CXXX MCUs incorporate an advanced RISC architecture. The PIC18CXXX has enhanced core features, 32 level-deep stack, and multiple internal and external interrupts sources. The separate instruction and data busses of the Harvard architecture allow a 16-bit wide instruction word with the separate 8-bit wide data. A total of 77 instructions (reduced instruction set) are available. The PIC18CXXX family has special features to reduce external components, thus reducing cost, enhancing system reliability and reducing power consumption. The PIC18CXXX family is considered among the top of the shelf considering Microchip products. The C letter in the PIC18CXXX indicates that this family of MCUs is an OTP program-memory (One-Time-Programmable), which means that the memory used for storing the program can't be cleared electrically (not EEROM) but by using ultraviolet radiation (it is EPROM). Other Microchip Families (e.g. PIC16FXXX) are Flash MCUs, this means that they can be programmed and erased electrically without the need to the ultraviolet radiation (EEROM), this makes the development process faster, but since there were no PIC18FXXX MCUs available, we had to use this family because of the more features it provides.
MCLR/VPP RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS/LVDIN RE0/RD/AN5 RE1/WR/AN6 RE2/CS/AN7 VDD VSS OSC1/CLKI OSC2/CLKO/RA6 RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RD0/PSP0 RD1/PSP1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
PIC18C45 2
11
* Most of the figures in this chapter are extracted from the datasheets of each hardware module. One can find these datasheets on the companion CD
The PIC18C452 has 32K bytes of EPORM (Program memory) and 1536 bytes of RAM (Scratch Board), this relatively huge-program-memory space helps us develop software with this PIC that can't be developed with others. The PIC18C452 can operate at a frequency up to 40 MHz. Software development for the PIC18C452 (and any PIC from any family) can be done using the MPLAB. The MPLAB is a complete Integrated Development Environment (IDE) from Microchip, it allows the user to edit, debug, compile, download code and even simulate from a single user interface. MPASM is a utility that is integrated with the MPLAB; it helps simulating software behavior before downloading the final machine code to the PIC. The PICSTART Plus is a serial hardware programmer that can be used within the MPLAB to program the PIC. The development for the PIC18C452 can be either using the C language or the assembly language; we have developed all the programs using the assembly language.
In the next subsections we will introduce some of the main features of the PIC18C452 that will help build up the system. The PIC18C452 is the core of our system because it has to interface almost all other modules.
2.1.1
Interrupts
Interrupt-driven software simplifies development and helps build a more rigid system. Interrupts can come from many sources (internal and external). We shall be using interruptdriven architecture throughout the entire system. This means that each module in the system has its own interrupt that the PIC sees and services. There are two interrupt vectors. One interrupt vector is for high priority interrupts and is located at address 000008h. The other interrupt vector is for low priority interrupts and is located at address 000018h. We shall use interrupt priority because of the many interrupts requesting servicing; and some interrupts are considered much more important than others.
12
The PIC (in general) has four registers associated with interrupts. The INTCON register contains the Global Interrupt Enable bit (GIE), as well as the Peripheral Interrupt Enable bit (PEIE), the PIE/PIR register pair that enables the peripheral interrupts and displays the interrupt flag status and the Interrupt Priority Register (IPR) that controls whether the interrupt source is a high priority or low priority interrupt. There are other registers used to pull interrupt statuses for other internal and external modules too. When a valid interrupt occurs, program execution vectors to one of these interrupt vector addresses and the corresponding Global Interrupt Enable bit (GIE, GIEH, or GIEL) is automatically cleared (this is done to disable other interrupts from generating another interrupt signal while servicing the current). In the interrupt service routine, the sources of the interrupt can be determined by testing the interrupt flag bits. The interrupt flag bits must be cleared before re-enabling interrupts to avoid infinite interrupt requests. Most flag bits are required to be cleared by the application software. There are some flag bits that are automatically cleared by the hardware. When an interrupt condition is met; that individual interrupt flag bit will be set regardless of the status of its corresponding mask bit. While like in normal operation one needs to push and pop the WREG and STATUS registers; this is not necessary in our case because the PIC18C452 automatically pushes and pops these registers at interrupts. The return from interrupt instruction, RETFIE, can be used to mark the end of the interrupt service routine. When this instruction is executed, the stack is popped and the GIE bit is set (re-enable interrupts). For more information about interrupts, see the Interrupt Logic Block Diagram in the PIC18C452 datasheets on the companion CD, it presents a good understanding of the interrupt login in the PIC18C452.
2.1.2
I/O Ports
General purpose I/O pins can be considered the simplest of the peripherals the PIC provides. They allow the PIC to monitor and control other devices. To add flexibility and functionality to a device, some pins are multiplexed with other functions. These functions depend on which peripheral features are on the device. In general, when a peripheral is functioning, that pin may not be used as a general purpose I/O pin. For most ports, the I/O pins direction (input or output) is controlled by the data direction register, called the TRIS register. TRIS<x> controls the direction of PORT<x>. A 1 in the TRIS bit corresponds to that pin being an input, while a 0 corresponds to that pin being an output. The PORT register is the latch for the data to be output. When the PORT is read, the device reads the levels present on the I/O pins (not the latch). I/O ports were used here for many reasons; one reason is to let the PIC control other devices (e.g. we will control another PIC in the NCN module), another reason is to simply use LEDs to show the progress of the software on the PIC. Since these I/O pins are multiplexed with other features; we have used many of the features through these pins. The PIC18C452 has 5 I/O ports different in length; they are PORTA, PORTB, PORTC, PORTD and PORTE. We will be utilizing some of the pins of all ports except PORTE. For detailed information about these ports, refer to the PIC18C452 datasheets on the companion CD.
2.1.3
Addressable USART
The Addressable Universal Synchronous Asynchronous Receiver Transmitter (Addressable USART) module is one of the serial I/O modules available in the PIC18CXXX family (another is the MSSP). The USART can be configured as a full duplex asynchronous system that can communicate with peripheral devices, such as personal computers.
13
The USART module can be setup through the TXSTA and RCSTA registers; setup includes selecting the serial communication type (synchronous or asynchronous), number of bits, baud rate The PIC will use this module to communicate with the Siemens M20 and with the other CCUs through the RF modules. We shall be using the PIC in the asynchronous mode. Asynchronous mode is selected by clearing the SYNC bit (TXSTA register). In this mode, the USART uses standard NRZ format (one start bit, eight or nine data bits and one stop bit), we are using the 8 bits format. An on-chip special 8-bit baud rate generator can be used to derive standard baud rate frequencies from the oscillator. The USART transmits and receives the LSb first. The USARTs transmitter and receiver are functionally independent, but use the same data format and baud rate. The baud rate generator produces a clock either x16 or x64 of the bit shift rate, depending on the BRGH bit (TXSTA register). The data on the RX pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the RX pin. The USART transmitter block diagram is shown beside. The heart of the USART transmitter is the transmit shift register (TSR). The shift register obtains its data from the read/write transmit buffer, TXREG. The TXREG register is loaded with data in software. The TSR register is not loaded until the STOP bit has been transmitted from the previous load. As soon as the STOP bit is transmitted (we have to keep pulling the TXSTA<TRMT> bit), the TSR is loaded with new data from the TXREG register. Once the TXREG register transfers the data to the TSR register, the TXREG register is empty and flag bit TXIF (PIR1<4>) is set.
Data Bus TXIF TXIE MSb (7) TSR Register Interrupt TXEN Baud Rate CLK TRMT SPBRG Baud Rate Generator SPEN TXREG Register 8 LSb 0 Pin Buffer and Control RC6/TX/CK
SPBRG
MSb STOP 7
RSR Register 1
LSb 0 START
Baud Rate Generator Pin Buffer and Control RC7/RX/DT Interrupt RCIF RCIE 8 Data Bus Data Recovery FIFO RCREG Register
SPEN
In the receiver block diagram. The data is received on the RC7/RX/DT pin and drives the data recovery block. The data recovery block is actually a high speed shifter operating at x16 times the baud rate; whereas the main receive serial shifter operates at the bit rate, or at FOSC. To set up an Asynchronous Reception: Initialize the SPBRG register for the appropriate baud rate. Enable the asynchronous serial port. If interrupts are desired (we will use the receive interrupt later on); we must set the enable bit RCIE. We enable continuous reception by setting bit CREN. Flag bit RCIF will be set when reception is complete and an interrupt will be generated. The PIC goes into an ISR (interrupt service routine). The software there pulls the RCIF bit and determines the source of the interrupt. Read the 8-bit received data by reading the RCREG register. The baud rate is generated by writing to the SPBRG register; the value in this register is evaluated in a formula along with the clock frequency of the PIC to determine the desired baud
14
rate. Choosing a clock frequency of 3.6864 MHz was made to ensure no percentage of error is in the desired baud rate. For more information about the USART, refer to the PIC18C452 datasheets on the companion CD.
2.1.4
The Master Synchronous Serial Port (MSSP) module is a serial interface useful for communicating with other peripherals or microcontroller devices. These peripheral devices may be serial EEPROMs, shift registers, display drivers, A/D converters, etc. The SSP module can operate in one of two modes:
Serial Peripheral Interface (SPI): It is typically a 3-wire interface, with a data out line (SDO), a data in line (SDI), and a clock line (SCK). Since the clock is present, this is a synchronous interface
We shall use the MSSP in the SPI mode because all of the peripherals that the PIC has to communicate with are SPI enabled. The PIC uses the SPI to communicate with the ADE7756 and the Slave PIC; this is why we should thoroughly explain the SPI. SPI operates in 4 different modes (2 master modes and 2 slave modes). SPI is a masterslave data interface; this means that one part has to generate the clock (and optionally the Chip Select) signal. We will be using the PIC in different SPI modes depending on the situation. (Coming a head: we will connect two PICs together through the SPI to interchange data, this means that one must be set to Master mode and the other must be set to Slave mode). The SPI mode allows 8-bits of data to be synchronously transmitted and received simultaneously. When initializing the SPI, several options need to be specified. This is done by programming the appropriate control bits in the SSPCON register (SSPCON<5:0>) and SSPSTAT<7:6>. These control bits allow the following to be specified:
Master Mode (SCK is the clock output) Slave Mode (SCK is the clock input) Clock Polarity (Idle state of SCK) Clock edge (output data on rising/falling edge of SCK) Data Input Sample Phase Clock Rate (Master mode only) Slave Select Mode (Slave mode only)
Internal Data Bus Read SSPBUF reg Write
The MSSP consists of a transmit/receive Shift Register (SSPSR) and a buffer register (SSPBUF). The SSPSR shifts the data in and out of the device, MSb first. The SSPBUF holds the data that was written to the SSPSR, until the received data is ready. Once the 8-bits of data have been received, that byte is moved to the SSPBUF register. Then the buffer full detect bit, BF (SSPSTAT<0>), and interrupt flag bit, SSPIF, are set. This double buffering of the received data (SSPBUF) allows the next byte to start reception before reading the data that was just received. Any write to the SSPBUF register during transmission/reception of data will be ignored, and the write collision detect bit, WCOL (SSPCON<7>), will be set. When the application software is expecting to receive valid data, the SSPBUF should be read before the next byte of data to transfer is written to the SSPBUF. Buffer full bit, BF (SSPSTAT<0>), indicates when SSPBUF has been loaded with the received data (transmission is complete). When the SSPBUF is read, the BF bit is cleared. This data may be irrelevant if the SPI is desired
SS Control Enable SS Edge Select 2 Clock Select SSPM3:SSPM0 SMP:CKE 4 TMR2 output 2 2 Edge Select Prescaler TOSC 4, 16, 64
SCK
15
only to transmit. Generally the SSP Interrupt is used to determine when the transmission/reception has completed. The SSPBUF must be read and/or written. If the interrupt method is not going to be used, then software polling can be done to ensure that a write collision does not occur. We shall be using the interrupt method. In the Master mode: the master can initiate the data transfer at any time because it controls the SCK. The master determines when the slave (Processor 2) is to broadcast data (the slave can only give the data when the master enables the clock). Data is transmitted / received as soon as the SSPBUF register is written to. As each byte is received, it will be loaded into the SSPBUF register as if a normal received byte (interrupts and status bits appropriately set). The clock polarity is selected by appropriately programming bit CKP (SSPCON<4>). The SPI clock rate (bit rate) is user programmable to be one of the following:
This allows a maximum data rate of 5 Mbps (at 20 MHz). In slave mode: the data is transmitted and received as the external clock pulses appear on SCK (generated by the master device). When the last bit is latched, the interrupt flag bit SSPIF is set. When in slave select mode, the SS pin allows multi-drop for multiple slaves with a single master (we will use this mode because the master PIC is going to interface both the ADE7756 and the slave PIC). To enable the serial port the SSP Enable bit, SSPEN (SSPCON<5>), must be set. To reset or reconfigure SPI mode, clear the SSPEN bit which re-initializes the SSPCON register, and then set the SSPEN bit. This configures the SDI, SDO, SCK, and SS pins as serial port pins. For the pins to behave as the serial port function, they must have their data direction bits (in the TRIS register) appropriately programmed. That is:
SDI must have the TRIS bit set SDO must have the TRIS bit cleared SCK (Master mode) must have the TRIS bit cleared SCK (Slave mode) must have the TRIS bit set -SS have the TRIS bit set
For more information about the SPI, refer to the PIC18C452 datasheets on the companion CD.
2.1.5
Timer0
The Timers modules embedded within the PIC present a simple counter/timer for the use of counting external pulses or timing a periodic task to happen. We need to use the timer module because we have to perform certain periodic tasks (e.g. reading the accumulated energy from the ADE7756). Timer0 helps doing so by generating an interrupt every 2 seconds (programmable). Timer mode is selected by clearing the T0CS bit (T0CON register). In timer mode, the Timer0 module will increment every instruction cycle. Timer0 can be configured as an 8-bit or a 16-bit timer. To configure the timer as a 16-bit counter, the T08BIT bit (T0CON register) must be cleared. We are using the timer mode not the counter mode because we want to generate a periodic interrupt.
16
The TMR0 interrupt flag bit is set when the TMR0 register overflows. When TMR0 is in 8-bit mode, this means the overflow from FFh to 00h. When TMR0 is in 16-bit mode, this means the overflow from FFFFh to 0000h. This overflow sets the TMR0IF bit (INTCON register). The interrupt can be disabled by clearing the TMR0IE bit (INTCON register). The TMR0IF bit must be cleared in software by the interrupt service routine.
TIMER0 BLOCK DIAGRAM IN 16-BIT MODE
FOSC/4 0 0 1 T0CKI pin T0SE Programmable Prescaler 3 T0PS2, T0PS1, T0PS0 T0CS PSA 8 8 TMR0H 8 Data Bus<7:0> 1 Sync with Internal Clocks (2 TCY delay) TMR0L TMR0 High Byte 8 Set Interrupt Flag bit TMR0IF on Overflow
There is a prescaler for Timer0, this prescaler is enabled or disabled in software by the PSA bit (T0CON register). Setting the PSA bit will enable the prescaler. The prescaler can be modified under software control through the T0PS2:T0PS0 bits. When the prescaler is enabled, prescaler values of 1:2, 1:4... 1:256 are selectable. We want to generate an interrupt every 2 seconds; this is done by setting Timer0 to 16bit timer mode (with internal clock), and writing E3E0h to the Timer0 high and low bytes (TMR0H and TMR0L). This means that Timer0 will overflow from FFFFh to 0000H after 7.8125 msec. This 7.8125 msec is multiplied by the prescaler 256 to give a total of 2 seconds. For more information about Timer0, refer to the PIC18C452 datasheets on the companion CD.
Remember
The PIC18C452 will be referred to throughout the entire text as the symbol shown.
PIC
17
2.2
M 20 Terminal
The Siemens M20 Terminal is a GSM900 Phase II voice, data, fax and SMS terminal device. This device is intended for universal use in various areas of application. The most important features of the M20 are: SDI must have the TRIS bit set Data, voice, fax and SMS services GSM 900 Phase II Data transmission rate up to 9600 bps SMS (Text mode, PDU mode) Sensitivity 108 dBm Integrated echo suppression and noise reduction (for handset) Digital audio interface Mini SIM card reader with integral drawer (3V) Reloadable software Software interface with commands as AT-Hayes 2W power Power supply (8 V to 28.8 V) Terminal equipment (TE) interface using RS232: Baud rates: 300-57600, default 19200. Weight 145 g Dimensions (max) LxWxH = 107.0 x 63.5 x 31.3 mm We are using the M20 to establish the link between the Central Office and the NCN. The broadness of the GSM network will give our system the great benefit of covering the largest area possible.
2.2.1
AT Commands
The operating functions of the M20 Terminal are accessed through the use of AT commands; these AT commands are conforming to GSM 07.07 and GSM 07.05 standards. AT commands are available via the serial interface of the M20 for function implementation. The AT standard is a line-oriented command language. Each command is made up of three elements: the prefix, the body, and the termination character.
18
The prefix consists of the letters AT The body is made up of individual characters; it consists of a name and (if The default termination character is <CR>(= 0x0D)
Example: AT+CMGR="12" This command reads the message with index 12 stored in the default SIM card place. Commands for the M20 can be categorized in two categories:
Setup commands: used to set the different parameters of the M20 (e.g. Baud rate, response type) Communication Commands: used to establish communication using the M20 (e.g. Read & Send SMS)
The M20 implements what is called User Profiles; they are non volatile memory (NVR) used to store the parameters the user sets for the M20. When the M20 is operated the next time, it will load the defined user profile at start up. This helps reduce AT commands used to setup the M20 on each startup. Yet, not every setting for a parameter can be saved in a user profile; that's why we need to initialize these parameters on every startup (e.g. to disable echoing characters back on the serial interface, we must send the ATE0 command to the M20 each time we start the M20 up). The specific AT commands that are needed for out system implementation shall be mentioned when we talk about connecting the M20 with the PIC18C452. For a complete list all AT commands for the M20, refer to the datasheets on the companion CD.
2.2.2
M20 Interface
As mentioned before; the M20 is accessed through the serial interface using RS232. We are using the DB9 connector. The DB9 connector has 9 signals, but we are not using all these signals; we are only using the basic TXD, RXD and GND signals to establish the interface. The M20 supports handshaking through the serial interface, but we are not using this feature because the M20 has to be connected to the PIC18C452; and the PIC doesn't support handshaking though its USART module.
Pin 1 2 3 4 5 6 7 8 9 Description Data Carrier Detect (DCD) Receive Data (RXD) Transmit Data (TXD) Data Terminal Ready (DTR) Ground (GND) Data Set Ready (DSR) Request to Send (RTS) Clear to Send (CTS) Ring Indication (RING)
5 9 4 8 3 7 2 6 1 DB9 CONNECTOR
Figure 2.7: Pin Diagram of the DB9 Connector. The M20 Uses Only the Marked Signals
2.2.3
The GSM link will connect the NCN with the Central Office. The M20 provides us with more than one way to establish the link (Voice, Data, Fax and SMS) and the SMS sounds the best to use for the current system. SMS (Short Messaging System) is easy to implement and is cheap. A standard message will contain 160 characters which is pretty enough for the type of data we are planning the send and receive.
19
The SMS in the M20 supports two modes: the Text mode and the PDU (Protocol Data Unit) mode. The text mode is the normal mode used between people sending each other messages using regular mobiles. The PDU mode is a special mode where data can be send using certain protocols that comprises specific data and certain data coding schemes, PDU messages can handle more data than a normal text mode message. Below is an example of a PDU message. The normal Service Center may not handle PDU formatted messages.
MR PDUtype DCS (7-bit coding) PID
0011000781214365F70000AA05E8329BFD06
SCA len VP (four days) type of Destination Adress: number (Phone-number 1234567) UDL UD ("hello" in 7 bit default alphabet)
We shall be using the SMS in the text mode because the data being sent and received is simple. Security is handled through creating our own GSM protocol; this protocol helps immune the system and handles errors. The GSM protocol will be mentioned with more details when we talk about connecting the M20 with the PIC18C452. SMS is handled using certain AT commands through which we can read and write messages.
Remember
The Siemens M20 will be referred to throughout the entire text as the symbol shown.
M20
20
2.3
RF Modules
An important goal in our design is to make the system cost effective; we can't put an M20 Terminal on every node in the system that we wish to get readings from, instead we shall be using cheap RF modules to link the NCN with the surrounding CCUs. This will reduce cost and will produce a nice challenge to stand for. RF modules are specified by their operating frequency, modulation type, maximum data rate and maximum distance of operation (in both open fields and in buildings). FM transceivers are considered more stable in operation than AM transceivers, because FM transceivers are more noise-immune than AM ones. The frequency spectrum is divided between major systems in almost every country in the world, e.g. the cellular system in Jordan operates in the frequency range around 900 MHz. The frequency around 433 MHz can be used by the public (within some standard operating ranges and conditions), and it is the frequency of operation of the RF modules in our hands. The 433 MHz is not used in Jordan by any major system. According to the communication theory, the antenna length of the modules should be (/4), that's about 17 cm. No special antennas where used here because the transmitter and the receiver were too close to each other for the demo purposes, but if they are to spaced a larger distance; we should consider changing the antenna type. The RF modules in our hands are the transmitter FM-RTFQ1-433 and the receiver FM-RRFQ1-433; they are both made by the company (RF Solutions). They operate on the 433 MHz frequency and the transmitter range is about 75 meters between buildings (which defines the maximum radius of our Region), this range depends mainly on the type of antenna used and on the positioning of the module.
2.3.1
FM-RTFQ1-433
It is the transmitter module [6]; it uses a special purpose IC that does the job of modulating the signal using FSK modulation. The maximum input frequency is 4.6 Kbps. The transmitter operates at a voltage level of 3V; this was made to reduce power dissipation and to let the module be used in handheld devices. (This requires some signal level modifications because all of the other digital circuitry is devices that operate at the 5V voltage level).
In
XTAL
XTAL Oscillator
PLL Synthesizer
En
2 3
5 4
Pin 1 2 3 4 5 6
Description Enable (active high) Data input Ground, Connect to RF earth return path Supply Voltage Ground, Connect to RF earth return path External Antenna
The FM transmitter uses an internal PLL circuit (Phase Locked Loop) to lock on the carrier frequency of 433 MHz. This PLL requires time to lock to the frequency each time we transmit, this problem is handled by software; we will mention it in more details when we put the RF modules and the PIC together.
21
2.3.2 FM-RTFQ1-433
It is the receiver module [6]; it also uses a special purpose IC that does the job of demodulating the received signal (it uses the TDA 5210, it is an ASK/FSK Single Conversion Receiver). Unlike the transmitter, the receiver operates at the 5V voltage level; this makes it ready for connection with the other digital circuitry.
Vcc In Vcc
Mixer
10.7MHz IF Filter
FM Demodulator
Comparator
Out
GND
PLL Synthesizer
GND
GND
Component Side 1 3 7 11 15
Pin 1 2 3 7
Pin 11 12,13 14 15
The FM receiver uses an internal intermediate frequency of 10.7 MHz, after that it demodulates the signal and a comparator outputs either a "1" or a "0" at a CMOS/TTL voltage level. The receiver operates only when there is a carrier signal detected, if there is no carrier detected it will keep generating noise (this problem was faced because the manufacture didnt use the Carrier Detect signal provided on the TDA 5210 IC, this raised some problems when implementing the modules in the final system, we will discuss this problem later on). For more information about the RF modules, refer to the datasheets on the companion CD.
Remember
The RF module will be referred to throughout the entire text as the symbol shown.
22
2.4
Analog ADE7756
From Analog Devices, the ADE7756 [4] is a high accuracy electrical power measuring IC. Output data can be read either from the serial interface (using an MCU) or from the pulse output (using a pulse counter). The ADE7756 incorporates two second order sigma-delta ADCs, reference circuitry, and all the signal processing required to perform active power and energy measurement.
AV DD
Reset DV DD AV DD V1P V1N V2N V2P AGND REF IN/OUT DGND
1 2 3 4 5 6 7 8 9 10 20 19 18 17
RESET
DVDD
DGND
PGA V1P V1N TEMP SENSOR V2P V2N 2.4V REFERENCE 4k ADC ADC
MULTIPLIER
HPF1
MULTIPLIER
LPF2
ADE7756
ZX SAG
APGAIN[11:0] PHCAL[5:0]
APOS[11:0]
ADE7756
TOP VIEW
16 15 14 13 12 11
O
ADE7756 REGISTERS AND SERIAL INTERFACE
DFC
CF CFDIV[11:0]
LPF1
AGND
REFIN/OUT
CLKIN
CLKOUT
Figure 2.11: Analog ADE7756, Pin Configuration & Functional Block Diagram
The ADE7756 uses two differential input Channels (voltage and current signals) to calculate the energy consumed by a certain electrical load after performing certain digital steps. The two channels are input both as voltage signals. The current signal is converted into a voltage signal using traditional current sensing tools (shunt or current transformer).
2.4.1
Basic Operation
Simply, the main function of the ADE7756 is to multiply the voltage channel (CH2) by the current channel (CH1) and extract the DC component of the product (LPF2). The result of this DSP is the active (average) power. The ADE7756 accumulates this information and provides the active energy in a register (AENERGY). A frequency output (CF) is proportional to the active energy and can be used to drive a pulse counter or simply a LED.
0110010101
ADC Currnet
Instantaneous Power 0110010101
LPF
Average Power
Accumulate
Consumed Energy
ADC Voltage
The input channels are sampled at a frequency up to CLKIN/128, each sample is a 20bit sample, this very high sampling rate helps reduce digitization errors and produce a more correct output. The ADE7756 is accessed through a data transfer protocol called SPI (refer to the PIC18C452 section for details about this protocol). Through SPI we set the ADE7756's different parameters to properly produce the desired output. Output on the other hand can be read through two different ways: either using the SPI to read a 40-bit register (AENERGY) that holds the accumulated energy (for a specific time), or using a hardware pulse counter to count the pulse output (CF), this pulsing output is proportional to the accumulated energy. Since we are using the PIC18C452, we shall be using the SPI method to configure the ADE7756 and read the accumulated energy. A simple LED is connected to the (CF) signal to show the frequency proportionality to the energy.
23
This basic interpretation was made to simplify the ADE7756 operation. The ADE7756 goes in much more complex steps and process to produce the final output. For more detailed information about the ADE7756 operation, refer to the datasheets on the companion CD.
2.4.2
The load is connected to the ADE7756 by its voltage and current signals. The voltage channel represents the line voltage. Referring back to the datasheets; we see that there are conditions for the input voltage and current channels, the most important condition is that the inputs don't exceed the max range of 1 volt; this condition is satisfied for both the current and the voltage as follows: The voltage is dropped down from 220V to about 1V in two steps; the 1st step is using a drop down transformer that drop the voltage from 220V to 12V, the 2nd step is to use a voltage divider with large resistor values to drop the voltage further to about 0.92V.
Current Sensor
220/12 20 19 18 17 16 15 14 13 12 11 1 2 3 4 5 6 7 8 9 10
DIN RESET DOUT DVDD SCLK AVDD CS V1P CLKOUT V1N CLKIN V2P IRQ V2N SAG AGND ZX REF CF DGND ADE7756
20K
10K
Votage Sensor
100K
The current is not fed directly as it is to the ADE7756 but rather as a voltage equivalent, this is made by allowing the current to flow in a small resistance (shunt) to produce a voltage, this voltage is taken as to represent the current, and it should not exceed the 1 volt barrier. This condition is simply made by putting a very small resistance (about 1) in the way of the current, making sure the voltage produced is less that 1 volt (for the present load). For larger loads; smaller shunts are needed, some designs for the ADE7756 suggested a special type shunt of 100. For the sake of demonstration; we are using a regular lamp bulb as a load.
2.4.3
Through SPI we talk to the ADE7756 using the PIC18C452, the ADE7756 is accessed by simply writing to special registers and reading from certain register, it has 18 registers different in length, most of them are writable but all are readable. All registers of the ADE7756 are on the datasheets. Before reading or writing any register, we must provide the ADE7756 with the address of that register, we use the Communication register to do that; by writing to this 8-bit register, we say to the ADE7756 that we need to read a certain register (with the address A4A3A2A1A0) or write to a one.
DB7 W/-R DB6 0 DB5 0 DB4 A4 DB3 A3 DB2 A2 DB1 A1 DB0 A0
Example: if we want to read the active energy register (AENERGY with address 02h), we simply write 02h to the Communication register, after that we read from the SPI 5 times to get the 40-bit AENERGY register. This register is a read only register; this means that writing to this address (Communication register=82h) will result in nothing. The most important register that determines the operation of the ADE7756 is the MODE register, it is a 16-bit register that controls most of the features in the ADE7756; features like enabling or disabling filters and choosing the sampling rate for the ADCs, we can even choose what output we want (we can read the sampled waveforms of channel 1 and channel2). Most of the features of the ADE7756 are listed in the next section.
24
15 0 TEST 1 (TEST MODE SELECTION SHOULD BE SET TO 0) WAVSEL (WAVE FORM SELECTION FOR SAMPLE MODE) 00 = LPF2 01 = RESERVED 10 = CH1 11 = CH2 DTRT (WAVE FORM SAMPLES OUTPUT DATA RATE) 00 = 27.9kSPS (CLKIN/128) 01 = 14.4kSPS (CLKIN/256) 10 = 7.2kSPS (CLKIN/512) 11 = 3.6kSPS (CLKIN/1024) SWAP (SWAP CH1 AND CH2 ADCs) DISCH2 (SHORT THE ANALOG INPUTS ON CHANNEL 2) DISCH1 (SHORT THE ANALOG INPUTS ON CHANNEL 1)
14 0
13 0
12 0
11 10 0 0
9 0
8 0
7 0
6 0
5 0
4 0
3 1
2 1
1 0
0 0 ADDR: 06H DISHPF (DISABLE HPF IN CHANNEL 1) DISLPF2 (DISABLE LPF2 AFTER MULTIPLIER) DISCF (DISABLE FREQUENCY OUTPUT CF) DISSAG (DISABLE SAG OUTPUT) ASUSPEND (SUSPEND CH1 AND CH2 ADCs) TEMPSEL (START TEMPERATURE SENSING) SWRST (SOFTWARE CHIP RESET) CMODE (CALIBRATION MODE)
2.4.4
Special Features
Phase Compensation: While we are using a shunt as the current sensor, we can use a current transformer (CT) to do the same job. A CT has the advantage of isolating the primary signal from the secondary signal, but it also has the disadvantage of producing phase errors between the two channels, this leads to errors in the final reading. Phase errors could occur internally in the ADE7756 itself, we need a way to fix these errors if they happen. The ADE7756 can do phase compensation in the range 0.1-0.5, phase compensation is made by setting a time delay or a time advance in the channel 2 processing chain, the value of this time compensation can bet set by writing to the register (PHCAL). DC Offset: We could face the problem of DC shifts in the channels after they are sampled; such shifts add DC errors to the active power and this affects the final output. We can get rid of this error by simply removing the DC offset from any channel. The ADE7756 can remove the DC offset from channel 1 by filtering its output using a high pass filter HPF1. DC offsets can happen either externally or they can be due to the internal ADCs them self.
Zero Crossing Indication: the ADE7756 has an output pin (ZX) that alternates with the each zero crossing of the line voltage, the ZX signal will go logic high on a positive going zero crossing and logic low on a negative going zero crossing on Channel 2. Monitoring this pin will detect losses in the line voltage.
Line Voltage SAG Detection: In addition to the detection of the loss of the line voltage signal (zero crossing), the ADE7756 can also be programmed to detect when the absolute value of the line voltage drops below a certain peak value (specified by the SAGLVL register), for a number of half cycles of the voltage line (specified by the SAGCYC register). If such condition happens; the ADE7756 will set the SAG pin low. Monitoring the SAG pin can be used as a warning indication if there is a fault on the voltage line. Using this feature; we can perform certain actions as soon as possible (e.g. saving the data on an EEROM, sending a message indicating a line failure, and so on).
Waveform Sampling: The default output from the ADE7756 is the active energy read from the AENERGY register, yet we can get other outputs from the ADE7756 other than the energy; the ADE7756 can provide us with waveform sampling for channel 1 and 2 (the current and the voltage signals), the availability of such digital outputs widens the scope of the data we can provide for the electrical power system, we can perform DSP on the waveforms and calculate different system parameters like the active and reactive power, RMS values for the current and voltage, PF and much more. Waveform samples can be taken by setting the WAVSEL two bits MODE<14, 13> to select the desired waveform to sample and read at the output.
25
The default value is 00 which means that the output is the active energy, e.g. to read the waveform samples of the current signal on channel 1; we set the WAVSEL bits to 10.
Temperature Sensor: The ADE7756 provides the user with a temperature output, this output can also be used for performance monitoring too.
Remember
The ADE7756 will be referred to throughout the entire text as the symbol shown.
ADE7756
26
2.5
CS SK DI DO
1 2 3 4
8 7 6 5
VCC NC NC GND
DI
INSTRUCTION REGISTER
VCC
ADDRESS REGISTER
DECODER
EEPROM ARRAY
16
CS SK DI DO GND NC VCC
Chip Select Serial Data Clock Serial Data Input Serial Data Output Ground No Connect Power Supply
DO
READ/WRITE AMPS
16
VSS
The 93C56 is a 2048-bit serial CMOS non-volatile EEPROM; it is organized as an array of 128X16. It can retain stored data up to 40 years with no power supply connected. Fairchild Company manufactured the chip we're using. The chip is interfaced through the serial peripheral interface (SPI), it is connected to the standard 4 wires of the chip select (CS), clock (SK), data input (DI) and data output (DO) signals. The SPI settings of the PIC should be set as to function properly with this chip.
2.5.1
All features of the 93C56 can be accessed through 7 instructions implemented on the chip; these instructions are used for various Read, Write, Erase and Write Enable/Disable operations. The instructions are shown in table 2.1.
Instruction READ WEN WRITE WRALL WDS ERASE ERAL Meaning Read stored words in the 93C56. The address must be specified Write Enable, this instruction must be issued at least once before any reading process to take place Store data as words in the 93C56. The address must be specified Write All, used to fill all the 128 words of the 93C56 with the word in the data field Write Disable, used to protect the data stored in the chip. This must be used if no writing is to be made for a long period Fills the specified addressed word with 1s Erase All, used to fill all the 93C56 words with 1s
The 93C56 provides more than the basic Read and Write functions; other functions are used to help maintain the system (like erasing all the data and disabling writing). Any function of these is accessed by sending the 93C56 the corresponding instruction data shown in table 2.2.
27
Since the 93C56 is a 2048-bit memory organized as 16-bit words; the address range for the whole words stored is 0x00-0x7F. We will be using this address for accessing our data in the 93C56.
Instruction READ WEN WRITE WRALL WDS ERASE ERAL Start Bit 1 1 1 1 1 1 1 Opcode Field 10 00 01 00 00 11 00 Address Field A5 A4 A3 A2 X X X X A5 A4 A3 A2 X X X X X X X X A5 A4 A3 A2 X X X X Data Field A1 X A1 X X A1 X A0 X A0 X X A0 X
X 1 X 0 0 X 1
A6 1 A6 1 0 A6 0
D15-D0 D15-D0
2.5.2
Counting these bits will result in 11 bits or 27 bits (depending on the instruction). Such numbers of bits don't constitute an integer number of bytes; we need them to constitute an integer number of bytes because the SPI module of the PIC handles bytes only. This problem is solved by introducing null zeros before issuing the start bit as shown in the figure. Such argument is valid also when sending the data filed (not shown in figure).
Start Bit Opcode Address Field
1 XXXXXXX
Byte1
Null Zeros Start Bit Opcode
XXX
Byte2
Address Field
0 0 0 0 01 X X
Byte1
XXXXXXXX
Byte2
Figure 2.17: Adapting the Instruction Bits sent to the 93C56 from the PIC18C452 to form an integer number of bytes
Another issue that needs solving is the incoming data from the 93C56 (the addressed word), the 93C56 sends a dummy zero bit before sending the 16-bit word to the PIC. This additional added bit at the beginning of the data string forces the PIC to read 3 bytes from the st 93C56 (because the total number of bits is 17), the 1 byte holds the dummy bit along with the 7 MSBs of the addressed word, and the reset of the addressed word is in the other 2 bytes. This problem is handled in a similar manner, but further bits manipulation is involved.
Remember
The 93C56 EEPROM will be referred to throughout the entire text as the symbol shown.
NVR
28
2.6
Supplementary Hardware
We have introduced most of the major hardware modules we are going to use in the system; however the system still needs extra hardware to help put all these modules together.
Remember
The Line Driver will be referred to throughout the entire text as the symbol shown.
MAX232
R2 240
Signal (0 and 5 V)
U1A 1 2
2.2K
74LS07
This configuration is used only for the input data driving the FM transmitter, we need not do this for the output data coming from the FM receiver because the receiver outputs a TTL signal be default.
29
GSM Link
3.1
PIC
Master PIC
Mother Unit PIC 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RB2/INT2 RA4/T0CKI RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
MAX232
Driver
M20
M20
13 8 11 10 1 3 4 5 2 6 16
12 9 14 7
SIEMENSE
1 2 3 Tx Rx GND Antenna 4
M20
M20 Initialization
At the PIC startup, the PIC sends a byte representing the termination character of the M20, which is the Carriage Return (CR) character, to cancel any previous pending command in the M20 due to error. An ASCII character is output from the PIC as a hexadecimal code representing that character.
Termination Character The character that must end every AT command line. Default: CR
An optional feature of the M20 is that it can echo any character received through the serial port. This is useful and user-friendly property when using a monitor-furnished system.
*The concept of Slave PIC is discussed in more details in Chapter 4
31
However in our system where the communication is fully machine communication the echoed characters are redundant; thus the PIC disables this feature using the ATE command.
ATE Command Format ATE [<value>] Enable command echo This command determines whether or not the M20 terminal echoes characters received from serial port during command state. Parameter <value> 0 Echo mode off 1 Echo mode on
Some GSM networks support more than one mode of SMS messages. Thus the M20 gives the user the option to select his/her mode using the AT+CMGF command. We only need to use the common used one, TEXT mode.
AT+CMGF Command Format AT+CMGF=[<mode>] Select SMS message format This command specifies the input and output mode of messages to be used. Parameter <mode> 0 PDU mode 1 Text mode
The next step is to delete all messages in the memory of the SIM card installed in the M20. This will ensure no full-inbox case would take place during the M20 operation. The delete command AT+CMGD should be repeated 19 times to empty all memory locations.
AT+CMGD Command Format AT+CMGD=<index> Delete SMS message M20 terminal deletes the SMS message stored in memory location <index>. Parameter <index> the index of the message storage location in the memory. It could be in the range from 1 to 19.
That was the last step in the initializing of M20. Figure 3.2 shows the initialization process in a glance. The M20 is now ready to receive messages and pass them to the PIC.
M20
PIC
Master PIC
M20
Startup
Startup
Ready
Yes
32
The end of the alert is determined by the termination character. As mentioned before, after loading the alert from the M20 its content is checked to ensure this is really a newmessage alert. If it passed the test the PIC sends an AT command ordering the message content of the received index from the M20. the used command is AT+CMGR.
AT+CMGR Command Format AT+CMGR=<index> Read SMS message The M20 terminal returns SMS message with location value <index>. Parameter <index> the index of the message storage location in the memory. It could be in the range from 1 to 19.
The response-type flag should be set to indicate that a message content is to be received at the moment. The PIC is now ready to get the ordered message from the M20. The SMS message is delivered from the M20 in the following format:
+CMGR: Parameters <number> <date> <time> <body> REC READ,<number>,?????-????,<date>,<time><body> The cellular phone number that sends the message. The message delivery data. The message delivery time. The message body.
In a similar manner, the content of the received string is scanned to check validity. The body content should coincide with the protocol rules specially set for this project purposes. This protocol is discussed in the next section of this chapter. Depending on the type of the message, the PIC runs its proper subroutine. In any step of the process, if an invalid character is detected the PIC starts special invalidity subroutines depending on the type of invalidity and terminates the whole operation by resetting the PIC. In addition, if -for any reason- the PIC function got frozen for longer than 40 seconds it automatically cancels the frozen task and resets itself. The message reading process is described again briefly in figure 3.3.
33
M20
PIC
Master PIC
M20
New Message
Main
interrupt
USART (M20)
Other
Check other
Yes
Delete Message
Reset parameters
No
No
Delete Message
Ready Again
The number to which the message is sent is either picked from a received message from the Central Office or either previously stored in the PIC as an emergency number. The message-type flag determines the body content of the message, whether it is a meter reading that has just been received or one of the message formats available in the PIC. The message types and their formats will be clarified in more detail in the protocol section of this chapter.
34
As the command format shows, after the telephone number is entered to the M20 a termination character is send. The M20 will reply to the PIC with a stream of characters ended by a space character that indicates the M20 readiness to receive the message content. For this reason, the PIC will wait an interrupt from the M20 and check for the space reception before it starts body writing. When this is done (i.e. the M20 response finishes), the PIC begins to send the body content characters to the M20 terminal. A (ctrl-Z) character sent from the PIC will inform the M20 that the body has ended and the PIC will send the load message to the desired receiver. The message-sending process is reviewed again in figure 3.4.
M20
PIC
Master PIC
M20
Ready
Main
Certain Process
Reset parameters
No
interrupt
Other
USART (M20)
Yes
Is it a space? Yes
Check other
Send Message
Send ctrl-Z
35
3.2
Starting Character
Ending Character
of all the above-format parts, the 1-digit Task Index should be presented in more detail. The possibilities of (Task Index) part of the protocol are shown in table 3.1, where the (NCN) column indicates an NCN-related task and (CCU) column indicates a CCU-related task. An Extra column tells if the task needs any additional values to be attached within the (Extra Data) part of the string.
Task Index 0 1 2 3 4 5 6 7 8 Task Description Check Operation (Check Link Status) Read Meters Accumulated Energy Read Power Factor Read Switch Status Connect/Disconnect Line Reset PIC Reset Slave PIC Change Security Code Change Emergency Number
Table 3.1: Task Index Description
NCN
CCU
Extra
As the table shows, three tasks would need extra data. The shapes of these information are descriped in table 3.2.
Task Index 4 7 8 Extra Data Description Switch On or Off Task Indicator New Security Code for the NCN New Emergency Mobile Telephone Number
Table 3.2: Extra Data Description
For tasks where data readings are aquired, the reply for successful tasks from the NCN to the Central Office should be in this form
36
This format is applicable for Accumulated Energy , Power Factor and Switch Status reading tasks (Task Index 1, 2 and 3). For the other tasks which include specific-action jobs, the response of a successful job should be as follows
@<CCU ID>F@
The F character means that a task related to the assigned CCU failed to be finished due to some problem. It is then a matter of the Central Office to take the proper action in order to solve that problem. It should be mentioned that to access the NCN itself, the "CCU ID" field is set to "00". In the same way, when the NCN replies on its tasks it sends the same previous ID.
In the Send Message actions of the table, the bold words are the content of the invalidity message which should be sent to the utility. It can be also noted that when we dont receive a valid mobile telephone number, such as the case when we receive invalid characters in the number or the whole string is invalid, we cant respond to the sender at all. Not only this, but also we cant even check wither the received message has been sent by an authorized system user or not.
3.2.3 An Example
Let us assume this scenario. A utilitys Central Office wanted to perform these tasks: 1. Read accumulated energy of the meter connected to CCU of ID 12 in the region of the NCN with security code ID1234. This NCN has a mobile telephone number +96277910803. 2. Check the status of the link with CCU 15 in the same previous region. 3. Reset the Slave PIC of the same previous NCN. The utility was able to get the meter reading successfully. However, due to a failure in CCU 15, it cant respond to the NCN calls. And due to a personal error, the system user inserted the security code as (CD1234) instead of (ID1234). The conversation between the Central Office and the NCN according to this scenario is illustrated in figure 3.5.
37
1
PIC CCU 12 PIC CCU 15
M20
M20
PIC
NCN (ID 1234) Central Office
PIC CCU 12
M20
M20
PIC
PIC CCU 15
Central Office
2
PIC CCU 12 PIC CCU 15
M20
M20
PIC
NCN (ID 1234) Central Office
?
PIC CCU 12 Something Wrong
M20
M20
PIC
PIC CCU 15 Cant Receive the Task!
Central Office
3
M20
M20
PIC
NCN (ID 1234) Central Office
M20
M20
PIC
NCN (ID 1234) Central Office
38
RF Link
When discussing the basic design to our problems system, the RF link was introduced as the economic solution to interface NCNs with the relevant CCUs in their regions. This chapter explores the RF link in more detail and the connection implementation between an NCN and its CCUs is also described.
4.1
M20
Serial
Serial
PIC
NCNs PIC
More than one solution can be realized to solve this problem. The solution we selected is simply to use another Slave PIC as a transponder between the Master PIC and the RF modules utilizing its free USART port in this job. This is surely not the optimal solution since there are special-purpose chips that can do this job in a relatively very cheaper cost. But we preferred not to give this point a lot of caring since we already know that there are other types of the PIC having two USART ports. This would completely eliminate our problem if we didnt plan our design on the PIC18C452 basis from the beginning.
Serial Data In (SDI) Serial Data Out (SDO) Serial Clock (SCK) Chip Select (CS)
The first two pins are the data input and output pins of the PIC. It is clear that the output of the Master should be connected to the input of the Slave and vice versa. The Serial Clock is the synchronization clock generated in the Master PIC and harmonizes the Slaves work proceeding with that of the Master. The Chip Select is a very useful feature for us, since
40
we can drive many Slaves by one Master. This pin shows its power when connecting an ADE7756 [4] and an NVR to the NCNs Master PIC through the SPI in addition to the Slave PIC. The previous four pins are not the only used to interface the Master PIC with the Slave PIC, since there are still four more pins used in each PIC in order to maximize the control of the Master on the system and consequently increase the system stability. These Pins are:
New Action Interrupt In (INT1) New Action Interrupter Rx-Data Blocking Slave Reset
The reason behind the two interrupt pins can be clarified easily if we fully digest the statement that the Slave PIC renders its Slavery role adroitly. The Master PIC can always wake up the Slave and send to it; however, the Slave PIC can never tell the Master anything unless it receives a license from the Master to do so. In formal words, the Master PIC selects the desired Slave through the CS pin; this directly starts to feed the Slave with Masters clock through the SCK pin. Then the Master can transfer data to the Slave at any time. When this happen, the Slave replies to the Master with the data stored in a special SPI register (SSPBUF). For more details on SPI operation in general you can refer to the PICs section in Chapter Two or to its datasheet in the attached Companion CD. The use of SPI in this part of the system is illustrated in the coming subsection of this Chapter How It Works. As mentioned, a third Rx-Data Blocking pin is used. The function of this pin is to stop the Slave PIC from passing the data received at the RF Rx to the Master PIC. This blocking is highly desired when data is sent through the NCNs RF Tx to avoid hearing echo case which may disturb the Master. The last Pin connection between Master and Slave PICs is the Slave Reset pin. This pin carries a command to the Slave PIC to reset itself when required. The ability to do this gives the system a bonus feature as a fully freezing-immune system. Figure 4.2 shows the basic connections between the Master and Slave PIC. The full schematics are provided in Appendix A.
PIC
Slave PIC
RF Module Tx
Rx Slav e 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2
PIC
Master PIC
M20
Tx Rx Master
CS
SCK
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 SCK 18 CS 19 CS 20
PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2
41
PIC
Slave PIC
PIC
Master PIC
Main
Main
Check other
Other
interrupt
INT1
No
No
Yes
Yes
PIC
Slave PIC Check other
Other
PIC
Master PIC
interrupt
USART
Main
Main
Yes
interrupt
INT1
Other
Check other
No
Return to Main
42
4.2
3.25 Volt
5 Volt
LM317
RF Tx Regulator
In GND
GND Vcc
The voltage level supplied by the regulator is determined using the formula
VOUT = 1.25 [ 1 + ( R2/R1 ) ]
Then using an R2 = 240 and R1 = 150 will lead to a VOUT value of 3.25 volts, which is acceptable.
Open-Collector Buffer
Using the design shown in figure 4.5 of the Open-Collector Buffer (47LS07), and benefiting from the already produced 3.25 voltages of the regulator circuit, the maximum output of the buffer will never exceed the supply voltage level (3.25 V).
43
+3.25 V
PIC Tx (0 and 5 V)
In GND
GND Vcc
74LS07
Transistor Circuit
In a similar manner of the previous approach, the transistor circuit shown in fig 4.5 and supplied by a Vcc= 3.25 volts will always bring out a maximum of less than 3.25 V-level signal.
VCC = +3 V
9.7 k V out Q2
Diode Series
Although it seems to be a trivial solution when compared to the other two solutions, it can prove itself as well-doing approach. Every diode in the series simply cuts about 0.7 volts from the PICs signal. As much we need to reduce the signal level, as much we add extra diodes to the series. Figure 4.6 shows this simple circuit. As our goal is not to complicate the system structure, we used the last solution in our system implementation. However the other two solutions were tested and worked properly.
From the PIC
1 2 3
En
FM-RTFQ1
EA
6 5 4
In GND
GND Vcc
0000FFFFh
44
4.3
FM1 1 2 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 En FM-RTFQ1 EA 6 5 4
In GND
GND Vcc
RF Tx
TX RX
PIC
RF Rx
The Data In and Out pins of the RF Tx and Rx, respectively, are connected to the Slave PIC of the NCN. In addition, the CCUs PIC and the NCNs Master PIC have control on their relevant RF transmitters Enable signals. This control is a must to solve two contrary problems; the first is that one transmitter at least must be enabled at any time; otherwise the RF receiver will keep detecting noise and delivering it to the system as a sort of data. This is a design limitation of the RF receiver, because a special-purpose IC called (TDA 5210) used in the receiver has the Carrier Detect feature which would enable the receiver to stay at sleep mode when no signal is broadcast from any transmitter. This is why we should always keep one transmitter, the NCNs transmitter, enabled to broadcast its carrier without data. As the RF receiver can never understand from a transmitter when another one, even if null, is enabled, the NCN must disable its transmitter when it waits data from a CCU, and only the transmitter of that desired CCU should be enabled.
1 2 3
45
4.4
RF Link Protocol
After the Master PIC of the NCN extracts the SMS message, it should reshape the task included in this message to a form that can be understood at the CCU side. For this reason, a simple RF-Link Protocol was developed to be respected in every conversation between the NCN and any of its CCUs through the RF channel. Any task alert sent from the NCN to the CCU must take the following format
2-digit ID for the CCU Requested to do a Task Extra Optional Data Needed in some Tasks
The information included in the format is exactly that received from the utility, but only those related to the CCU. When the called CCU receives the alert, it should reply to the NCN with the same received message added to it the acquired reading if any. For example if the meter at CCU number 12 is to be read, the NCN should send
@121@
The CCU will get the meter reading and send a message similar to the following to the NCN.
@121 000000000010C1F368B2@
A good indication of the systems stability is that if the CCU did not reply to the NCNs request within 40 second, this is considered a failure and the NCN replies to the Central Office with a failed-task report.
@12F@
46
After we have established a rigid base for data to be easily interchanged between the Central Office and any CCU in the system, we now move on to the process of gathering data for the Central Office and controlling different processes at the CCU; this is done with the help of some special ICs and circuitry that are interfaced with the PIC. Data collected for an electricity system ranges from the simple energy consumed by people to the 3rd harmonics of a 3-phase power line going into a factory. Here we introduce an example of collecting the consumed energy by a load, try to read its power factor and read the status of a switch at the CCU. Chapter 8 should give further ideas for more data to be collected (either using the same hardware available or by new means). Processes to control wirelessly are endless. It ranges from controlling a simple switch to flying an airplane. As an example, we will try to control a switch connected to a small light bulb on and off at the CCU site, the switch represents the power line that we need to control (connect/disconnect). This should simulate process controlling as a proof of concept for the credibility of the system.
5.1
Data Gathering
We will try to collect the energy consumed by an electrical load at the customer side. We will also try to gather other additional data (like the power factor and the status of a switch). The Analog ADE7756 plays the key role in providing most of the data at the CCU.
5.1.1
Almost all old electricity meters use coils and magnets to calculate the energy, and spin gears with numbers printed on them to give the reading. Such meters are still used until this day here in Jordan and in most of the Arab countries. Getting a digital microcontroller to interface such meters would require the need to convert mechanical energy into a digital stream of 1s and 0s (theoretically it is possible), but we need not to because there are new electricity meters that give us the ability to interface them digitally (ABB and other companies manufacture such meters); this way we can simply get the data at the CCU and deliver it to the Central Office. Since we dont have a meter that can be digitally interfaced, we will work with a very famous chip in this field: the ADE7756 from Analog Company [4]. This chip takes an electrical load (via its voltage and current) and calculates the consumed energy by that load. Refer back to Chapter 2 for brief description and information about the ADE7756 or refer back to the datasheets on the companion CD. As a reminder, the ADE7556 uses both the voltage and current inputs to digitally calculate the consumed energy by the load. This is simply done by first converting the voltage and current signals into digital signals. The average power is calculated by multiplying both signals and passing the output through a digital LPF to extract the DC content (average power); the output is then accumulated periodically at a very high speed (integrated) to calculate the energy.
0110010101
ADC Currnet
Instantaneous Power 0110010101
LPF
Average Power
Accumulate
Consumed Energy
ADC Voltage
48
The ADE7756 is considered a very cheap solution for the AMR system. The ADE7756 represents only a data source; this data source could be anything else (e.g. a data from a system other than the electricity system itself). The ADE7756 was used as a proof of concept.
5.1.2
The PIC18C452 [3] is the device that shall be connected to the ADE7756. The PIC interfaces the ADE7756 through the Serial Peripheral Interface (SPI). The specifications for the SPI used are extracted from the datasheet of the ADE7756, and the PIC should configure its SPI settings as so (please note that the PICs in the NCN and the CUU also interface the 93C56 EEPROM [7] via SPI, and the SPI settings are different from those used with the ADE7756, this forces the PIC to change its SPI settings each time it talks to either one of them). Communication between the PIC and the ADE7756 is made by requesting something then taking the response after that; e.g. when the PIC needs to know the consumed energy by the load; it sends 02h (Read AENEGY register) to the Communication register in the ADE7756 to indicate so. The ADE7756 then lets the PIC read (one byte at a time) the 40-bit consumed energy register AENERGY. Refer back to Chapter 2 or to the ADE7756 datasheets on the companion CD.
Master 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 SCK 18 CS 19 CS 20 PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 SDO 23 SDI 22 21 220V 1
SPI
ADE7756
PIC
DIN RESET DOUT DVDD SCLK AVDD CS V1P CLKOUT V1N CLKIN V2P IRQ V2N SAG AGND ZX REF CF DGND ADE7756
20K
10K
100K
Figure 5.2: The PIC is interfaced with the ADE7756 through SPI
One of the SPI settings that the PIC must properly set so that valid SPI communication is to be established is the Idle Clock Polarity; the datasheet of the ADE7756 specifies that the idle state of the clock of the serial communication (SCK) should be low (0V). This condition is met with the PIC by setting the SSPCON1<CKP> bit to 0. Other settings are set using this register and the SSPSTAT register. The ADE7756 is interfaced in both the NCN and the CCU. The chip-select signal is used in the SPI connection; this is because the chip select resets the ADE7756 serial interface and puts it in the communication mode. The chip-select signal for the ADE7756 is active low (while it is active high for the 93C56). Appendix A contains full schematics for the NCN and CCU.
4 93C56 DO DI CLK 3 2 1
M20
Tx Rx 220V 40 39 38 37 36 35 34 33 32 31 30 CS 29 28 27 26 25 24 SDO 23 SDI 22 21 1
RF Module Tx
Rx Slav e 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 SCK 18 CS 19 CS 20 Master
CS
CS
SCK
SDO SDI
PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2
DIN RESET DOUT DVDD SCLK AVDD CS V1P CLKOUT V1N CLKIN V2P IRQ V2N SAG AGND ZX REF CF DGND ADE7756
20K
10K
100K
Figure 5.3: Master PIC in the NCN Interfaces the ADE7756, the Slave PIC and the 93C56 Using SPI. Each device has its Own Chip Select Signal. There are Other Control Signals between the Master and the Slave not Shown
49
The NCN also uses SPI to interface the Slave PIC (to use its USART to communicate with the CCUs as explained in Chapter 2) alongside with the ADE7756 and the 93C56. A separate Chip Select signal is given to each device.
5.1.3
The final accumulated reading is just a null number that must be converted into a watthour reading. Tthis is done by multiplying it by a constant figure (We will name this constant the Energy Constant. It has the units of watt-hour/LSB). This energy constant is the output of the Calibrating process of the ADE7756; it is a process that determines what does a LSB in the AENERGY register equals as watt-hour energy. We will introduce the calibration process soon.
A.
The ADE7756's basic operation mentioned in the beginning is BASIC. There are still more steps and operations to go through to yield the final output. These steps need configurations and settings to be made, this is done through writing to some registers in the ADE7756 (mainly the MODE register). We will mention some of these registers and the values assigned to each.
MODE (16-bit): This register controls most of the settings (refer to chapter 2 for details); we will set it to zero (0000h). This setting does the following: select the output to be the active energy, the sampling rate to the maximum (CLKIN/128), enable HPF in channel 1 (to remove any DC offset errors), enable LPF2 after the multiplier (the result is the average power), and enable frequency output at CF. See the figure for more information.
15 0 14 0 13 0 12 0 11 0 10 0 9 0 8 0 7 0 6 0 5 0 4 0 3 0 2 0 1 0 0 0 ADDR: 06H DISHPF (ENABLE HPF IN CHANNEL 1) DISLPF2 (ENABLE LPF2 AFTER MULTIPLIER) DISCF (ENABLE FREQUENCY OUTPUT CF) DISSAG (ENABLE SAG OUTPUT) ASUSPEND (DON'T SUSPEND CH1 AND CH2 ADCs) TEMPSEL (STOP TEMPERATURE SENSING) SWRST (USED FOR SOFTWARE RESET) CMODE (USED IN CALIBRATION MODE)
TEST 1 (TEST MODE SELECTION SHOULD BE SET TO 0) WAVSEL 00 = LPF2 DTRT (WAVE FORM SAMPLES OUTPUT DATA RATE) 00 = 27.9kSPS (CLKIN/128) SWAP (DON'T SWAP CH1 AND CH2 ADCs) DISCH2 (DON'T SHORT THE ANALOG INPUTS ON CHANNEL 2) DISCH1 (DON'T SHORT THE ANALOG INPUTS ON CHANNEL 1)
SAGLVL (7-bit): Sag Voltage Level. This register determines at what peak signal level on channel2 (line voltage) the SAG pin will become active (set to 0). The signal must remain low for the number of cycles specified in the SAGCYC register before the SAG pin is pulled low. We set this register to zero or to any small value; this means that the SAG pin will only go low if the voltage level is zero or very small (i.e. no voltage or line failure).
50
SAGCYC (7-bit): Sag Line Cycle Register. This register specifies the number of half line cycles the signal on channel2 must be below SAGLVL before the SAG output is activated. We set this register to 06h, indicating that 6 half line cycles must happen before setting the SAG pin low at a SAG event. APOS (12-bit): Active Power Offset Register. This register contains a constant energy offset that will always be added to the accumulated energy in the AENERGY register, this register helps in correcting errors that cannot be corrected by any of the other errorcorrection registers (e.g. phase compensation, channel1 and 2 offsets). To calculate the value in this register is simple and direct; sixteen LSBs (APOS = 010h) written to the APOS register are equivalent to 1 LSB in the Waveform Sample register.
11 CURRENT CHANNEL APOS [11:0] 0
LPF2
23
WAVEFORM [23:0]
VOLTAGE CHANNEL
39
AENERGY[39:0]
OUTPUT LPF2
4 CLKIN
WAVEFORM REGISTER VALUES ARE ACCUMULATED (INTEGRATED) IN THE ACTIVE ENERGY REGISTER
TIME nT
There are still other registers to set. Examples are the CH1OS (channel 1 offset), CH2OS (channel 2 offset), APGAIN (active power gain) and other registers. Such registers depend on the calibration process mentioned ahead, this means that the values of such registers could change from one ADE7756 to another. All these registers are set by the connected PIC. Again, setting the registers is made by writing to the Communication register the address of the desired register to write to, then sending the value to that register. The following listing is part of an assembly code that shows how to set the MODE register to 0040h (software-reset the ADE7756).
; 0x86 ; CommReg ; ChipSelectADE ; SendComm ; 0x00 ; SendADE ; 0x40 ; SendADE ; ChipDeselectADE; Setting the MODE register to 1808 Save Chip Call Send 86h to the CommReg (it is a temp register in the PIC) select the ADE7756 the "Send Communication Register" subroutine 0040h to the ADE (2 bytes)
Assembly Code
Listing 5.1: Assembly Code for Setting the MODE register to 0040h
B.
Although the accumulated energy in the ADE7756 is put in the AENERGY register, we are reading the RSTENERGY register instead; this register is a copy of the AENERGY register. The difference is that the RSTENERGY will reset the accumulated energy reading to zero after each reading process. The RSTENERGY register can be simply read by writing 03h to the Communication register. We then keep accumulating this reading in a larger 80-bit register in the PIC. We will call this new 80-bit register the Total Accumulated Energy register (TAE).
51
At full load (inputs are at max range = 1V); the ADE7756 could take up to 5 seconds to fill the RSTENERGY 40-bit register (depending on the ADE7756 settings), this means that we should read the energy in this register before it is full and data is lost; this is done periodically by the connected PIC every predefined time elapse. We have set the PIC to interrupt every 2 seconds (using the Timer0 module). On each interrupt; the PIC will read the energy from the ADE7756 and accumulate the reading into the TAE register. The following workflow diagram shows part of the PICs operation when connected to the ADE7756.
ADE7756
PIC
Calculate Energy
Main
No
Comm. Reg?
Yes
Interrupt
Timer0 Interrupt Send 0x03 to Comm. Reg.
Other
Check Other
Figure 5.6: the PIC Accumulating the Energy from the ADE7756
Every 40 seconds, the PIC saves the TAE register in the 93C56 EEPROM (along with other data); this is done to insure no data is lost at a power down situation. At startup, the PIC loads this stored energy in the 93C56 and keeps accumulating the ADE7756 energy over this reading.
NVR
PIC
Main
Interrupt
Timer0 Interrupt Accumulate ADE7756 Energy
Other
Check Other
40 Sec Passed?
Figure 5.7: the PIC Stores the ATE Register in the 93C56 EEPROM Every 40 Seconds
The workflows shown here add to the whole software implementing the system in both the NCN and the CCU. Chapter 7 should contain workflows for the entire system. All software files used to program the PICs can be found on the companion CD.
C.
The last step in calculating the energy from the ADE7756 is to convert the value received from the TAE register into a more meaningful reading of watt-hour energy. This is
52
done by multiplying the output by the energy constant; it has the units of (watt-hour/LSB). The process of calibrating the ADE7756 will yield this energy constant. The process of calibrating the ADE7756 is simple; we apply a fixed load (known watthour load) at the inputs of the ADE7756 for a fixed period of time, then we read the accumulated energy from the PIC. This reading represents the watt-hour consumption of the load for that period. An example will illustrate.
Example: If we put a lamp bulb (energy = 60 watt-hour) at the inputs of the ADE7756, and after an hour we read the TAE register from the PIC and found it to be 000000000013B4BF8E26h, then the Energy Constant for that particular ADE7756 will be:
Example
Energy Constant = (Energy/TAE) = 60d/13B4BF8E26h = 7.0891122812e-10 watt-hour/LSB If (at normal operation) we find that the TAE register reads 0000000004B4ACE7AF32h, then the consumed energy can be found like this: Energy = TAE*(Energy Constant) = 4B4ACE7AF32h*7.0891122812e-10d= 3667.9361064661 watt-hour Listing 5.2: Calculating the Energy Constant, an Example
Although this calibration process seems easy, it still needs a programmed PIC with the human interface software to do it. This is why we have developed a calibration program that helps the user calibrate his ADE7756. The calibration software is very simple; it lets the user write to and read any register in the ADE7756 using a normal PC. The PC is connected to the PIC through the serial port (USART module in the PIC).The program also accumulates the energy from the ADE7756 every 2 seconds, relieving the user from manually doing so. The user only has to set the different registers of the ADE7756, and the final output will help calculate the energy constant. HyperTerminal can be used to calibrate the ADE7756. Just connect the PC to the PIC at a baud rate of 19200 bps. The process of writing any value to the ADE775d is like this:
Enter the 2 bytes you want to write to the ADE7756 register Enter W (Write) Enter the address of the register you want to write to, follow the table below
Add. 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K Registers Read after an (R) # bits Registers Written after a (W) WAVEFORM 24 bit Invalid (Read Only) AENERGY 40 bit Invalid (Read Only) RSTENERGY 40 bit Invalid (Read Only) STATUS 8 bit Invalid (Read Only) RSTATUS 8 bit Invalid (Read Only) MODE 16 bit MODE CFDIV 12 bit CFDIV CH1OS 6 bit CH1OS CH2OS 6 bit CH2OS GAIN 8 bit GAIN APGAIN 12 bit APGAIN PHCAL 6 bit PHCAL APOS 12 bit APOS ZXTOUT 12 bit ZXTOUT SAGCYC 8 bit SAGCYC IRQEN 8 bit IRQEN SAGLVL 8 bit SAGLVL TEMP 8 bit Invalid (Read Only) Users stored 2 bytes 16 bit Reset user bytes to 0000h TAE 80-bit Reset the TAE register Table 5.1: Calibration Program, Registers Addresses
53
Addresses J and K are not registers on the ADE7756, they are registers on the PIC. J is the 2 byte register the user stores his data in, and K is the 10 bytes TAE register. Any address entered outside the above range will be ignored. Please note that the calibration program is case sensitive. Example: if you want to set the MODE register to 1808h, just type 1808, W, 6. Example: if you want to read the SAGCYC register, just type R, F. The data going to the ADE7756 is right justified; this means that if you enter 1506, W, F. this will fill the SAGCYC register with the value 06h. The schematic diagram for the calibration hardware is shown in appendix A.
5.1.4
The power factor of the load is another type of data we will try to deliver to the Central Office. Power factor can be calculated in many different ways, one way is by using DSP. Since we can read the waveforms of the current and voltage channels from the ADE7756; we can do any mathematical process with this discreet data and find our power factor (we can also find the RMS values of the current and voltage, the reactive power and much more information about the line), but as this DSP seems easy to do, the PIC18C452 can't do it. The PIC18XXXX family is the newest family of MCUs from Microchip, and support for this family is not yet fully complete. Older MCU families (like the PIC17XXXX) have full support from Microchip. Support includes publishing libraries to be used with the MCU (like the math libraries we need). Our PIC18C452 doesn't have any library from any kind, and trying to build a toolbox such as the math library from scratch would be tedious and very hard. Yet, the power factor can still be found using the PIC and the ADE7756 with no real DSP involved. This is done by finding the phase difference between the current and voltage signals going into the ADE7756. We shall use a simple algorithm that scans for the zero crossing of both the current and the voltage. When the zero crossing of one channel is found; we start a counter that stops at the zero crossing of the other channel. The value in this counter represents the phase difference between the two channels. This counter is converted to a phase difference in degrees, and the cosine of this phase difference is calculated to be the power factor.
Start Counter Stop Counter
Current (Channel1)
Voltage (Channe2)
We can read the current and voltage signals from the ADE7756 using WAVEFORM register. The data source sampled in this register is selected by data bits 14 and 13 in the Mode Register (WAVSEL bits).
To read the current (channel1) waveform; set the WAVSEL bits to 10 To read the voltage (channel2) waveform; set the WAVSEL bits to 11
54
The WAVEFORM register is a 24-bit two's complement register; this means that the 24th bit determines whether the total value in the register is positive (0) or negative (1). This is how we scan for zero crossings in each signal; we just keep monitoring the last bit in the waveform. The scanning process here is not made as the scanning process for a new incoming message from the M20 (i.e. to store the whole data in a memory bank then scan it); this is because the number of samples to store here is very large and there is no enough memory space to save them all. Instead, we will do real time scanning for the samples; each sample (from each channel) will be scanned immediately after it is read.
5.1.5
This last data we are delivering is only for proving that the system can deliver any data available at the CCU. It is a simple user-controlled switch tied to the input of an I/O port of the PIC. We will read the switch status for the CCU units only. A similar switch is connected to the PIC in the NCN, but it functions as an alarm system that will automatically send a message using the Emergency Number stored in the 93C56. This switch represents any major parameter change the Central Office would like to know about ASAP (e.g. power down, low power factor, system manipulation, theft). The NCN will alert the Central Office once this switch is changed from off (logic 0) to on (logic 1). As for the connection of the switch with the PIC; we can't just use a simple Single-Pole Double-Throat (SPDT) switch, this is because the transient period will disturb the normal operation of the PIC. Instead, we will use a very simple way to gain a very stable switch. The following schematic explains.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RB3/CCP2 RA3/AN3/VREF+ RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
A B
Proving the validity of this switch is very simple, first assume the switch is at point (A), thus making the final input to the PIC a 0. If the switch is to be moved to (B); then at the transition point (C) the 0 signal at the PIC side will still be latched due to the feedback of one inverter to the other. By reaching point (B), the circuit will force the new signal to be a 1. This simple solution solves the problem of transients due to wires not connected to anything.
5.2
Process Controlling
An AMR system could be the part responsible for the physical disconnection of the power line if someone didn't pay his bills. This is a simple example for a process the Central Office should be able to control. We can think of other processes like sending some sort of an indication to the customer that he/she is absorbing to much current or a bill is overdue, the number of ideas is endless. For the sake of demonstration; we will wirelessly control a switch connected to a regular DC lamp bulb. The switch is a transistor-based switch were a CMOS signal from an I/O port of the PIC is going to control the switching. See the figure.
55
+5V
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
LAMP 1
2.7K
C945 2N3053
This DC lamp needs about 300 mA of current to lighten, thus a special transistor (2N3053) is used. This transistor handles large currents than the usual ones. Another regular BJT transistor is used as the driving base for the above transistor, thus forming a Darlington pair. The diodes are used because the lamp operates at a lower voltage level than the 5V. The Central Office controls the switch wirelessly (as everything else), but when a power failure happens and no power supply is feeding the digital circuits, the status of this switch is saved in the 93C56, and in the next startup the switch will be set to the last state the Central Office desired. As simple this switch-control process seems; it forms the basic idea for controlling a state of an AC line at the customer side.
56
Central Office
6.1
6.2
System Overview
We have developed a very simple software program to simulate the operation of the Central Office; no database connection was made because this was developed for the sake of demonstration only. The development of the software was made with Visual Studio.NET and the targeted platform was Windows XP, this is why all screen shots in this chapter are taken from a Windows XP environment.
Figure 6.1: Central Office
The software has the basic features of sending and receiving all kinds of tasks, it also helps to setup the different parameters needed for the system to operate correctly (like the COM port settings and the mobile settings), plus debugging errors faced (especially when trying to link with the GSM device). Below is a snapshot of the main page in the Central Office, we will explain every section (feature) of the software ahead.
58
Since we have only one M20 device; we needed another GSM device to be interfaced with the Central Office in order to access the GSM network and establish a connection with the NCN units. The Nokia 8210 mobile phone was used to accomplish this. Nokia 8210 is not a GSM modem (it cannot be accessed directly with regular AT commands). An interpreting medium was needed to establish the connection with the mobile. This problem was solved using the Nokia Data Suite; this utility installs a virtual modem (with a new COM Port number) on the Host Computer. This virtual modem is the interpreting medium used to communicate with the Nokia 8210 (Connected to a physical port).
Virtual COM Physical COM
Central Office
AT Commands
Nokia 8210
Figure 6.2: Nokia Data Suite is used to Communicate with the Nokia 8210
With the Data Suite; the 8210 can be accessed using special AT commands (which are very similar to those used with the M20, this is because AT commands are standardized).
6.3
System Walkthrough
The following figure explores the main areas of the IDE for the Central Office and gives comments on them.
Menu Bar, Use it to exit the program or to see the Help About User Control Area, here the user performs actions and sees results
Navigation Tabs, use these tabs to navigate other pages in the Central Office, these pages contain most of the system features
Port Status, this shows the number of port opened, or indicates if no port is opened
We will introduce the main features of the Central Office system as walkthrough steps. We shall introduce the following features:
Initializing the Software Sending Tasks Receiving Tasks Debugging and Troubleshooting
59
Figure 6.4: Initializing the Central Office from the Settings Tab
1. Connect the Nokia 8210 to any COM port on the computer 2. Launch the Central Office 3. Select the tab
4. in the COM Port Settings, select the COM port number (which is the number of the virtual COM port for the Nokia Data Suite) 5. Click the button (it will be enabled once a COM port number is selected)
*If the COM port is opened (the status bar indicates so), all controls in the system will be enabled. Otherwise, a message pops showing that the desired port can't be opened.
6. To initialize the Nokia 8210; in the Mobile Settings click the button, this will software-initialize the Nokia 8210 (and the Nokia Data Suite) by sending specific AT commands in a row to the mobile (this is similar to initializing the M20 with the PIC). Please note that not clicking this button will result in invalid messages read from the mobile. The system is now partially initialized, but there are still more steps to go 7. The Task Reply Number field must be filled with a valid mobile number (this is the number to which the NCN will reply) 8. the Default Message Index combo box determines the index of the incoming message to read (the Nokia 8210 doesn't give indication for new messages arrival like the M20, so the user has to manually click a "Read Task" button when a message arrives. This scenario was faced because of the use of the Nokia 8210 and it will not happen if an M20 was used) Now the Central Office is fully initialized and ready to Send Tasks (our next section)
60
The Send Task group box holds all task information that must be sent to an NCN (these information makeup the SMS that will be sent to the NCN). All tasks to send are sent from here. 1. Specify the NCN Security Code in its respective field. It is a 6-digit code 2. Specify the NCN Mobile Number in its respective field; it is the number of the M20 at the NCN side. It is a numeric field of any length 3. Specify the CCU ID in its respective field; it is the ID for the specific CCU the user wishes to access. It is a 2-digit ID 4. From the Required Task combo box, select the required task to perform. Each selected task opens its own specific task box for the user (this task box contains either notes about the task or further information needed to perform the task). figure 6.6 shows all tasks available along with their task boxes 5. After selecting the required task and specifying any further information needed by that task (if any); the task is now ready to be sent to the targeted NCN. Sending the task is made by simply clicking the Send Task button (you won't miss it)
Please note that all controls in the Central Office have validation criteria assigned to them, e.g. the user can't input 07788G4717 in the NCN Mobile Number field, the software will not allow him to send the task unless the number field is corrected and filled with numbers only. This applies for most of the fields in the system.
61
As an example; the task information shown in figure 6.5 will send the following SMS to the M20 with mobile number 077884717:
Reply Number Specified in the Settings Tab 2-digit CCU ID Connect Line
To view this actual sent message; the software allows the user to see all transactions made between the Central Office software and the Nokia 8210. All these transactions can be tab under the Data Sent to the Mobile group box (we will see this viewed in the feature in the Debugging and Troubleshooting section).
When the Nokia 8210 indicates the arrival of a new message (i.e. to ring and the user hears it, not to send an AT statement); the user clicks the "Read Task" button. The Central Office sends the appropriate AT command to read the message (with the Default Message Index specified by the user). If a message is successfully read, the Central Office begins
62
scanning the message. The output of this scanning process is displayed in the Receive Tasks group box. The figure below shows a valid response for the task sent in the previous section.
The Received Task Details shows the details of the message received; it shows the CCU ID, Task Index and the Extra Data (if any) received from the NCN unit. The example shown in the figure above indicates that CCU 55 has received the task of switching on the line and it did perform this task. The Received Task Details also indicates an unrecognized received message or a nomessage-received situation. This may happen if either the specified Default Message Index is wrong or if the mobile is not properly connected to the COM port. The following will be displayed to the user:
The message analysis procedure is simple and straightforward. In a real system scenario; the output of this message analysis process should drive other data-based subroutines and procedures to maintain the CCUs' data and transactions.
63
All valid analyzed tasks are stored in a log file for demonstration only. This log file can be viewed from the tab.
Figure 6.10: The Debug View Helps Determine Errors in the System
64
If it helps to overtake the communication between the Central Office and the mobile to solve errors, then the user can use the "Send Custom AT Command" feature in the Mobile Setting group box. This lets the user to force specific AT commands to be sent to the mobile.
The button is used to empty unwanted messages from the mobile. It uses the message index specified by the combo box to delete the specified message. Emptying unwanted messages avoids errors due to messages waiting in queues to arrive to the mobile.
65
As we have just finished exploring the AMR management software and its cool user interface in the previous chapter, we are now ready to reorganize our knowledge on the different stages of the system studied through this report chapters as individual subsystems, and start looking to these subsystems as a one full system that functions to achieve the goal it is designed for. The first part of the chapter combines the three stages of the system, the Central Office, the Network Control Node (NCN) and the Cell Control Unit (CCU) together and presents a brief review of the main features and functions of every stage, but this time from the whole system point of view. The last section simulates a real case of the system operation in an example that would make the reader more familiar with the Fixed-Network AMR technology in general, and with our own implementation of this technology-using system in particular.
7.1
System Startup
The whole system startup is a fundamental part of its operation as a step that if made carefully and accurately will ensure a stable behaviour of the system all the time. The startup procedure should take place at the first time the system is brought to job. Moreover, every system stage must be ready to perform its own startup procedure on any component that seems to fail or restart itself completely when needed but also ensure that it could resynchronize its operation with the whole system after every startup.
Variables and constants defining Indication flags resetting I/O ports setup SPI setup USART setup Timer setup and resetting Interrupts setup Read previous state from the 93C56 ADE7756 setup and resetting (if applicable) M20 setup
The full description of every step was fulfilled in earlier chapters and is not part of our discussion as we only summarize the main ideas in this chapter.
67
7.2
System Operation
After startup; The NCNs, CCUs and the Central Office software are all waiting the system-user command to perform the task in request. Not only this, but also the system may be brought to work by an emergency alert sent by the NCNs. Regardless of the task type, the system user should start with inserting the mobile telephone number and the Security Code of the NCN to be called and the CCU number within the chosen NCN region. Then the desired task is selected and any extra data needed to accomplish that task is fed to the system. A Send Task button click will build the SMS text message that contains all the information above. Only one NCNs M20 terminal can receive the utilitys sent message. This will wakeup the Master PIC to read the message, extract it, check its validity and determine whether the task held by the massage is an NCN or CCU-based task; therefore there are two routes to follow here.
When an NCN-based task is received, the Master PIC performs it by itself. This includes the NCN Security Code updating, Emergency Contact Number updating, resetting the Master or Slave PICs. In addition, the Master PIC may be controlling its own meters cell, so in this case if any command concerns any of these meters, the Master PIC will do the job as if it is a CCU PIC. After the task is done, the Master PIC enforces the M20 to reply to the Central Office either with the data acquired in the system-user message if any, or just with a message confirming that the task has been successfully finished. When a CCU-based task is received, the Master PIC converts the task from the GSMLink protocol format to the RF-Link protocol format. This format, as previously illustrated, contains only the CCU number and the task index with any additional information needed by the CCU to perform the task. The rebuilt task is then passed to the Slave PIC of the NCN which will broadcast the new-task alert through its RF transmitter to all CCUs in the range. Activating the RF transmission from the NCN automatically disables the Slave-PIC response to any data received at the RF receiver, and once transmission is completed the NCNs RF transmitter is disabled. The technical reasoning of these two steps is fully discussed in Chapter 4. Although all CCUs RF receivers will detect the new-task alert sent by their mother NCN; only one CCU, whose number is carried in the alert, is able to execute the requested task. This task may be a CCU-link check, Total Accumulated Energy reading, power-factor reading, power-line status check and power-line switching on or off. Similar to the NCN operation, if a data-reading task is performed; the CCU number, the task index and the read data are sent to the NCN through the enabled-on-request RF transmitter of the CCU. Otherwise only a confirmation of task accomplishment is sent to the NCN. The NCNs RF receiver will forward the CCU message to the Slave PIC which passes it again to the Master PIC. The latter reshapes the message to be consistent with the GSM-Link protocol format, and finally the M20 terminal will send the message to the number received within the utilitys task message content. At the utility, the Central Office is sensitive for new messages. It reads and extracts these messages and runs the proper operation depending on the data received from the NCNs.
In emergency cases at the NCN, such as power-down, the NCN itself alerts the utility on this emergency. This is done through an SMS message sent by the M20 terminal. Figure 7.1 summarizes the different system operation cases. The example presented in the next section is to clarify this operation.
68
PIC
Master PIC NVR
To Main
Main
Store TAE Register in 93C56 EEPROM Yes
No
PIC
INT1 interrupt U SART Send Dummy Data to R ead Slave Data Timer0
40 Sec Passed?
Slave PIC
INT1
interrupt
USART
No
Yes
New Message
Ne ed to send m essage
Receive Data from the Mater PIC Send Message (i) Body
No
SPI Data?
Yes
Delete Message
Ready Again
Send Message
69
Disable RF Transmitter
New Task
PIC
CCU PIC
Timer0
Interrupt
Main
USART
Enable RF Transmitter
To Main
No
Calculate Energy
ADE7756
Due to any kind of error, the desired task may not be achieved. It could be a CentralOffice user error or a hardware failure at any system stage. In such cases, the NCN will respond to the Utility with an error report that indicates the failed task or the invalidity type in the Central-Office message. In addition, if any error causes the NCN or the CCU to freeze its operation for more than 40 seconds, it automatically resets the system and starts from the beginning again. The NCN or CCU may be forced to shut down due to low-power situations and restart themselves when power is supplied again. In either cases of startup, no fear of losing data should take place, since the EEPROM chip connected to every PIC of the system is capable of storing the PICs memory content every 40 seconds. This feature enables the PIC to reload its memory at startup.
No
Comm. Reg?
Yes
NVR
40 Sec Passed?
Yes
70
7.3
71
@151@
AT+CMGS=077910803" @077884717 ID1234 151@ Cellular Base Station M20 M20 Master Slave
RF Module
PIC
PIC
RF Module
PIC PIC
ADE7756
Nokia 8210
NCN ID1234
CCU 15
@151 00000037F2ED24B56B54@
PIC PIC
ADE7756
Nokia 8210
NCN ID1234
CCU 15
72
Conclusion
We have chosen to implement the Fixed-Network AMR system because it seemed the best solution for the problem of wireless electricity metering. We tried to give as much as possible to open an eye on the endless capabilities of such system.
8.1
Work Done
Most of what was planned in Chapter 1 has been done. An automatic meter reading system utilizing the GSM network and a custom RF solution along with the data acquiring tools, storage devices, process-controlling equipment and software was designed and tested for the simple reason of demonstration. Data is interchanged between different sections of the system; a Central Office wirelessly communicates with a network of NCNs. These NCNs extend the capacity of the system by controlling other sub-networks of CCUs. Each CCU is equipped with data acquiring tools used to gather the customer's information (e.g. consumption, line status) and other process-controlling tools (e.g. line switching). Thus the CCU is the hand of the electrical utility at the customer side. The NCN interfaces the Central Office with the CCUs; this is done by reshaping the SMS-formatted data from the Central Office to a new format sent through the RF to the CCU and vice versa.
8.2
Problems Faced
As much the previous chapters gave an idea of the simplicity of the system, as many major problems were faced (and solved). These problems were:
Need another USART Module: The Master PIC in the NCN unit needed to interface with two devices (the M20 and the RF module) through the USART. However, the PIC18C452 used has only one USART module. This lead us to use another PIC (through SPI) and use its USART as the second port to which the RF modules where connected. This usage wasn't easy to make as it sounds to be, since too many control lines and interrupts were used. This issue was covered in Chapter 3. RF Synchronization: The RF receiver used had a problem of that it can't operate properly unless a carrier signal (from the transmitter) is detected. But if no carrier is detected; the receiver will take noise entering its circuit as valid data and output it to the PIC. This was due to bad design in the RF receiver by not implementing a CarrierDetect signal. We have overcome this problem enforcing a single transmitter to always enable its carrier signal, and because there were many transmitters in the system; software-controlled synchronization was made to ensure both data exchangeability and receiver stability. Software Management: The work flowchart for the Master PIC in the NCN unit was full of interrupts and interconnected branches of software modules. Developing such a complex structure was hard especially because Assembly language was used. However, even if the development language was a higher-level language (e.g. C) and hence easier to manage; the size of the final hex dump file could be larger and could not fit the PIC's memory space (we are already using 2/3 the PIC's memory).
74
8.3
Further Suggestions
We have introduced a basic design of a Fixed-Network AMR system. Yet there are more ideas and suggestions that can be integrated within this design.
RECHARGEABLE BATTERY
75
References
References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] Automatic Meter Reading Association, www.amra.org Itron Company, www.itron.com, and other resources Microchip PIC18C452 datasheets on the companion CD, www.microchip.com Analog ADE7756 datasheets on the companion CD, www.analog.com Siemens M20 Terminal datasheets on the companion CD, www.siemens.com RF Solutions RTFQ1/RRFQ1 datasheets on the companion CD, www.rfsolutions.co.uk Fairchild 93C56 datasheets on the companion CD, www.fairchildsemi.com DS14C232 datasheets on the companion CD, www.national.com Automatic Remote Meter Reading, graduation project (2002) by Camelia A. Najjar and Salam M. Zalloum
77
Appendix A
Tx
+5 V LM317 3 VIN FM-RRFQ1 Vcc GND Din GND 7 11 12 13 14 15 GND NC NC Dout PD 100 uF 150 2 3 In GND 100 uF 100 uF GND Vcc 240 5 4 1 2 3 Slav ePIC 300 LED 300 LED 100 VCC 0.1 uF 100 uF
CS 93C56
Rx
+3.25 V 2 FM4
05
05
05
+5 V
VOUT
1 ADJ 1 En EA FM-RTFQ1 6
93C56
DO
DI
CLK
CS
2.7K
C945
100
+5V
2N3053
Enable Tx
MasterPIC
3.6864 Mhz
SDO SDI Disable Receive to Salve Interrupt1 Reset Slave
20 pF
20 pF
OFF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
CS Slave CS ADE7756 SCK
PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
ON
M20
1 uF + 1 uF +
SIEMENSE
Tx +
2 1 uF 16 VCC TC232 +
Rx
GND
Antenna
VCC
15
1 uF 1 uF
33 pF
33 pF
3.6864 Mhz
20 19 18 17 16 15 14 13 12 11
DIN RESET DOUT DVDD SCLK AVDD CS V1P CLKOUT V1N CLKIN V2P V2N IRQ SAG AGND ZX REF CF DGND
1 2 3 4 5 6 7 8 9 10
79
Tx
Rx
+5 V +3.25 V LM317 3 1 VIN ADJ VOUT 2 100 uF 150 1 2 3 En FM-RTFQ1 EA 6 1 2 3 5 4 7 FM4 FM-RRFQ1 Vcc GND Din GND GND NC NC Dout PD 11 12 13 14 15 05 05 05 +5 V
+5V 240
In GND
GND Vcc
100 uF
100 uF
ChildPIC LAMP 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
CS 93C56
Enable Tx
100
3.6864 Mhz
SCK
PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RB0/INT0 RE0/RD/AN5 RE1/WR/AN6 VDD VSS RE2/CS/AN7 VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2
300
LED
20 pF
20 pF
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
A B
DI CLK CS 93C56
DO
CS ADE7756
220V 1 4.7 uF U2 ADE7756 20 19 18 17 16 15 14 13 12 11 DIN RESET DOUT DVDD SCLK AVDD CS V1P CLKOUT V1N CLKIN V2P IRQ V2N SAG AGND ZX REF CF DGND 1 2 3 4 5 6 7 8 9 10 10K 220/12 VCC 20K
3.6864 Mhz 33 pF 33 pF
10K
300
100K
VCC
80
3.6864 Mhz
U2 ADE7756
20 pF
20 pF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
PIC18C425 MCLR/Vpp RB7 RA0/AN0 RB6 RA1/AN1 RB5 RA2/AN2/VREFRB4 RA3/AN3/VREF+ RB3/CCP2 RA4/T0CKI RB2/INT2 RA5/AN4/SS/LVDIN RB1/INT1 RE0/RD/AN5 RB0/INT0 RE1/WR/AN6 VDD RE2/CS/AN7 VSS VDD RD7/PSP7 VSS RD6/PSP6 OSC1/CLKI RD5/PSP5 OSC2/CLKO/RA6 RD4/PSP4 RC0/T1OSO/T1CKI RC7/RX/DT RC1/T1OSI/CCP2 RC6/TX/CK RC2/CCP1 RC5/SDO RC3/SCK/SCL RC4/SDI/SDA RD0/PSP0 RD3/PSP3 RD1/PSP1 RD2/PSP2 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
3.6864 Mhz 33 pF 33 pF
20 19 18 17 16 15 14 13 12 11 DIN RESET DOUT DVDD SCLK AVDD CS V1P CLKOUT V1N CLKIN V2P IRQ V2N SAG AGND ZX REF CF DGND
1 2 3 4 5 6 7 8 9 10
10K
100K
1 uF +
1 uF + 1 uF 16 VCC TC232 + +
VCC
PC Rx PC Tx
VCC
15
1 uF 1 uF
1 6 2 7 3 8 4 9 5
81