fixed-network automatic meter reading (amr) system
DESCRIPTION
Graduation Project by Ramadan Abu Ghosh and Akram Awad.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 designthat 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 theGSM network and a custom RF solution. Different hardware modules areintroduced 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 maybe 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 micro controllers can help in gathering more data and control further processes.TRANSCRIPT
To my father, mother, sisters and brother
To someone who taught me to believe in dreams Akram
To my beloved family and true friends, Ramadan
Fixed-Network
Automatic Meter Reading(AMR) System
Preface
II
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.
Akram Jamal Awad Ramadan Tyseer Abu Ghosh
III
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.
Table of Contents
V
Preface I
Table of Contents IV
Ch 1: Introduction 1 1.1 Why Distributed Electrical Energy? 2 1.2 Why AMR? 3 1.3 Problem and Solution 6
1.3.1 Problem Statement 6 1.3.2 Solution Approach 6
1.4 Glossary 8 1.5 Symbols Convention 9 1.6 Report Outline 9
Ch 2: System Infrastructure 10 2.1 Microchip PIC18C452 11
2.1.1 Interrupts 12 2.1.2 I/O Ports 13 2.1.3 Addressable USART 13 2.1.4 Master Synchronous Serial Port (MSSP) 15 2.1.5 Timer0 16
2.2 Siemens M20 Terminal 18 2.2.1 AT Commands 18 2.2.2 M20 Interface 19 2.2.3 SMS with the M20 19
2.3 RF Modules 21 2.3.1 FM-RTFQ1-433 21 2.3.2 FM-RTFQ1-433 22
2.4 Analog ADE7756 23 2.4.1 Basic Operation 23 2.4.2 Adapting the Input Signals 24 2.4.3 Communicating with the ADE7756 24 2.4.4 Special Features 25
2.5 93C56, Serial EEPROM 27 2.5.1 Using the 93C56 EEPROM 27 2.5.2 Adapting Data to and from the 93C56 28
2.6 Supplementary Hardware 29 2.6.1 Line Driver (MAX232) 29 2.6.2 Voltage Regulator (LM317) 29 2.6.3 Open Collector Buffer 29
Ch 3: GSM Link 30 3.1 The PIC and the M20 31
3.1.1 Hardware Interface 31 3.1.2 AT Command Interface 31
3.2 GSM Link Protocol 36 3.2.1 Protocol Main Rules 36 3.2.2 Invalidity Reports 37 3.2.3 An Example 37
VI
Ch 4: RF Link 39 4.1 Need Another USART Module 40
4.1.1 The Slave PIC 40 4.1.2 The Master PIC and the Slave PIC 40 4.1.3 How It Works 42
4.2 Adapting the RF Transmitter 43 4.2.1 Power Supply 43 4.2.2 Input Data Level 43 4.2.3 Transmitter's Phased Locked Loop (PLL) 44
4.3 The PIC and the RF Modules 45 4.3.1 Hardware Interface 45 4.3.2 How It Works 45
4.4 RF Link Protocol 46
Ch 5: Data Gathering & Process Controlling 47 5.1 Data Gathering 48
5.5.1 Calculate Digitally with the ADE7756 48 5.5.2 The PIC18C452 and the ADE7756 49 5.5.3 Calculating the Consumed Energy 50 5.5.4 Calculating the Power Factor 54 5.5.5 Reading the Status of a Switch 55
5.2 Process Controlling 55
Ch 6: Central Office 57 6.1 What is a Central Office? 58 6.2 System Overview 58
6.3 System Walkthrough 59 6.3.1 Initializing the Software 60 6.3.2 Sending Tasks 61 6.3.3 Receiving Tasks 62 6.3.4 Debugging and Troubleshooting 64
Ch 7: Total System Implementation 66 7.1 System Startup 67
7.1.1 NCN Startup 67
7.1.2 CCU Startup 67 7.1.3 Central Office Startup 67
7.2 System Operation 68 7.3 The System Through an Example 71
Ch 8: Conclusion 73 8.1 Work Done 74 8.2 Problems Faced 74
8.3 Further Suggestions 75
References 76
Appendix A 78 A.1 NCN Schematic Diagram 79
A.2 CCU Schematic Diagram 80 A.3 ADE7756 Calibration Schematic Diagram 81
Introduction
2
1.1 Why Distributed Electrical Energy?
Since its "discovery", electricity has been always one of the fundamental requirements for any modern civilization and its development. It is now at the heart of any property, whether it is residential, commercial or industrial. Thinking for a while, we can imagine how deep electricity goes through our lives. Factories, mills, laboratories, traffic lights, televisions, PCs and cell phones are just few examples on the present situation of Electricity Empire.
For many decades, Studies in the field of electrical energy used to concentrate on
electricity generation, power transmission methods, transmission networks, line losses, etc… Nevertheless, in all generations of electrical power technologies no significant changes in electrical energy meters were remarked. It used to be the very basic and traditional meter either in its shape or functionality, and it had nothing to do as a part of the system except electrical energy consumption calculation.
But the scene turned far different in the last few years. Metering technology has
advanced wide steps to achieve the so called (new age of metering), which made benefit from every possible technology. Latest models of electrical meters utilize the advantages of modern communication systems, data transfer techniques and circuitry integration technologies. Therefore, many new functions were added to the electrical meter and many other are not farther than a single IC addition. All such advances bring the electrical energy meter much nearer to its goal, not only to calculate energy consumption but also to be able to track the quality of electricity and have full system control at the customer side.
But, are these technologies limited for electrical energy metering purposes only?
Fortunately, the answer is No! The electrical energy can be considered as one of the extremely difficult quantities to be measured since it is a combination of two "invisible" quantities, voltage and current. Approving on this statement, it will be clear to realize that once a technology works properly for electrical energy metering purposes, the system can be modified or even simplified to match other similar purposes such as water or gas consumption metering.
3
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 reader’s 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
A brief of every method is given hereby.
Electronic Meter Reading (EMR) This method only differs from the recording book method in that readings are entered
directly through a keyboard to a mini-computer where data can be loaded easily to the system’s main server at the utility office.
Remote Meter Reading (RMR)
A typical hand-held device with an optical-sensing or infra-red port is used here to automatically read and store the meter reading once the reader holds his device and directs its port to the meter side. In this method the probability of human error in recording the readings is effectively reduced.
Off-site Meter Reading (OMR)
Unlike the previous illustrated systems, this is the first step in migration to the AMR technology. It consists of a Portable Radio Network installed in handheld devices. In the other side, a transmitter, or a transceiver, is installed in the meter. The handheld device will then receive the meter reading while walking or slowly driving by the reading route. Although there is no need in this method to visit the meter location itself, it is still mandatory that the meter area is personally visited by the reader. This is mainly because the wireless communication between the meter and hand-held device is of the short-range and minimum-power type due to size limitations of both devices, as well as the highly-lossy medium of the communication channel by nature (buildings, trees, metal gates, etc…).
Mobile AMR
The only human effort in meter reading is the driver’s effort in this method. A special-purpose 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
4
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)
CCU(Cell Control Unit)
NCN(Network Control Node)
Central Office
Electricity Meters
Cell
Figure 1.1: Fixed-Network AMR System Structure
The system’s network components include: • Cell Control Unit (CCU) • Network Control Node (NCN) • Utility’s 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 utility’s 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
5
• 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.
6
1.3 Problem and Solution
1.3.1 Problem Statement 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 utility’s 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 utility’s 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.
ADE7756
ADE7756
PIC PIC
M20
ADE7756 ADE7756
M20
Database
CellNCN
Central Office
NVRNVR
PIC
Microcontroller
ADE7756
Digital Meter
M20
GSM Modem RF Module Host Processor
NVR
93C56EEPROM
Figure 1.2: Solution System Block Diagram 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
7
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 utility’s 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 SMS-message form and sent again to the Host Computer.
8
1.4 Glossary
The following table describes some technical terms that are used in this report for clarification.
Term Description
ADE7756 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
AMR Automatic Meter Reading
CCU 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
Cell The CCU and meters connected to it
Central Office The utility office that contains the Host Computer and any other supplementary devices
Line Driver The MAX232 low-power +5 TIA/EIA-232 dual driver/ receiver. It isused between M20 and the PIC
Host Computer The mainframe computer at the utility that controls the system operations
M20 The Siemens M20 Terminal which is the GSM modem of the system
NCN 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
NVR The 93C56 non-volatile EEPROM chip used as a storage device for the NCN and the CCU.
PIC The PIC18C452 high-performance microcontroller produced by Microchip and works as the heart of every system part
Region The group of CCUs covered by one NCN, with the NCN itself
RF Rx The FM RRFQ1-433 Radio-Frequency FM receiver working at 433 MHz. It is a production of RF Solutions
RF Tx The FM RTFQ1-433 Radio-Frequency FM transmitter working at 433 MHz. It is also produced by RF Solutions
SMS Short Messaging Service
SPI 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
USART 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
9
1.5 Symbols Convention The following symbols are used throughout this report to present the system
components.
ADE7756
ADE7756 RF Module
MAX232
RS232/TTLLine Driver
PIC
PIC18C452 Electrical LoadHost Computer
M20
M20
NVR
93C56EEPROM
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 system’s 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
11
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.
R
B7R
B6R
B5R
B4R
B3/C
CP2
RB2
/INT2
RB1
/INT1
RB0
/INT0
V DD
VSS
RD
7/PS
P7R
D6/
PSP6
RD
5/PS
P5R
D4/
PSP4
RC
7/R
X/D
TR
C6/
TX/C
KR
C5/
SDO
RC
4/SD
I/SD
AR
D3/
PSP3
RD
2/PS
P2
MC
LR/V
PP
RA0
/AN
0R
A1/A
N1
RA2
/AN
2/V R
EF-
RA3
/AN
3/VR
EF+
RA4
/T0C
KIR
A5/
AN
4/S
S /LV
DIN
RE0
/RD
/AN
5R
E1/W
R/A
N6
RE2
/CS/
AN7
V DD
VSS
OSC
1/C
LKI
OSC
2/C
LKO
/RA6
RC
0/T1
OSO
/T1C
KIR
C1/
T1O
SI/C
CP2
RC
2/C
CP1
RC
3/SC
K/SC
LR
D0/
PSP0
RD
1/PS
P1
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
PIC18C452
Figure 2.1: Pin Diagram for the Microchip PIC18C452
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.
* 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
12
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.
Figure 2.2: Microchip MPLAB IDE
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 interrupt-driven 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.
13
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 pin’s 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.
14
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 USART’s 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.
x64 Baud Rate CLK
SPBRG
Baud Rate Genera
USART RECEIVE BLOCK DIAGRAM
tor
RC7/RX/DT
Pin Bufferand Control
SPEN
DataRecovery
CREN
RSR RegisterMSb LSb
RCREG Register
FIFO
Interrupt RCIF
RCIE
Data Bus
8
64
16or
STOP START7 1 0
USART TRANSMIT BLOCK DIAGRAM
TXIFTXIE
Interrupt
TXEN Baud Rate CLK
SPBRG
Baud Rate Generator
MSb LSb
Data Bus
TXREG Register
TSR Register
(7) 0
TRMT SPEN
RC6/TX/CK
Pin Bufferand Control
8
Figure 2.3: USART Transmit and Receive Block Diagrams
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
15
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 Master Synchronous Serial Port (MSSP)
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
• Inter-Integrated Circuit (I2C): This is a two wire communication 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 master-
slave 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)
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
Figure 2.4: SPI Block Diagram
Read Write
InternalData Bus
SSPSR reg
SSPBUF reg
SSPM3:SSPM0
bit0 ShiftClock
SS ControlEnable
EdgeSelect
Clock Select
TMR2 output
TOSCPrescaler4, 16, 64
2EdgeSelect
2
4
Data to TX/RX in SSPSRTRIS bit
2SMP:CKE
SDI
SDO
SS
SCK
( )
16
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:
• FOSC/4 (or TCY) • FOSC/16 (or 4 • TCY) • FOSC/64 (or 16 • TCY)
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.
17
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.
T0CKI pin
T0SE
0
10
1
T0CS
FOSC/4
ProgrammablePrescaler
Sync withInternalClocks TMR0L
(2 TCY delay)
Data Bus<7:0>
8
PSAT0PS2, T0PS1, T0PS0
Set InterruptFlag bit TMR0IF
on Overflow
3
TMR0
TMR0H
High Byte
88
8
Read TMR0L
Write TMR0L
TIMER0 BLOCK DIAGRAM IN 16-BIT MODE
Figure 2.5: Timer0 Block Diagram in 16-bit Mode
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 16-
bit 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
18
2.2 Siemens M20 Terminal The Siemens M20 Terminal [5] is a GSM modem that combines all the features
required by developers and users to gain the power of GSM in their communication system. It is designed for handling complex industrial applications such as telemetry, and for integration in stationary or mobile fields all over the world.
M20 Term
inal
V.24 interfaceSub-D socket
Power supply(8-28,8V)and audio interface
FMEantenna connector SIM card reader
Handset interfaceOperating status LED Mounting holesbottom top
Figure 2.6: Siemens M20 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.
19
• The prefix consists of the letters “AT“ • The body is made up of individual characters; it consists of a name and (if applicable) associated values • 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 Description 1 Data Carrier Detect (DCD) 2 Receive Data (RXD) 3 Transmit Data (TXD) 4 Data Terminal Ready (DTR) 5 Ground (GND) 6 Data Set Ready (DSR) 7 Request to Send (RTS) 8 Clear to Send (CTS) 9 Ring Indication (RING)
DB9 CONNECTOR
594837261
2.2.3 SMS with the M20 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.
Figure 2.7: Pin Diagram of the DB9 Connector. The M20 Uses Only the Marked Signals
20
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.
0011000781214365F70000AA05E8329BFD06
PDU-type
MR
len
type ofnumber
Destination Adress:(Phone-number 1234567)
PID
DCS
VP(four days)
UDLUD ("hello" in 7 bit
default alphabet)
(7-bitcoding)
SCA
Figure 2.8: Example of a Message in the PDU Mode
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
21
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).
1
23
Top View(ComponentsUnderneath)
6
54
XTAL XTALOscillator
PLLSynthesizer Power Amp
In
En
Out
Pin Name Description1 En Enable (active high)2 IN Data input3 GND Ground, Connect to RF earth return path4 Vcc Supply Voltage5 GND Ground, Connect to RF earth return path6 EA External Antenna
Figure 2.9: The FM-RTFQ1-433 Transmitter, Operation and Pin Diagram 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.
22
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.
Component Side
1 3 7 11 15
Pin Pin Name Pin Pin Name1 +Vcc 11 GND2 GND 12,13 NC3 Data In (Antenna) 14 Data Out7 GND 15 Power Down
GND GND
Vcc
GND
Pre AmpFilter
OutMixer 10.7MHz
IF FilterFM
Demodulator Comparator
PLLSynthesizer
VccIn
Figure 2.10: The FM-RRFQ1-433 Receiver, Operation and Pin Diagram 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 didn’t 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.
23
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.
TOP VIEW
20
19
18
17
16
15
14
13
12
11
1
2
3
4
5
6
7
8
9
10
ADE7756
DGND
REF IN/OUT
AGND
DVDD
AV DD
V1P
V2P
V2N
V1N
CF
ZX
SAG
DOUT
SCLK
CS
IRQ
CLKIN
CLKOUT
Reset DINMULTIPLIER
DVDD
HPF1 LPF2
DGND
CLKOUT
V1PV1N
V2PV2N
2.4VREFERENCE
ADC
AVDD
PGA
CLKINREFIN/OUT
CF
AGND
4k
PHCAL[5:0]
MULTIPLIER
APOS[11:0]
DFC
DIN DOUT SCLK CS IRQ
ZX
ADE7756 REGISTERSAND
SERIAL INTERFACE
ADE7756
TEMPSENSOR
APGAIN[11:0]
CFDIV[11:0]LPF1
ADC O
RESET
SAG
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.
ADC
ADC
Currnet
Voltage
0110010101
0110010101
LPF Accumulate
InstantaneousPower
AveragePower
ConsumedEnergy
Figure 2.12: ADE7756 Basic Operation
The input channels are sampled at a frequency up to CLKIN/128, each sample is a 20-
bit 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.
24
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 Adapting the Input Signals
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.
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 Communicating with the ADE7756
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 DB6 DB5 DB4 DB3 DB2 DB1 DB0
W/-R 0 0 A4 A3 A2 A1 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.
1
220V
VotageSensor
ADE7756
1234567891011
121314151617181920 RESET
DVDDAVDD
V1PV1NV2PV2N
AGNDREF
DGNDCFZXSAGIRQCLKINCLKOUTCSSCLKDOUTDIN
10K
20K
100K
LOAD
220/12
CurrentSensor
Figure 2.14: Communication Register in the ADE7756
Figure 2.13: Voltage and Current Conditioning for the ADE7756
25
ADDR: 06H
TEST 1(TEST MODE SELECTION SHOULD BE SET TO 0)
WAVSEL(WAVE FORM SELECTION FOR SAMPLE MODE)
00 = LPF201 = RESERVED
10 = CH111 = 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)
0 0 0 0 0 0 0 0
7 6 5 4 3 2 1 0
0 0 0 0 1 1 0 0
89101112131415
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)
Figure 2.15: MODE Register in the ADE7756
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.
26
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
27
2.5 93C56, Serial EEPROM Electricity meters currently used do not "Reset to Zero" when a power failure occurs.
Adding this feature to our digital system is a must. Although the PIC18C452 is one of the most advanced MCUs available, it is still an
EPROM and therefore can't function as a non-volatile memory (NVR). We need the ability to store data in the absence of the power supply feeding the digital circuitry, data such as the accumulated energy for example. Adding this feature we can improve our system by making sure no data is lost whatever the circumstances are. The 93C56 [7] is a Serial EEPROM that helps accomplish that.
VCC
NC
GND
CS
SK
DI
DO
1
2
3
4
8
7
6
5
NC
INSTRUCTIONDECODER
CONTROL LOGICAND CLOCK
GENERATORS
HIGH VOLTAGEGENERATOR
ANDPROGRAM
TIMER
INSTRUCTIONREGISTER
ADDRESSREGISTER
EEPROM ARRAY
READ/WRITE AMPS
DATA IN/OUT REGISTER16 BITS
DECODER
16
16
DATA OUT BUFFER
CS
SK
DI
DO
VSS
VCC
CS Chip Select
SK Serial Data Clock
DI Serial Data Input
DO Serial Data Output
GND Ground
NC No Connect
VCC Power Supply
Figure 2.16: 93C56, Connection and Functional Diagrams
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 Using the 93C56 EEPROM
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 Meaning
READ Read stored words in the 93C56. The address must be specified
WEN Write Enable, this instruction must be issued at least once before any reading process to take place
WRITE Store data as words in the 93C56. The address must be specified WRALL Write All, used to fill all the 128 words of the 93C56 with the word in the data field
WDS 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
ERASE Fills the specified addressed word with 1s ERAL 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.
Table 2.1: Instructions of the 93C56
28
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 Start Bit Opcode Field Address Field Data Field
READ 1 10 X A6 A5 A4 A3 A2 A1 A0 WEN 1 00 1 1 X X X X X X
WRITE 1 01 X A6 A5 A4 A3 A2 A1 A0 D15-D0 WRALL 1 00 0 1 X X X X X X D15-D0
WDS 1 00 0 0 X X X X X X ERASE 1 11 X A6 A5 A4 A3 A2 A1 A0 ERAL 1 00 1 0 X X X X X X
2.5.2 Adapting Data to and from the 93C56 If noticed in table 2.2; an instruction can be done by sending the following to the chip:
• Start bit (“1”): should be issued to properly recognize the cycle • 2-bit Opcode: to select the instruction to be issued • 8-bit address: address for the read or write instruction, it could be a don't-care in other instruction • 16-bit data field: used only in the write instructions
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).
Byte1
1XXXXXXX XXX
StartBit Opcode Address Field
Byte1
000001XX XXXXXXXX
StartBit Opcode Address Field
Byte2
Byte2
Null Zeros
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 93C56 (because the total number of bits is 17), the 1st 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
Table 2.2: Instruction Set for the 93C56
29
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.
2.6.1 Line Driver (MAX232) Due to the voltage level difference between CMOS/TTL devices and devices using the
RS232 voltage level in the serial interface, we need a chip that can adapt voltage level between such devices.
Devices that use the RS232 voltage levels are the PC and the Siemens M20. The PIC is
a CMOS chip that needs to be linked with these devices; the MAX232 [8] does the linking job.
Remember The Line Driver will be referred to throughout the
entire text as the symbol shown. MAX232
2.6.2 Voltage Regulator (LM317)
While most digital devices are operating at the 5V power supply, the new trend is to
reduce power consumption by letting devices operate at a much lower voltage level; this is also made for devices that are meant to be portable (and battery operated).
The RF transmitter FM-RTFQ1-433 used is one such device; it operates at a voltage
level of 3.3V, and all of the input signals should be adapted to this level too. We need either a new 3.3V power supply (with its ground connected to the ground of the 5V power supply) or a way to convert the 5V power supply to a 3.3V.
Voltage regulation using the LM317 is very widely used; the
LM317 is used along with some resistors and capacitors to change the input voltage from 5V to 3.3V with a high output current, this is done by following an equation that relates the connected resistors to give the desired output. See the next equation that gives an output voltage of 3.25V using just two resistors.
VOUT = 1.25*(1 + R2/R1) VOUT = 1.25*(1 + 240/150) = 3.25 V
2.6.3 Open Collector Buffer Solving the problem of devices operating at voltage levels of 3.3V, we are faced by the
problem of signals at a voltage level of 0V and 3.3V (like the data signal for the RF transmitter FM-RTFQ1-433).
We need a way to change the voltage level of
CMOS/TTL signals to any desired voltage level; this is done by using an open collector buffer (like the 74LS07). We just need to connect the open collector to the desired voltage level through a resistor, put the desired signal we want to convert on the input of the buffer and take our new adapted signal from the output of the buffer.
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.
+5 V +3.25 V
LM317
3
1
2VIN
ADJ
VOUT
R2240
R1150
Figure 2.18: LM317
+3.25 V
U1A
74LS07
1 2
Signal (0 and 3.25 V)
Signal (0 and 5 V)
2.2K
Figure 2.19: 74LS07, OC Buffer
GSM Link
31
3.1 The PIC and the M20
The basic idea in using GSM communications in NCNs is to receive order messages from the utility in SMS form. The Master PIC [3] excutes the proper routine related to the message content and passes its commands to the CCUs through the Slave PIC*. Reversly, the system sends its replies, whether they are readings, reports or alerts, to the utility’s mainframe again in SMS form via the GSM network. The Master PIC highly benefits from the M20 feature that it alerts for any action within the GSM network at the serial data terminal, so the PIC can always monitor what is delivered to the M20 from network.
3.1.1 Hardware Interface
Since there should be a bidirectional communication between the Master PIC and the
M20 in the NCN, the transmitter pin (TX) of each device is to be connected to the receiver pin (RX) of the other. However since data terminal equipment (DTE), the M20 [5] in our case, mainly deals with TIA/EIA-232-E voltage level standards while data circuit-terminating equipment, the PIC in this case, usually uses the CCITT V.28 standards; an extra circuitry needs to be added to interface the PIC with the M20. The DS14C232 driver [8] realizes this when the TX and RX pins of the USART module in the PIC are connected to those of the M20 through the driver instead of being directly connected. Figure 3.1 shows a simplified diagram of this connection. The full wiring of the NCN including the PIC and M20 connection is described in Appendix A.
PIC
Master PIC
MAX232
Driver
M20
M20 Mother Unit PIC
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940MCLR/Vpp
RA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
SIEMENSEM20
1
2
3 4
Tx
Rx
GND Antenna
MAX232
26
7
8 9
1011
1213
14
16
1345
V+V-
T2OUT
R2IN R2OUT
T2INT1IN
R1OUTR1IN
T1OUT
VCC
C1+C1-C2+C2-
Figure 3.1: M20-PIC Connection
3.1.2 AT Command Interface
As illustrated in Chapter 2, the language M20 uses to dialogue with other devices
through the serial-data terminal is the AT Hayes Command set. The criterion in which the PIC and M20 communicate is provided here.
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
32
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 Enable command echo Command Format ATE [<value>]
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 Select SMS message format Command Format AT+CMGF=[<mode>]
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 Delete SMS message Command Format AT+CMGD=<index>
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.
Startup
Is it the 19th
message?
Send terminationcharacter
Disable M20'scommand echo
Set messagemode to TEXT
PIC
Master PIC
Delete a messagefrom M20
No
Yes
M20
M20
Startup
Ready for a newAT command
M20 will not sendechoes
SMS messagesare in TEXT mode
Message memoryis emptyReady
Figure 3.2: M20 Initialization
33
New Message Reading When an SMS message is received by the M20, a “new message” alert is sent to the
PIC’s USART receiver. The receiver interrupt flag (RCIF) is set due to this alert and the interrupt subroutine is executed. It should be remembered that the new-message alert is not the only string that could be received from M20, as there are many other important or unimportant indications arriving the receiver terminal. In addition, we could be waiting another response through the message reading or writing steps as will be shown later instead of waiting a new message. For this reason a special response-type flag is introduced to mark for the waited string in every step and a character-by-character scanning is to be performed to check the validity of the received string of data referring to a pre-stored format for every step of message reading. In the case when new message is received, the format looks like the following:
CMTI New SMS message indication Indication Format +CMTI: “SM”, <index>
This indication informs that the M20 terminal received a new SMS message and stored it in the SIM card memory. Parameter <index> the index of the message storage location in the memory. It could be in the range from 1 to 19.
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 new-message 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 Read SMS message Command Format AT+CMGR=<index>
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: “REC READ”,”<number>”,”?????-????”,”<date>,<time>”<body>
Parameters <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.
34
Main
Store receiveddata
PIC
Master PIC
M20
M20
NewMessage
New messagealert sent
Send message (i)content
Delete Message
ReadyAgain
interrupt
New SMS?
Check writingprocess
SMS Body?
Valid SMSindication?
Assign the newmessage index (i)
Read message ofindex (i)
Reset parameters
Yes
Yes
USART(M20)
No
No
Other
No
Store receiveddata
Valid SMSformat?
Run ProtocolCheck
Delete MessageNo
Yes
Yes
Check other
Figure 3.3: SMS Message Reading Process
New Message Sending Whether a meter reading, quality report, or deficiency alert is to be sent to the utility, a
new SMS message needs to be constructed in the Master PIC of the NCN and turned to the M20 which interfaces with the GSM network. Here is the way:
Unlike the reading process, the message writing process is activated by the Master PIC
itself not due to M20 alert interrupt. When the system intends to send a message to the Central Office, first of all the message-type flag should indicate what type of message is to be sent. This flag is set to the proper state through the PIC’s routine running. The real writing process starts when the Master PIC sends the message-send command (AT+CMGS) to the M20.
AT+CMGS Send SMS message Command Format AT+CMGS=”<number>” <CR><body><ctrl-Z>
The M20 terminal sends an SMS message with text in the <body>. Parameter <number> the number to which the new message is sent. <body> the body content of the sent message.
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.
35
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.
Main
Send a “send-message”
command to M20
PIC
Master PIC
M20
M20
Ready
Reply with a“space”
This is the end ofthe message
SendMessage
interrupt
Reset parameters
USART(M20)
Other
Writingresponsewaited?
No
Yes
Yes
Certain Process
A new SMSmessage needs to
be sent
Is it a“space”?
Check Message-Type flag
Send messagebody to M20Send ctrl-Z
Check other
Wait for the spacecharacter
Yes
Figure 3.4: SMS Message Sending Process
36
3.2 GSM Link Protocol
3.2.1 Protocol Main Rules It has been mentioned in the previous section that a certain protocol was set to insure
the maximum and easiest understanding between the utility, exemplified by the Central Office, and its NCNs spreading allover the network area. Moreover, such a protocol will make the system more stable and secure against any distructive actions.
As a part of the protocol, any message sent from the Central Office to the NCN must be
in the following form
@<Reply Number> <NCN ID> <CCU ID><Task Index><Extra Data>@
The Mobile Number to Reply to.It Can be of Any Length
6-digit Unique SecurityCode for the NCN
2-digit ID for the CCURequested to do a Task
1-digit Index for the Taskto PerformStarting Character Ending Character
Extra Optional Data Neededin some Tasks
Space Space
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 Task Description NCN CCU Extra
0 Check Operation (Check Link Status) 1 Read Meter’s Accumulated Energy 2 Read Power Factor 3 Read Switch Status 4 Connect/Disconnect Line 5 Reset PIC 6 Reset Slave PIC 7 Change Security Code 8 Change Emergency Number
Table 3.1: Task Index Description As the table shows, three tasks would need extra data. The shapes of these information
are descriped in table 3.2.
Task Index Extra Data Description Size 4 Switch On or Off Task Indicator 1 digit 7 New Security Code for the NCN 6 digits 8 New Emergency Mobile Telephone Number 12 digits
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
@<CCU ID><Task Index> <ExtraData>@Space
37
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><Task Index>@
If -for any reason- the aquired task failed to be done within a certain time, the NCN will reply to the utility through an SMS message indicating the failure. The reply format is
@<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.
3.2.2 Invalidity Reports All our speech on GSM protocol discussed only valid code formats which is not always
the case. The NCN may receive an invalid ID, invalid task or any other type of format invalidity. The NCN should be able to take action in any of these situations. These actions are summarized in table. Please note the error place is marked with an undelined bold font.
Invalidity Example Action
Tel. Number @+962771F345 ID1234 151@ Delete Message (No Number) NCN ID @+9627712345 IM1234 151@ Send “Wrong Code” Message
Task Index @+9627712345 ID1234 15A@ Send “Wrong Task” Message Extra Data @+9627712345 ID1234 004A3@ (Not 6) Send “Wrong Task” Message No Space @+9627712345 ID1234151@ (No space) Send “Wrong Format” Message
All This is an invalid SMS for test! Delete Message (No Number) Table 3.3: Invalidity Action Overview
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 don’t 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 can’t respond to the sender at all. Not only this, but also we can’t 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 utility’s 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 can’t 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.
38
1
PIC
M20 M20
NCN(ID 1234) Central Office
Read Energy in CCU 12@+96277910803 ID1234 121@
Send Task toCCU 12
PIC
M20 M20
NCN(ID 1234) Central Office
Ok, Send to Utility@121 00000000004F6A32672B@
Send Readingto NCN
Process Taskand Respond
2
PIC
M20 M20
NCN(ID 1234) Central Office
Check Status of CCU 15 Link@+96277910803 ID1234 150@
Send Task toCCU 15
PIC
M20 M20
NCN(ID 1234) Central Office
Not OK, Send Failed Task Report@15F@
Can’t Receivethe Task!
?Something
Wrong
3
PIC
M20 M20
NCN(ID 1234) Central Office
Reset the Slave PIC in the NCN@+96277910803 CD1234 006@
PIC
M20 M20
NCN(ID 1234) Central Office
Not Ok, Send Invalidity ReportWrong CodeInvalid Security Code!
PIC
CCU 12
PIC
CCU 15
PIC
CCU 12
PIC
CCU 15
PIC
CCU 12
PIC
CCU 15
PIC
CCU 12
PIC
CCU 15
Figure 3.5: GSM Link Protocol Example
RF Link
40
When discussing the basic design to our problem’s 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 Need Another USART Module
4.1.1 The Slave PIC
The RF modules used; FM-RTFQ1-433 and FM-RRFQ1-433 [6], use serial
transmission to get data to be broadcasted and deilver received data, respectively. This is true for both pairs of RF modules at the NCN and CCU sides. This fact axiomatically lead us to state that the component which should be connected to these modules must have a serial communication module. In our case this component is the PIC integrated in the CCU and NCN units, which already has the serial USART module. For the CCU part this is perfect; however, for the NCN we found a new problem since the lonely USART module of the NCN’s PIC is already in use to interface with the M20 terminal [5]. The problem is sybolized in figure 4.1.
PIC
M20
NCN’s PIC
? SerialSerial
Figure 4.1: The Missing Connection Mystery
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 didn’t plan our design on the PIC18C452 basis from the beginning.
4.1.2 The Master PIC and the Slave PIC
We now understand the need of two PICs at the NCN instead of one. But shouldn’t we
ask ourselves, if the Slave PIC is connected to the RF module through the USART, then what is there between the Master and Slave?! This is a reasonable question, and if we go back to Chapter 2 when mentioning some of the PIC features [3], we can conclude that the best to use in this position is the SPI (Serial Peripheral Interface) which is available –of course– in both PICs. As an entry to this connection details, it is worth to go over the basics of SPI one more time. The SPI uses mainly four pins of the PIC, these are:
• 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 Slave’s work proceeding with that of the Master. The Chip Select is a very useful feature for us, since
41
we can drive many Slaves by one Master. This pin shows its power when connecting an ADE7756 [4] and an NVR to the NCN’s 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 Master’s 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 PIC’s 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 NCN’s 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
PIC
Master PIC
InterruptInterrupt
ClockSDO
SDOCS
Give Data
Tx
CS
SDO
RF Module
SCK
Master
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940
MCLR/VppRA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
SCK
CS
SDI
Rx
Slav e
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940
MCLR/VppRA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
INT1
SDO
Rx
INT1
Reset
TxM20
Stop Data
SDICS
Figure 4.2: Master-Slave PICs Connection
42
4.1.3 How It Works The communication between the Master and Slave PIC at the NCN unit is not as
simple as it may seem for the first glance. When the Master wants to pass a command to a CCU, it first sends an interrupt signal to the Slave PIC; this will make it ready to receive data from the Master. A byte received from the Master is sent directly to the RF Tx. After sending data to the CCU, the Master disables the NCN’s RF Tx to overcome the destructive effect of two transmitters working on the same RF carrier frequency. This point will be studied in more detail in the coming section of this chapter.
When the RF Rx of the NCN detects a signal, the Slave checks the Rx-Data Blocking
flag to know if it should alert the Master or not. If yes, the Slave sends its own interrupt signal which will wakeup the Master’s SPI operation again. Thus, the Master PIC calls the data received by the Slave. Once this finishes, the Master enables the RF Tx again to be ready for the next action. The Master-Slave communication process is simplified in the flow chart below, figure 4.3.
Main
Send data toSlave through SPI
PIC
Master PIC
Main
Need to send datato the RF
Send Interrupt tothe Slave
PIC
Slave PIC
interrupt
INT1
Check otherOther
Does SPItransfer
complete?
Yes
No Finish alldata?
YesNo
Send data toUSART (RF)
Figure 4.3: (a) Master-to-Slave Writing Process
PIC
Master PIC
PIC
Slave PIC
Main
Send data throughSPI
Main
Send Interrupt tothe Master interrupt
INT1
Check otherOther
Receive Slave’sdata
Received datavia SPI?
Yes
No Send dummy datato read the Slave
Processreceived data
Can alert theMaster?
Return toMain
Yes
No
interrupt
USART
Check otherOther
(b) Slave-to-Master Writing Process
43
4.2 Adapting the RF Transmitter In their original situation, the chosen RF modules can not said to be “ready” to install
in our system, as there are some technical parameters that should be matched for the RF modules and the rest of the system, as well as there are some technical limitations that should be overcome. This section will be dedicated to talk about and solve specific RF transmitter problems, while the next section will describe the solution of some problems arise due to the real operation of the RF-module pairs within the system.
4.2.1 Power Supply
While the RF Rx (FM-RRFQ1-433) is driven by a 5-volt source (Vcc = 5) and delivers
received data to the system in 0 or 5-volt level mode, which is fully compatible with whole system theme, the RF Tx somehow contradicts this theme. The RF (FM-RTFQ1-433) Transmitter module needs a 3.3-volt source to supply power to its circuit, and due to this it is also limited to receive a shrinked voltage range of (0 V – 3.3 V) only from the system which outputs up to 5-volt signals.
For this reason, and to solve the 3.3-V power supply problem, an additional regulator
IC (LM317) is used. This regulator, with the aid of a simple resistor-capacitor circuitry connected to it, can output a fixed voltage-level of DC signal that satisfies our purpose needs. Figure 4.4 shows the connection between the RF Tx and the regulator and the additional circuit components.
RF Tx Regulator
LM317
5 Volt3.25 Volt
C1100 uF
+5 V
R2240
FM-RTFQ11
23 4
5
6En
InGND Vcc
GND
EA
+3.25 V
R1150
LM317
3
1
2VIN
ADJ
VOUT
Figure 4.4: RF Transmitter-Regulator Connection
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.
4.2.2 Input Data Level As mentioned above, another problem regarding the RF Tx is that it is limited to stand
not more than 3.3-V signal level as a maximum, so it is obvious that an extra stage should be inserted between the TTL-level pin of the PIC and the data-input pin of the RF Tx to drop down the voltage level from 5 to 3.3 volts. We can introduce at least 3 simple approaches to perform this stage’s function, the Open-Collector Buffer, a transistor circuit and finally the very basic series of diodes.
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).
44
Figure 4.5: Open-Collector Voltage Adapter
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.
9.7 k
2.7 k
V in
9.7 k
VCC = +3 V
Q1
V out
2.7 kQ2
Figure 4.5: Transistor-Based Voltage Adapter
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 PIC’s 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
FM-RTFQ11
23 4
5
6En
InGND Vcc
GND
EA
Figure 4.6: Diode-Based Voltage Adapter
4.2.3 Transmitter's Phased Locked Loop (PLL)
Reading the documentation of the RF transmitter, we notice the Initial Frequency
Accuracy parameter (-25 to 25 KHz). This parameter was not understood until the actual implementation of the module with the system.
The internal PLL of the transmitter module needs time to lock at the right carrier
frequency (433 MHz), this needed time is not measured in seconds but in the number of successive bytes sent to the transmitter in a row (i.e. each time we need to send data through the transmitter, it needs to start its PLL synchronization process, thus loosing a significant number of bytes from the first bytes sent to the transmitter).
This problem was solved by sending a row of specific dump bytes to the transmitter
before sending our own data. This dump data was tested over and over to make sure PLL synchronization is made as soon as possible. We have found that the best dump data to send was:
0000FFFFh
PIC Tx (0 and 5 V) FM-RTFQ11
23 4
5
6En
InGND Vcc
GND
EAU1A
74LS07
1 2
+3.25 V
R3
2.2K
45
4.3 The PIC and the RF Modules
4.3.1 Hardware Interface
Whether it is at the CCU or NCN side, the RF-module pair is connected to a PIC which controls its operation. As expected, the Data-Input pin of the RF transmitter should be connected to the TX pin of the USART port of the PIC; however this does not mean a direct connection as we have just described the level voltage conflict between both pins. In the other side, the Data-Out pin of the RF receiver should be connected directly to the RX pin of the PIC’s USART. Of course, for the CCU this description is clear since there is only a unique PIC. But when talking about the NCN, we should notice that some pins are connected to the Slave PIC while others are connected to the Master PIC. Figure 4.7 provides the part of schematic diagram related to the PIC-RF module connection. The full schematics are available in Appendix A.
RF Tx
PIC
RF Rx
TX
RX
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940
MCLR/VppRA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
FM1FM-RTFQ11
23 4
5
6En
InGND Vcc
GND
EA
FM2FM-RRFQ1
1 2 3 7 1514131211
Vcc
GN
DD
in
GN
D
PD
Dou
tN
CN
CG
ND
Figure 4.7: PIC–RF Modules Connection
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 CCU’s PIC and the NCN’s 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 NCN’s 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.
4.3.2 How It Works
When the NCN wants to communicate to a CCU, it runs the SPI routine to pass the
data from the Master to the Slave PIC. The Master sets the Rx Data-Blocking pin to disable echo. The Slave will send every bit of data to the RF Tx. When this finishes, the Master disables the NCN’s Tx to give the CCU to transmit its reply. At the CCU side, the Rx is always enabled to receive data, so when data is detected it starts forwarding the received data to the CCU’s PIC, which processes the data and outputs the proper reply to the NCN which is sent through the RF Tx. After receiving the reply at the NCN side, the CCU’s Tx is disabled and that of the NCN is enabled again.
46
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
@<CCU ID><Task Index><Extra Data>@
2-digit ID for the CCURequested to do a Task
1-digit Index for the Taskto Perform
Starting Character Ending Character
Extra Optional Data Neededin 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 system’s stability is that if the CCU did not reply to the NCN’s request within 40 second, this is considered a failure and the NCN replies to the Central Office with a failed-task report.
@12F@
Data Gathering& Process Controlling
48
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 Calculate Digitally with the ADE7756
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 don’t 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.
ADC
ADC
Currnet
Voltage
0110010101
0110010101
LPF Accumulate
InstantaneousPower
AveragePower
ConsumedEnergy
Figure 5.1: Basic Operation of the ADE7756
49
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 and the ADE7756
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.
ADE7756 PICSPI
CS
100K
CS
20K
Master
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940
MCLR/VppRA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
SDO
1
ADE7756
1234567891011
121314151617181920
RESETDVDDAVDD
V1PV1NV2PV2N
AGNDREF
DGNDCFZXSAGIRQCLKINCLKOUTCSSCLKDOUTDIN
SDI
220/12
10K
SCKSDO
CS
SCK
SDI
220V
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.
SDI
Tx
1Master
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940
MCLR/VppRA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
20K
CS
Rx
SDI
M20
CS
CS
Slav e
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940
MCLR/VppRA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
CS
ADE7756
1234567891011
121314151617181920
RESETDVDDAVDD
V1PV1NV2PV2N
AGNDREF
DGNDCFZXSAGIRQCLKINCLKOUTCSSCLKDOUTDIN
SCK
220V
10K
100K
SDO
Rx
93C56
1
2
34
CS
CLK
DIDO
SDI
220/12
Tx
SCK
CS
SCK
RF Module
SDO SDO
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
50
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 Calculating the Consumed Energy The steps to go through for calculating the consumed energy using the ADE7756 are:
A. Setup the ADE7756 B. With the PIC, keep reading the RSTENERGY register every fixed period of
time and accumulate the reading in a larger register C. Convert the reading to energy, This step needs the ADE7756 to be calibrated
The final accumulated reading is just a null number that must be converted into a watt-
hour 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. Setting the ADE7756
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.
ADDR: 06H
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)
0 0 0 0 0 0 0 0
7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0
89101112131415
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)
Figure 5.4: Setting the MODE Register in the ADE7756
• 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).
51
• 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 error-correction 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.
4CLKIN
TIME nT
WAVEFOR REGISTER
VALUEST
23 0
AENERGY[39:0]
WAVEFORM REGISTER VALUES AREACCUMULATED (INTEGRATED) INTHE ACTIVE ENERGY REGISTER
ACTIVE POWERSIGNAL P
LPF2CURRENTCHANNEL
VOLTAGECHANNEL
OU
TPU
T LP
F2
WAVEFORM [23:0]
APOS [11:0]
39 0
11 0
Figure 5.5: APOS register added to the Total Accumulated Energy
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).
Ass
embl
y C
ode
; Setting the MODE register to 1808 movlw 0x86 ; movwf CommReg ; Save 86h to the CommReg (it is a temp register in the PIC) call ChipSelectADE ; Chip select the ADE7756 call SendComm ; Call the "Send Communication Register" subroutine movlw 0x00 ; Send 0040h to the ADE (2 bytes) call SendADE ; movlw 0x40 ; call SendADE ; call ChipDeselectADE; Chip deselect the ADE7756
B. Accumulating the Consumed Energy with the PIC 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).
Listing 5.1: Assembly Code for Setting the MODE register to 0040h
52
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.
Main
Interrupt Check OtherOther
Send 0x03 toComm. Reg.
Timer0Interrupt
Read 40-bitActive Energy(RSTENERGY)
Add to 80-bitTAE Register
CalculateEnergy
Comm.Reg?
Check Comm.Register
Ready Data forthe PIC
No
Yes
ADE7756 PIC
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.
Main
Interrupt Check OtherOther
AccumulateADE7756 Energy
Timer0Interrupt
PIC
40 SecPassed?
Store TAERegister in
93C56 EEPROM
No
Yes
NVR
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. Calibrating the ADE7756
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
53
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 watt-
hour 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.
Exam
ple
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:
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 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. Registers Read after an (R) # bits Registers Written after a (W) 1 WAVEFORM 24 bit Invalid (Read Only) 2 AENERGY 40 bit Invalid (Read Only) 3 RSTENERGY 40 bit Invalid (Read Only) 4 STATUS 8 bit Invalid (Read Only) 5 RSTATUS 8 bit Invalid (Read Only) 6 MODE 16 bit MODE 7 CFDIV 12 bit CFDIV 8 CH1OS 6 bit CH1OS 9 CH2OS 6 bit CH2OS A GAIN 8 bit GAIN B APGAIN 12 bit APGAIN C PHCAL 6 bit PHCAL D APOS 12 bit APOS E ZXTOUT 12 bit ZXTOUT F SAGCYC 8 bit SAGCYC G IRQEN 8 bit IRQEN H SAGLVL 8 bit SAGLVL I TEMP 8 bit Invalid (Read Only) J Users stored 2 bytes 16 bit Reset user bytes to 0000h K TAE 80-bit Reset the TAE register
Table 5.1: Calibration Program, Registers Addresses
Listing 5.2: Calculating the Energy Constant, an Example
54
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 Calculating the Power Factor
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
Voltage(Channe2)
Current(Channel1)
Figure 5.7: Power Factor Calculation
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
55
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 Reading the Status of a Switch
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.
34 12
C
A
B
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940MCLR/Vpp
RA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
Figure 5.8: Simple Implementation of a Switch
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.
56
C9452.7K
2N3053
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940
MCLR/VppRA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
LAMP 1
+5V
Figure 5.9: DC Lamp Switch
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.
Central Office
58
6.1 What is a Central Office?
After a whole communication system was established and data was gathered, we need to use this communication system in order to get the data and to control the processes. This is the job of the Central Office.
The Central Office is the main harvesting node that collects data from all NCNs (and
CCUs) in the system and manages process controlling too. The automation of the system should mainly be implemented in the Central Office.
So, in its simplest form, it could be a software program installed in the electricity utility.
It should be connected to a database to store various data and transactions from different nodes in the system. The computer should interface a GSM device to enable sending/receiving data from/to NCNs in the AMR system.
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.
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.
Figure 6.2: Central Office Main Form
Figure 6.1: Central Office
59
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).
Nokia DataSuite
AT CommandsNokia Specific
Commands
Nokia 8210
VirtualCOM
PhysicalCOM
CentralOffice
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.
Navigation Tabs, use these tabs tonavigate other pages in the CentralOffice, these pages contain most of
the system features
Menu Bar, Use it to exit theprogram or to see the Help About
Port Status, this shows thenumber of port opened, or
indicates if no port is opened
User Control Area, here the userperforms actions and sees results
Figure 6.3: Overview of the Central Office IDE
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
60
6.3.1 Initializing the Software At startup, most of the software controls are disabled; this is because the Central Office
hasn't been initialized yet. Initializing the system is about setting up the system parameters properly in order to establish a healthy communication with the Nokia 8210. The figure below shows the Settings tab; here we initialize the system by the steps mentioned below.
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)
61
6.3.2 Sending Tasks
After we have initialized the Central Office; we move on to sending tasks to CCUs in
the system, this is done in the tab as shown below.
Figure 6.5: Sending Tasks from the Central Office Tab
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.
62
Figure 6.6: Available Tasks and Their Task Boxes
As an example; the task information shown in figure 6.5 will send the following SMS to
the M20 with mobile number 077884717:
@077910803 ID1234 5541@
Reply Number Specifiedin the Settings Tab
6-digit NCNSecurity Code
2-digit CCU ID
Task Index(Connect/Disconnect
Line)
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
viewed in the tab under the Data Sent to the Mobile group box (we will see this feature in the Debugging and Troubleshooting section).
6.3.3 Receiving Tasks When the CCU or NCN performs the required task, the NCN should reply to the
Central Office with a message showing the status of the performed task. Here we will read this message and analyze it to extract the information sent from the NCN.
As mentioned before; the Nokia 8210 doesn’t give indication about the arrival of new
messages. This leads us (for the sake of demonstration) to supply the user with a "Read Task" button along with the "Default Message Index to read". Such situation -of course- should not happen in a real implemented system.
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
63
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.
Figure 6.6: Receiving Tasks with the Central Office
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 no-
message-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:
Figure 6.7: Unrecognized Messages and No Message Read conditions
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.
64
All valid analyzed tasks are stored in a log file for demonstration only. This log file can
be viewed from the tab.
Figure 6.9: Logfile Holds All Valid Tasks Received
6.3.4 Debugging and Troubleshooting The basic operation of the Central Office is complete as explained in the previous
sections. This section presents some further useful features implemented in the Central Office that help the user debug errors and troubleshoot them.
All transactions made between the Central Office and the Nokia 8210 mobile can be
viewed by the user, these transactions help determine errors affecting the system operation. All data sent from the Central Office and data received from the Nokia 8210 can be viewed from
the tab.
Figure 6.10: The Debug View Helps Determine Errors in the System
65
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.
Figure 6.11: The Send Custom AT Command.
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.
Total System Implementation
67
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.
7.1.1 NCN Startup
We do not need to repeat that the PIC is the “Heart” and “Brain” of every hardware
stage in our system. This statement will obviously lead us to understand why it is the device responsible for the startup of the stage components in the NCN. Actually the Master PIC not only plays the main role in setting up the other components of the NCN, but can also command the Slave PIC to restart itself at any time. The Master PIC startup procedure includes the following steps:
• 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.
7.1.2 CCU Startup The PIC of the CCU operates the basic startup procedure, as well as it resets all the
ADE meters connected to it, setups them and makes them ready to calculate and accumulate energy.
7.1.3 Central Office Startup
To provide full communication between the utility and the system’s network
components, the AMR management system software should be properly installed in the utility’s computer terminals. The software should be carefully tested and all setting should be made before logging in to the network. This includes communication port setting, default reply number and many other parameters.
68
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 NCN’s M20 terminal can receive the utility’s 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 GSM-
Link 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 NCN’s 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 NCN’s 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 utility’s 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.
69
PIC
Mas
ter
PIC
Mai
n
inte
rrup
t
USA
RTTi
mer
0IN
T1
Acc
umul
ate
AD
E77
56E
nerg
y
40Se
cPa
ssed
?
Stor
eTA
ER
egis
teri
n93
C56
EEPR
OM
No
Yes
NVR
PIC
Sla
vePI
C
Giv
eD
ata
Thro
ugh
SPI
Rec
eive
Slav
e’s
Data
SPID
ata?
Yes
No
Sen
dD
umm
yD
ata
toR
ead
Slav
eD
ata
Pro
cess
Rec
eive
dD
ata
Stor
eR
ecei
ved
Dat
a
M20
New
Mes
sage
Send
Mes
sage
(i)Bo
dy
Del
ete
Mes
sage
Rea
dyA
gain
New
SMS?
SMS
Bod
y?
Valid
SMS
Indi
catio
n?
Rea
dN
ewM
essa
ge(i)
Res
etPa
ram
eter
s
Yes
Yes
No
No
No
Stor
eRe
ceive
dDa
ta
Valid
SMS
Form
at?
Run
Prot
ocol
Che
ck
Del
ete
Mes
sage
No
Yes
Yes
ToM
ain
ToM
ain
M20
Nee
dto
send
mes
sage
Rec
eive
mes
sage
body
from
the
Mas
terP
IC
Send
Mes
sage
Writ
eSM
SIn
dica
tion?
Send
Mes
sage
toM
20Yes
New
Data
toSe
ndTh
roug
hR
F
Send
Dat
ato
USA
RT
(RF)
Rece
iveDa
tafro
mth
eM
ater
PIC
inte
rrup
t
New
Dat
afr
omR
F
Send
inte
rrupt
INT1
toM
aste
rto
Rea
dth
isda
ta
USA
RTIN
T1
Giv
eD
ata
toM
aste
r? Yes
Disc
ard
Data
and
Retu
rnN
o
Figure 7.1: Total NCN Operation Flowchart
70
Send
0x03
toC
omm
.Reg
.
Read
40-b
itAc
tive
Ener
gy(R
STEN
ERG
Y)A
ddto
80-b
itTA
ER
egis
ter
Calc
ulat
eEn
ergy
Com
m.
Reg
?
Che
ckC
omm
.R
egis
ter
Rea
dyD
ata
for
the
PIC
No
Yes
AD
E77
56
40S
ecP
asse
d?N
o
Yes
Stor
eTA
ER
egis
ter
in93
C56
EEPR
OM
NVR
Mai
n
Inte
rrup
tTi
mer
0
PIC
ToM
ain
Rec
eive
Mes
sage
from
the
RF
Per
form
the
acqu
ired
Task
Enab
leR
FTr
ansm
itter
Rep
lyto
NC
Nth
roug
hR
F
Dis
able
RF
Tran
smitt
er
US
AR
T
New
Task
CC
UP
IC
Figure 7.2: Total CCU Operation Flowchart
Due to any kind of error, the desired task may not be achieved. It could be a Central-Office 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 PIC’s memory content every 40 seconds. This feature enables the PIC to reload its memory at startup.
71
7.3 The System Through an Example
Our scenario can be presented as follows: A consumer was fully disappointed of her last electricity-consumption bill. She
complained that the meter installed at her house door was “crazy”. As she said, her family consumption was no more than half the value shown on the bill. The Customer-Service officer calmed the lady down and asked her:
- May I have your bill, please?
He picked the Consumer ID number from the bill and inserted it to the Central Office
Consumer Information screen. One click and all information about the consumer and her consumption were on the screen. From the data provided, the officer realized that the consumer meter was covered by NCN of Security Code (ID1234) and it is directly connected to the CCU numbered (15) within the mentioned NCN’s region. The screen also showed that the mobile telephone number (077910803) was used to communicate with the desired NCN.
The first thing the officer thought of was to get the present meter reading and compare it
with the last reading, which was just the day before, since the reading process became a daily habit of the system’s NCNs. He selected “Read Energy” task from the tasks list of the Central Office, filled the needed fields and clicked on “Send Task”… and that’s it!
Few seconds and the Central Office alerted for the reply reception. As the data got from
the meter and after the automatic analysis of the consumer load-line history, the consumer had an unusual high-consumption period for one week. When the officer described the situation to the lady, she shouted:
- Oh, sorry! I have just remembered. It was my son wedding and we kept celebrating for a week. No lights, flashes, sound systems and other staff were shut down for total seven days! Sorry sir, but I still wonder, how could you read my house-meter in a glance?!
Here is the Answer…
72
Nok
ia 8
210
Cel
lula
r Bas
eSt
atio
n
M20
M20
PIC
NC
N ID
1234
RF
Mod
ule
PIC
Mas
ter
Slav
e
PIC
CC
U 1
5
PIC
RF
Mod
ule
AD
E775
6
Elec
tric
al L
oad
AD
E775
6
Nok
ia 8
210
Cel
lula
r Bas
eSt
atio
n
M20
M20
PIC
NC
N ID
1234
RF
Mod
ule
PIC
Mas
ter
Slav
e
PIC
CC
U 1
5
PIC
RF
Mod
ule
AD
E775
6
Elec
tric
al L
oad
AD
E775
6
Pro
cess
Req
uest
ed T
ask
:(S
end
TAE
to C
entr
al O
ffice
)
AT+
CM
GS=
”077
9108
03"
@07
7884
717
ID12
34 1
51@
@15
1@
@15
1 00
0000
37F2
ED24
B56
B54
@
AT+
CM
GS=
”077
8847
17"
@15
1 00
0000
37F2
ED24
B56
B54
@
@15
1 00
0000
37F2
ED24
B56
B54
@
Conclusion
74
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 Carrier-Detect 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).
75
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. Power Supply Backup System
The reader could have the thought that this system needs a power supply independent
from the line voltage feeding the load. This helps the system to be always online and report different urgent problems at the site (e.g. a power down situation).
The figure below shows one simple design using the 7805 voltage regulator and a
regular 5V rechargeable battery.
+12V 78051 3
2VIN VOUT
GN
D
RECHARGEABLE BATTERY
+5V
R
Power SupplyFeeding theSystem
Figure 8.1: Rechargeable Power Supply Backup System
Other Ways for Gathering Data
There could be other ways than the GSM network to gather the customer's data.
Telephone lines are one example; a V22 chipset can be used with the PIC to interface the PIC with the telephone line. The dial tones can be used as the data form. Customers' information can be gathered at times when people are not using the phone (mainly at night).
There is another new method (or idea) to collect data; it is by using the power lines
themselves. The power lines mainly contain the 50 Hz frequency. Higher frequencies can be used to interchange data between the system parts. This method is used in high-voltage power lines (to quickly control the circuit breakers switching).
Web-Enabled Customer-Service Solution As all information and statistics about the customers' consumption are available at a
higher resolution than the traditional way; a web-enabled customer-service solution can be introduced. Such solution would enable the customer to monitor e.g. his consumption rate and view his overdue bills online.
Other Systems Benefiting from this System As the PIC is interfaced with the M20; a data channel is always available from the
customer's side, therefore enabling any other ideas for new systems to gather whatever data from the customer's side.
Examples are many; water and gas consumption, real time security alarm systems,
wireless control systems…
References
77
References: [1] Automatic Meter Reading Association, www.amra.org [2] Itron Company, www.itron.com, and other resources [3] Microchip PIC18C452 datasheets on the companion CD, www.microchip.com [4] Analog ADE7756 datasheets on the companion CD, www.analog.com [5] Siemens M20 Terminal datasheets on the companion CD, www.siemens.com [6] RF Solutions RTFQ1/RRFQ1 datasheets on the companion CD, www.rfsolutions.co.uk [7] Fairchild 93C56 datasheets on the companion CD, www.fairchildsemi.com [8] DS14C232 datasheets on the companion CD, www.national.com [9] Automatic Remote Meter Reading, graduation project (2002) by Camelia A. Najjar and
Salam M. Zalloum
Appendix A
79
10K
33 pF
20 pF
VC
C
+
1 uF
to M
aste
rInte
rrupt
1
150
20 pF
VC
C
100
220/
12
to S
alve
Inte
rrupt
1
CS
93C
56
+
1 uF
20K
100
+3.2
5 V
+
1 uF
FM
-RTF
Q1
1 2 3456
En
In GN
DV
ccG
NDEA
100
uF
LED
+5 V
10K
100
uF
U2 A
DE
7756
1 2 3 4 5 6 7 8 9 1011121314151617181920
RE
SE
TD
VD
DAV
DD
V1P
V1N
V2P
V2N
AG
ND
RE
FD
GN
DC
FZ
XS
AG
IRQ
CLK
INC
LKO
UT
CS
SC
LKD
OU
TD
IN
SIEM
ENSE
M20
1 2 34
Tx Rx
GN
DA
nten
na
Tx
LED
0.1 uF
CS
Sla
ve
Rx
34
100 uF
12
Mas
terP
IC
PIC
18C
425
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 202122232425262728293031323334353637383940
MC
LR/V
ppR
A0/
AN
0R
A1/
AN
1R
A2/
AN
2/VR
EF-
RA
3/A
N3/
VRE
F+R
A4/
T0C
KI
RA
5/A
N4/
SS/L
VD
INR
E0/
RD
/AN
5R
E1/
WR
/AN
6R
E2/
CS
/AN
7V
DD
VS
SO
SC
1/C
LKI
OS
C2/
CLK
O/R
A6
RC
0/T1
OSO
/T1C
KIR
C1/
T1O
SI/C
CP
2R
C2/
CC
P1
RC
3/S
CK
/SC
LR
D0/
PS
P0R
D1/
PS
P1R
D2/
PS
P2
RD
3/P
SP
3R
C4/
SDI/
SDA
RC
5/S
DO
RC
6/TX
/CK
RC
7/R
X/D
TR
D4/
PS
P4
RD
5/P
SP
5R
D6/
PS
P6
RD
7/P
SP
7V
SS
VD
DR
B0/
INT0
RB
1/IN
T1R
B2/
INT2
RB
3/C
CP
2R
B4
RB
5R
B6
RB
7
SD
IS
DO
3.68
64 M
hz
100 uF
1
2.7K
+
1 uF
VC
C
LM31
7
3 1
2V
IN
AD
J
VO
UT
300
2N30
53
300
220V
Sla
veP
IC
PIC
18C
425
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 202122232425262728293031323334353637383940
MC
LR/V
ppR
A0/
AN
0R
A1/
AN
1R
A2/
AN
2/V
REF
-R
A3/
AN
3/V
REF
+R
A4/
T0C
KI
RA
5/A
N4/
SS
/LV
DIN
RE
0/R
D/A
N5
RE
1/W
R/A
N6
RE
2/C
S/A
N7
VD
DV
SSO
SC
1/C
LKI
OS
C2/
CLK
O/R
A6
RC
0/T1
OSO
/T1C
KI
RC
1/T1
OSI
/CC
P2
RC
2/C
CP1
RC
3/S
CK
/SC
LR
D0/
PSP
0R
D1/
PSP
1R
D2/
PS
P2R
D3/
PS
P3R
C4/
SD
I/SD
AR
C5/
SD
OR
C6/
TX/C
KR
C7/
RX/
DT
RD
4/P
SP4
RD
5/P
SP5
RD
6/P
SP6
RD
7/P
SP7
VS
SV
DD
RB
0/IN
T0R
B1/
INT1
RB
2/IN
T2R
B3/
CC
P2R
B4R
B5R
B6R
B7
NC
N S
chem
atic
Dia
gra
m
LAM
P
OFF
20 pF
100
uF
Enable Tx
05
Dis
able
Rec
eive
CS
AD
E77
56
VC
C
FM
4FM
-RR
FQ1
123
7
1514131211
VccGNDDin
GND
PDDoutNCNCGND
0.1 uF
3.68
64 M
hz
20 pF
+5 V
VC
C
+1
uF
05
+5V
100K
15
05
C94
5
ON
4.7
uF33 pF
93C
56
1234
CS
CLKD
ID
O
SC
K
U5
TC23
2
2 6
7
89
1011
1213
14
161 3 4 5
V+
V-
T2O
UT
R2I
NR
2OU
T
T2IN
T1IN
R1O
UT
R1I
N
T1O
UT
VC
C
C1+
C1-
C2+
C2-
240
300
3.68
64 M
hzR
eset
Sla
ve
80
20K
4.7 uF
+3.25 V 05
CS ADE7756
FM4FM-RRFQ1
1 2 3 7 1514131211
Vcc
GN
DD
in
GN
D
PD
Dou
tN
CN
CG
ND
34
300
100
uF
05
2N3053
10K
A
VCC
33 p
F
12
150
LAMP 1
100K
SCK
10K
+5V
93C56
1
2
3 4
CS
CLK
DI DO
3.6864 Mhz
B
+5 V
20 p
F
220/12
300
Tx
FM-RTFQ11
23 4
5
6En
InGND Vcc
GND
EA
CCU SchematicDiagram
20 p
F
VCC
3.6864 Mhz
2.7K
240
+5 V
Ena
ble
Tx
LM317
3
1
2VIN
ADJ
VOUT
U2ADE7756
1234567891011
121314151617181920
RESETDVDDAVDD
V1PV1NV2PV2N
AGNDREF
DGNDCFZXSAGIRQCLKINCLKOUTCSSCLKDOUTDIN
Rx
33 p
F
100
100 uF
VCC
05
100 uF
C945
220V
0.1
uF
CS 93C56
1
ChildPIC
PIC18C425123456789
1011121314151617181920 21
22232425262728293031323334353637383940
MCLR/VppRA0/AN0RA1/AN1RA2/AN2/VREF-RA3/AN3/VREF+RA4/T0CKIRA5/AN4/SS/LVDINRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7VDDVSSOSC1/CLKIOSC2/CLKO/RA6RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRD0/PSP0RD1/PSP1 RD2/PSP2
RD3/PSP3RC4/SDI/SDA
RC5/SDORC6/TX/CKRC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7
VSSVDD
RB0/INT0RB1/INT1RB2/INT2
RB3/CCP2RB4RB5RB6RB7
C
100 uF
LED
81
300
0.1 uF
220/
12
+
1 uF
220V
VC
C1
VC
C
10K
PC R
x
+1
uFGND
VC
C
3.68
64 M
hz
PC
Ser
ial C
onne
ctor
DB
9
594837261
3.68
64 M
hz
+
1 uF
+
1 uF
20K
15
20 pF
U5
TC23
2
2 6
7
89
1011
1213
14
161 3 4 5
V+
V-
T2O
UT
R2I
NR
2OU
T
T2IN
T1IN
R1O
UT
R1I
N
T1O
UT
VC
C
C1+
C1-
C2+
C2-
4.7
uF
100
33 pF
33 pF
LED
U2 A
DE
7756
1 2 3 4 5 6 7 8 9 1011121314151617181920
RE
SE
TD
VD
DA
VD
DV
1PV
1N V2P
V2N
AG
ND
RE
FD
GN
DC
FZ
XS
AG
IRQ
CLK
INC
LKO
UT
CS
SC
LKD
OU
TD
IN
300
+
1 uF
100K
AD
E7756 C
alib
ration
Sch
emat
ic D
iagra
m
U4
PIC
18C
425
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 202122232425262728293031323334353637383940
MC
LR/V
ppR
A0/
AN
0R
A1/
AN
1R
A2/
AN
2/V
RE
F-
RA
3/A
N3/
VR
EF
+R
A4/
T0C
KI
RA
5/A
N4/
SS
/LV
DIN
RE
0/R
D/A
N5
RE
1/W
R/A
N6
RE
2/C
S/A
N7
VD
DV
SS
OS
C1/
CLK
IO
SC
2/C
LKO
/RA
6R
C0/
T1O
SO
/T1C
KI
RC
1/T1
OS
I/CC
P2
RC
2/C
CP
1R
C3/
SC
K/S
CL
RD
0/P
SP
0R
D1/
PS
P1
RD
2/P
SP
2R
D3/
PS
P3
RC
4/S
DI/
SD
AR
C5/
SD
OR
C6/
TX/C
KR
C7/
RX/
DT
RD
4/P
SP
4R
D5/
PS
P5
RD
6/P
SP
6R
D7/
PS
P7
VS
SV
DD
RB
0/IN
T0R
B1/
INT1
RB
2/IN
T2R
B3/
CC
P2
RB
4R
B5
RB
6R
B7
20 pF
100 uF
10K
PC T
xV
CC