Fixed-Network Automatic Meter Reading (AMR) System
Fixed-Network Automatic Meter Reading (AMR) System
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.
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.
II
Abstract
Fixed-Network Automatic Meter Reading (AMR) is the latest advance in
the telemetry field. It utilizes already available fixed communication networks
(e.g., the cellular network) for exchanging data to minimize cost and human effort.
The 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.
Yet, the results still need further analysis and improvements to be made.
Using other chips and advanced microcontrollers can help in gathering more data
and control further processes.
III
Table of Contents
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
V
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 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 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 VI
Introduction
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.
2
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]:
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 3
processes the data received from the meters and can either keep them to be loaded manually at
the utility or send them directly to the utility by means of a long-range communication network
such as cellular or satellite. It is clear that this method benefits as much as it can from the
utility's vehicle capabilities to reduce the losses, size and time limitations of the previous system,
however a new disadvantage arises which is the inability of the vehicle to reach the range of the
meter transmission in crowded or randomly-built areas.
Fixed-Network AMR
Of all the AMR implementation methods this can be called a "revolutionary method" in
the way that it completely eliminates many of the problems or limitations faced in the other
systems and opens the door for new functions, applications and developments to be added to
the system. Figure 1.1 shows the main structure of the Fixed-Network AMR system.
CCU
(Cell Control Unit)
Electricity Meters
CCU
(Cell Control Unit)
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:
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.
5
1.3 Problem and Solution
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 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.
NVR NVR
ADE7756 M20 M20
Database
PIC PIC
ADE7756
93C56
Microcontroller Digital Meter GSM Modem RF Module Host Processor
EEPROM
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.
7
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 is
used 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
8
1.5 Symbols Convention
The following symbols are used throughout this report to present the system
components.
RS232/TTL 93C56
PIC18C452 ADE7756 M20 RF Module Host Computer Electrical Load
Line Driver EEPROM
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 6: Central Office. This chapter introduces a software program that simulates
the Central Office. (Ramadan)
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)
9
System Infrastructure
Our desired goal is simply to establish a communication link and to gather data. The
solution for our problem resides on different hardware components interacting with each other
to achieve this goal. This chapter introduces these hardware modules briefly and mentions
some of the good features they provide to our system*.
RC4/SDI/SDA
RC7/RX/DT
RC6/TX/CK
RB3/CCP2
RD7/PSP7
RD6/PSP6
RD5/PSP5
RD4/PSP4
RD3/PSP3
RD2/PSP2
RC5/SDO
RB2/INT2
RB1/INT1
RB0/INT0
RB7
RB6
RB5
RB4
VDD
VSS
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
PIC18C45 2
10
12
13
14
15
16
17
18
19
20
11
1
2
3
4
5
6
7
8
9
MCLR/VPP
VSS
VDD
RA0/AN0
RC2/CCP1
RA1/AN1
RE0/RD/AN5
OSC2/CLKO/RA6
OSC1/CLKI
RE1/WR/AN6
RA2/AN2/VREF-
RE2/CS/AN7
RC3/SCK/SCL
RA4/T0CKI
RC0/T1OSO/T1CKI
RA3/AN3/VREF+
RD0/PSP0
RD1/PSP1
RC1/T1OSI/CCP2
RA5/AN4/SS/LVDIN
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.
11
* Most of the figures in this chapter are extracted from the datasheets of each hardware module. One can find these datasheets on
the companion CD
The PIC18C452 has 32K bytes of EPORM (Program memory) and 1536 bytes of
RAM (Scratch Board), this relatively huge-program-memory space helps us develop software
with this PIC that can't be developed with others. The PIC18C452 can operate at a frequency
up to 40 MHz.
Software development for the PIC18C452 (and any PIC from any family) can be done
using the MPLAB. The MPLAB is a complete Integrated Development Environment (IDE)
from Microchip, it allows the user to edit, debug, compile, download code and even simulate
from a single user interface. MPASM is a utility that is integrated with the MPLAB; it helps
simulating software behavior before downloading the final machine code to the PIC. The
PICSTART Plus is a serial hardware programmer that can be used within the MPLAB to
program the PIC. The development for the PIC18C452 can be either using the C language or
the assembly language; we have developed all the programs using the assembly language.
In the next subsections we will introduce some of the main features of the PIC18C452
that will help build up the system. The PIC18C452 is the core of our system because it has to
interface almost all other modules.
2.1.1 Interrupts
Interrupt-driven software simplifies development and helps build a more rigid system.
Interrupts can come from many sources (internal and external). We shall be using 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.
12
The PIC (in general) has four registers associated with interrupts. The INTCON
register contains the Global Interrupt Enable bit (GIE), as well as the Peripheral Interrupt
Enable bit (PEIE), the PIE/PIR register pair that enables the peripheral interrupts and displays
the interrupt flag status and the Interrupt Priority Register (IPR) that controls whether the
interrupt source is a high priority or low priority interrupt. There are other registers used to pull
interrupt statuses for other internal and external modules too.
When a valid interrupt occurs, program execution vectors to one of these interrupt
vector addresses and the corresponding Global Interrupt Enable bit (GIE, GIEH, or GIEL) is
automatically cleared (this is done to disable other interrupts from generating another interrupt
signal while servicing the current). In the interrupt service routine, the sources of the interrupt
can be determined by testing the interrupt flag bits. The interrupt flag bits must be cleared
before re-enabling interrupts to avoid infinite interrupt requests. Most flag bits are required to
be cleared by the application software. There are some flag bits that are automatically cleared
by the hardware. When an interrupt condition is met; that individual interrupt flag bit will be
set regardless of the status of its corresponding mask bit.
While like in normal operation one needs to push and pop the WREG and STATUS
registers; this is not necessary in our case because the PIC18C452 automatically pushes and
pops these registers at interrupts.
The “return from interrupt” instruction, RETFIE, can be used to mark the end of the
interrupt service routine. When this instruction is executed, the stack is “popped” and the GIE
bit is set (re-enable interrupts). For more information about interrupts, see the Interrupt Logic
Block Diagram in the PIC18C452 datasheets on the companion CD, it presents a good
understanding of the interrupt login in the PIC18C452.
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.
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.
Data Bus
Interrupt RCIF
SPEN 8
RCIE
USART RECEIVE BLOCK DIAGRAM Data Bus
In the receiver block diagram. The data is received on the RC7/RX/DT pin and drives
the data recovery block. The data recovery block is actually a high speed shifter operating at
x16 times the baud rate; whereas the main receive serial shifter operates at the bit rate, or at
FOSC. To set up an Asynchronous Reception: Initialize the SPBRG register for the
appropriate baud rate. Enable the asynchronous serial port. If interrupts are desired (we will
use the receive interrupt later on); we must set the enable bit RCIE. We enable continuous
reception by setting bit CREN. Flag bit RCIF will be set when reception is complete and an
interrupt will be generated. The PIC goes into an ISR (interrupt service routine). The software
there pulls the RCIF bit and determines the source of the interrupt. Read the 8-bit received
data by reading the RCREG register.
The baud rate is generated by writing to the SPBRG register; the value in this register is
evaluated in a formula along with the clock frequency of the PIC to determine the desired baud 14
rate. Choosing a clock frequency of 3.6864 MHz was made to ensure no percentage of error is
in the desired baud rate. For more information about the USART, refer to the PIC18C452
datasheets on the companion CD.
• 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
2
• Inter-Integrated Circuit (I C): 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:
(SSPSR) and a buffer register (SSPBUF). The SSPSR shifts the Read Write
data in and out of the device, MSb first. The SSPBUF holds SSPBUF reg
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 SSPSR reg
moved to the SSPBUF register. Then the buffer full detect bit, SDI bit0 Shift
Clock
BF (SSPSTAT<0>), and interrupt flag bit, SSPIF, are set. This SDO
double buffering of the received data (SSPBUF) allows the next
byte to start reception before reading the data that was just SS Control
Enable
received. Any write to the SSPBUF register during SS Edge
Select
transmission/reception of data will be ignored, and the write
collision detect bit, WCOL (SSPCON<7>), will be set. When 2
Clock Select
the application software is expecting to receive valid data, the SSPM3:SSPM0
SSPBUF should be read before the next byte of data to transfer SMP:CKE 4
2 (
TMR2 output
)
2
is written to the SSPBUF. Buffer full bit, BF (SSPSTAT<0>), Edge
Select Prescaler TOSC
indicates when SSPBUF has been loaded with the received data SCK 4, 16, 64
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:
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:
For more information about the SPI, refer to the PIC18C452 datasheets on the
companion CD.
2.1.5 Timer0
The Timers modules embedded within the PIC present a simple counter/timer for the
use of counting external pulses or timing a periodic task to happen.
We need to use the timer module because we have to perform certain periodic tasks
(e.g. reading the accumulated energy from the ADE7756). Timer0 helps doing so by
generating an interrupt every 2 seconds (programmable).
Timer mode is selected by clearing the T0CS bit (T0CON register). In timer mode, the
Timer0 module will increment every instruction cycle. Timer0 can be configured as an 8-bit or
a 16-bit timer. To configure the timer as a 16-bit counter, the T08BIT bit (T0CON register)
must be cleared. We are using the timer mode not the counter mode because we want to
generate a periodic interrupt.
16
The TMR0 interrupt flag bit is set when the TMR0 register overflows. When TMR0 is
in 8-bit mode, this means the overflow from FFh to 00h. When TMR0 is in 16-bit mode, this
means the overflow from FFFFh to 0000h. This overflow sets the TMR0IF bit (INTCON
register). The interrupt can be disabled by clearing the TMR0IE bit (INTCON register). The
TMR0IF bit must be cleared in software by the interrupt service routine.
Data Bus<7:0>
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
PIC
entire text as the symbol shown.
17
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.
V.24 interface
M 20 Terminal
Sub-D socket
Power supply
(8-28,8V)
and audio interface
FME
antenna connector SIM card reader
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.
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.
Example: AT+CMGR="12"
This command reads the message with index 12 stored in the default SIM card place.
• 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.
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
5
1 Data Carrier Detect (DCD) 9
2 Receive Data (RXD) 4
8
3 Transmit Data (TXD) 3
4 Data Terminal Ready (DTR) 7
2
5 Ground (GND) 6
6 Data Set Ready (DSR) 1
7 Request to Send (RTS)
8 Clear to Send (CTS) DB9 CONNECTOR
9 Ring Indication (RING)
Figure 2.7: Pin Diagram of the DB9 Connector. The M20 Uses Only the Marked Signals
0011000781214365F70000AA05E8329BFD06
len VP
SCA
(four days) UD ("hello" in 7 bit
type of Destination Adress: UDL default alphabet)
number (Phone-number 1234567)
We shall be using the SMS in the text mode because the data being sent and received is
simple. Security is handled through creating our own GSM protocol; this protocol helps
immune the system and handles errors. The GSM protocol will be mentioned with more details
when we talk about connecting the M20 with the PIC18C452.
SMS is handled using certain AT commands through which we can read and write
messages.
Remember
The Siemens M20 will be referred to throughout
the entire text as the symbol shown. M20
20
2.3 RF Modules
An important goal in our design is to make the system cost effective; we can't put an
M20 Terminal on every node in the system that we wish to get readings from, instead we shall
be using cheap RF modules to link the NCN with the surrounding CCUs. This will reduce cost
and will produce a nice challenge to stand for.
RF modules are specified by their operating frequency, modulation type, maximum data
rate and maximum distance of operation (in both open fields and in buildings). FM
transceivers are considered more stable in operation than AM transceivers, because FM
transceivers are more noise-immune than AM ones.
The frequency spectrum is divided between major systems in almost every country in
the world, e.g. the cellular system in Jordan operates in the frequency range around 900 MHz.
The frequency around 433 MHz can be used by the public (within some standard operating
ranges and conditions), and it is the frequency of operation of the RF modules in our hands.
The 433 MHz is not used in Jordan by any major system. According to the communication
theory, the antenna length of the modules should be (λ/4), that's about 17 cm. No special
antennas where used here because the transmitter and the receiver were too close to each other
for the demo purposes, but if they are to spaced a larger distance; we should consider changing
the antenna type.
The RF modules in our hands are the transmitter FM-RTFQ1-433 and the receiver
FM-RRFQ1-433; they are both made by the company (RF Solutions). They operate on the
433 MHz frequency and the transmitter range is about 75 meters between buildings (which
defines the maximum radius of our Region), this range depends mainly on the type of antenna
used and on the positioning of the module.
2.3.1 FM-RTFQ1-433
It is the transmitter module [6]; it uses a special purpose IC that does the job of
modulating the signal using FSK modulation. The maximum input frequency is 4.6 Kbps. The
transmitter operates at a voltage level of 3V; this was made to reduce power dissipation and to
let the module be used in handheld devices. (This requires some signal level modifications
because all of the other digital circuitry is devices that operate at the 5V voltage level).
In
XTAL PLL
XTAL Power Amp
Oscillator Synthesizer
Out
En
The FM transmitter uses an internal PLL circuit (Phase Locked Loop) to lock on the
carrier frequency of 433 MHz. This PLL requires time to lock to the frequency each time we
transmit, this problem is handled by software; we will mention it in more details when we put
the RF modules and the PIC together.
21
2.3.2 FM-RTFQ1-433
It is the receiver module [6]; it also uses a special purpose IC that does the job of
demodulating the received signal (it uses the TDA 5210, it is an ASK/FSK Single Conversion
Receiver). Unlike the transmitter, the receiver operates at the 5V voltage level; this makes it
ready for connection with the other digital circuitry.
Vcc Vcc
In
PLL
GND Synthesizer GND GND
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.
22
2.4 Analog ADE7756
From Analog Devices, the ADE7756 [4] is a high accuracy electrical power measuring
IC. Output data can be read either from the serial interface (using an MCU) or from the pulse
output (using a pulse counter). The ADE7756 incorporates two second order sigma-delta
ADCs, reference circuitry, and all the signal processing required to perform active power and
energy measurement.
AV DD RESET DVDD DGND
Reset 1 20 DIN
PGA
MULTIPLIER HPF1 MULTIPLIER LPF2 ADE7756 ZX
DV DD 2 19 DOUT V1P
ADC
V1N SAG
AV DD 3 18 SCLK
V1P 4 17 CS APGAIN[11:0]
TEMP APOS[11:0]
SENSOR
V1N 5 ADE7756 16 CLKOUT PHCAL[5:0]
TOP VIEW V2P
V2N 6 15 CLKIN
V2N
ADC O DFC
V2P 7 14 IRQ
AGND 8 13 4k ADE7756 REGISTERS CF
SAG 2.4V AND
REFERENCE SERIAL INTERFACE
REF IN/OUT 9 12 ZX
LPF1 CFDIV[11:0]
DGND 10 11 CF
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).
0110010101
ADC
Currnet LPF Accumulate
Consumed
Instantaneous Average Energy
Power Power
0110010101
ADC
Voltage
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.
23
This basic interpretation was made to simplify the ADE7756 operation. The ADE7756
goes in much more complex steps and process to produce the final output. For more detailed
information about the ADE7756 operation, refer to the datasheets on the companion CD.
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.
Example: if we want to read the active energy register (AENERGY with address 02h),
we simply write 02h to the Communication register, after that we read from the SPI 5 times to
get the 40-bit AENERGY register. This register is a read only register; this means that writing
to this address (Communication register=82h) will result in nothing.
The most important register that determines the operation of the ADE7756 is the
MODE register, it is a 16-bit register that controls most of the features in the ADE7756;
features like enabling or disabling filters and choosing the sampling rate for the ADCs, we can
even choose what output we want (we can read the sampled waveforms of channel 1 and
channel2). Most of the features of the ADE7756 are listed in the next section.
24
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 ADDR: 06H
TEST 1 DISHPF
(TEST MODE SELECTION SHOULD BE SET TO 0) (DISABLE HPF IN CHANNEL 1)
WAVSEL DISLPF2
(WAVE FORM SELECTION FOR SAMPLE MODE) (DISABLE LPF2 AFTER MULTIPLIER)
00 = LPF2 DISCF
01 = RESERVED
10 = CH1 (DISABLE FREQUENCY OUTPUT CF)
11 = CH2 DISSAG
(DISABLE SAG OUTPUT)
DTRT
(WAVE FORM SAMPLES OUTPUT DATA RATE) ASUSPEND
00 = 27.9kSPS (CLKIN/128) (SUSPEND CH1 AND CH2 ADCs)
01 = 14.4kSPS (CLKIN/256) TEMPSEL
10 = 7.2kSPS (CLKIN/512)
11 = 3.6kSPS (CLKIN/1024) (START TEMPERATURE SENSING)
SWRST
SWAP (SOFTWARE CHIP RESET)
(SWAP CH1 AND CH2 ADCs)
CMODE
DISCH2 (CALIBRATION MODE)
(SHORT THE ANALOG INPUTS ON CHANNEL 2)
DISCH1
(SHORT THE ANALOG INPUTS ON CHANNEL 1)
• DC Offset: We could face the problem of DC shifts in the channels after they are
sampled; such shifts add DC errors to the active power and this affects the final
output. We can get rid of this error by simply removing the DC offset from any
channel. The ADE7756 can remove the DC offset from channel 1 by filtering its
output using a high pass filter HPF1. DC offsets can happen either externally or
they can be due to the internal ADCs them self.
•Zero Crossing Indication: the ADE7756 has an output pin (ZX) that alternates
with the each zero crossing of the line voltage, the ZX signal will go logic high on a
positive going zero crossing and logic low on a negative going zero crossing on
Channel 2. Monitoring this pin will detect losses in the line voltage.
• Line Voltage SAG Detection: In addition to the detection of the loss of the line
voltage signal (zero crossing), the ADE7756 can also be programmed to detect
when the absolute value of the line voltage drops below a certain peak value
(specified by the SAGLVL register), for a number of half cycles of the voltage line
(specified by the SAGCYC register). If such condition happens; the ADE7756 will
set the SAG pin low. Monitoring the SAG pin can be used as a warning indication if
there is a fault on the voltage line. Using this feature; we can perform certain actions
as soon as possible (e.g. saving the data on an EEROM, sending a message
indicating a line failure, and so on…).
• Waveform Sampling: The default output from the ADE7756 is the active energy
read from the AENERGY register, yet we can get other outputs from the ADE7756
other than the energy; the ADE7756 can provide us with waveform sampling for
channel 1 and 2 (the current and the voltage signals), the availability of such digital
outputs widens the scope of the data we can provide for the electrical power system,
we can perform DSP on the waveforms and calculate different system parameters
like the active and reactive power, RMS values for the current and voltage, PF and
much more. Waveform samples can be taken by setting the WAVSEL two bits
MODE<14, 13> to select the desired waveform to sample and read at the output. 25
The default value is 00 which means that the output is the active energy, e.g. to read
the waveform samples of the current signal on channel 1; we set the WAVSEL bits
to 10.
Remember
The ADE7756 will be referred to throughout the
entire text as the symbol shown. ADE7756
26
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
CS
INSTRUCTION
SK DECODER
CONTROL LOGIC
CS 1 8 VCC INSTRUCTION AND CLOCK
DI REGISTER GENERATORS
SK 2 7 NC
DI 3 6 NC HIGH VOLTAGE
ADDRESS GENERATOR
DO 4 5 GND REGISTER AND
PROGRAM
TIMER
CS Chip Select 16
SK Serial Data Clock
DI Serial Data Input READ/WRITE AMPS
16 VSS
DO Serial Data Output
GND Ground
DATA IN/OUT REGISTER
NC No Connect 16 BITS
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.
Instruction Meaning
READ Read stored words in the 93C56. The address must be specified
Write Enable, this instruction must be issued at least once before any reading
WEN
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
Write Disable, used to protect the data stored in the chip. This must be used if no
WDS
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
Table 2.1: Instructions of the 93C56
The 93C56 provides more than the basic Read and Write functions; other functions are
used to help maintain the system (like erasing all the data and disabling writing…). Any
function of these is accessed by sending the 93C56 the corresponding instruction data shown in
table 2.2.
27
Since the 93C56 is a 2048-bit memory organized as 16-bit words; the address range for
the whole words stored is 0x00-0x7F. We will be using this address for accessing our data in
the 93C56.
Counting these bits will result in 11 bits or 27 bits (depending on the instruction). Such
numbers of bits don't constitute an integer number of bytes; we need them to constitute an
integer number of bytes because the SPI module of the PIC handles bytes only. This problem is
solved by introducing null zeros before issuing the start bit as shown in the figure. Such
argument is valid also when sending the data filed (not shown in figure).
Start
Bit Opcode Address Field
1 XXXXXXX XXX
Byte1 Byte2
Start
Null Zeros Bit Opcode Address Field
0 0 0 0 01 X X XXXXXXXX
Byte1 Byte2
Figure 2.17: Adapting the Instruction Bits sent to the 93C56 from the PIC18C452 to form an integer
number of bytes
Another issue that needs solving is the incoming data from the 93C56 (the addressed
word), the 93C56 sends a dummy zero bit before sending the 16-bit word to the PIC. This
additional added bit at the beginning of the data string forces the PIC to read 3 bytes from the
st
93C56 (because the total number of bits is 17), the 1 byte holds the dummy bit along with the
7 MSBs of the addressed word, and the reset of the addressed word is in the other 2 bytes. This
problem is handled in a similar manner, but further bits manipulation is involved.
Remember
The 93C56 EEPROM will be referred to throughout
the entire text as the symbol shown. NVR
28
2.6 Supplementary Hardware
We have introduced most of the major hardware modules we are going to use in the
system; however… the system still needs extra hardware to help put all these modules together.
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
+3.25 V
We need a way to change the voltage level of
CMOS/TTL signals to any desired voltage level; this is
2.2K
done by using an open collector buffer (like the 74LS07). Signal U1A
Signal
(0 and 5 V) (0 and 3.25 V)
We just need to connect the open collector to the desired 1 2
This configuration is used only for the input data driving the FM transmitter, we need
not do this for the output data coming from the FM receiver because the receiver outputs a
TTL signal be default. 29
GSM Link
3.1 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.
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. 31
*The concept of Slave PIC is discussed in more details in Chapter 4
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.
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.
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.
Parameter
<index> the index of the message storage location in the
memory. It could be in the range from 1 to 19.
That was the last step in the initializing of M20. Figure 3.2 shows the initialization
process in a glance. The M20 is now ready to receive messages and pass them to the PIC.
M20 PIC
Startup Startup
No
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”.
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:
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.
New
Main
Message
USART
(M20)
No
Yes Yes
Valid SMS No
indication?
Yes
Yes
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.
The number to which the message is sent is either picked from a received message from
the Central Office or either previously stored in the PIC as an emergency number. The
message-type flag determines the body content of the message, whether it is a meter reading
that has just been received or one of the message formats available in the PIC. The message
types and their formats will be clarified in more detail in the protocol section of this chapter.
34
As the command format shows, after the telephone number is entered to the M20 a
termination character is send. The M20 will reply to the PIC with a stream of characters ended
by a “space” character that indicates the M20 readiness to receive the message content. For this
reason, the PIC will wait an interrupt from the M20 and check for the “space” reception before
it starts body writing. When this is done (i.e. the M20 response finishes), the PIC begins to
send the body content characters to the M20 terminal. A (ctrl-Z) character sent from the PIC
will inform the M20 that the body has ended and the PIC will send the load message to the
desired receiver. The message-sending process is reviewed again in figure 3.4.
M20 PIC
Ready Main
Reply with a
Certain Process
“space”
A new SMS
This is the end of
message needs to Reset parameters
the message
be sent
No
USART
(M20) Writing Yes Is it a
interrupt response
“space”?
waited?
Other Yes
Check other
35
3.2 GSM Link Protocol
As a part of the protocol, any message sent from the Central Office to the NCN must be
in the following form
The Mobile Number to Reply to. 2-digit ID for the CCU Extra Optional Data Needed
It Can be of Any Length Requested to do a Task in 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.
As the table shows, three tasks would need extra data. The shapes of these information
are descriped in table 3.2.
For tasks where data readings are aquired, the reply for successful tasks from the NCN
to the Central Office should be in this form
36
Space
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
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.
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:
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.
37
1 Send Task to
CCU 12
Read Energy in CCU 12
@+96277910803 ID1234 121@
PIC
M20 M20
CCU 12
PIC
PIC
NCN
CCU 15 Central Office
(ID 1234)
PIC
M20 M20
CCU 12
PIC
PIC
NCN
CCU 15 Central Office
(ID 1234)
2 Send Task to
CCU 15
Check Status of CCU 15 Link
@+96277910803 ID1234 150@
PIC
M20 M20
CCU 12
PIC
PIC
NCN
CCU 15 Central Office
(ID 1234)
?
Not OK, Send Failed Task Report
@15F@
Something
PIC Wrong M20 M20
CCU 12
PIC
PIC
Can’t Receive NCN
Central Office
CCU 15 the Task! (ID 1234)
M20 M20
PIC
NCN
Central Office
(ID 1234)
M20 M20
PIC
NCN
Central Office
(ID 1234)
38
RF Link
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.
M20
Serial
? PIC
Serial
NCN’s PIC
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.
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 40
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:
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.
Interrupt
Interrupt
Clock
SDO
PIC CS
SDO
PIC
Give Data
Rx
Slav e Master
PIC18C425 PIC18C425
1 40 Stop Data 1 40
2 MCLR/Vpp RB7 39 Reset 2 MCLR/Vpp RB7 39
3 RA0/AN0 RB6 38 3 RA0/AN0 RB6 38
4 RA1/AN1 RB5 37 4 RA1/AN1 RB5 37
5 RA2/AN2/VREF- RB4 36 5 RA2/AN2/VREF- RB4 36
6 RA3/AN3/VREF+ RB3/CCP2 35 6 RA3/AN3/VREF+ RB3/CCP2 35
CS 7 RA4/T0CKI RB2/INT2 34 INT1 7 RA4/T0CKI RB2/INT2 34 INT1
8 RA5/AN4/SS/LVDIN RB1/INT1 33 8 RA5/AN4/SS/LVDIN RB1/INT1 33
9 RE0/RD/AN5 RB0/INT0 32 9 RE0/RD/AN5 RB0/INT0 32
10 RE1/WR/AN6 VDD 31 10 RE1/WR/AN6 VDD 31
11 RE2/CS/AN7 VSS 30 11 RE2/CS/AN7 VSS 30
12 VDD RD7/PSP7 29 12 VDD RD7/PSP7 29
13 VSS RD6/PSP6 28 13 VSS RD6/PSP6 28
14 OSC1/CLKI RD5/PSP5 27 14 OSC1/CLKI RD5/PSP5 27
15 OSC2/CLKO/RA6 RD4/PSP4 26 15 OSC2/CLKO/RA6 RD4/PSP4 26
16 RC0/T1OSO/T1CKI RC7/RX/DT 25 16 RC0/T1OSO/T1CKI RC7/RX/DT 25
17 RC1/T1OSI/CCP2 RC6/TX/CK 24 SDO 17 RC1/T1OSI/CCP2 RC6/TX/CK 24 SDO
SCK 18 RC2/CCP1 RC5/SDO 23 SDI SCK 18 RC2/CCP1 RC5/SDO 23 SDI
19 RC3/SCK/SCL RC4/SDI/SDA 22 CS 19 RC3/SCK/SCL RC4/SDI/SDA 22
20 RD0/PSP0 RD3/PSP3 21 CS 20 RD0/PSP0 RD3/PSP3 21
RD1/PSP1 RD2/PSP2 RD1/PSP1 RD2/PSP2
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.
PIC PIC
Main Main
INT1
Yes
Send data to
USART (RF)
PIC PIC
Other
Check other interrupt Main Main
USART
No INT1
Yes
42
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.
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.
+5 V +3.25 V
LM317
3 2
VIN VOUT
3.25 Volt 5 Volt 1
ADJ
R1
150 C1 1 FM-RTFQ1 6
En EA
LM317 100 uF
2
3 In GND
5
4
GND Vcc
R2
240
RF Tx Regulator
The voltage level supplied by the regulator is determined using the formula
Then using an R2 = 240 Ω and R1 = 150 Ω will lead to a VOUT value of 3.25 volts, which is
acceptable.
Open-Collector Buffer
Using the design shown in figure 4.5 of the Open-Collector Buffer (47LS07), and
benefiting from the already produced 3.25 voltages of the regulator circuit, the maximum
output of the buffer will never exceed the supply voltage level (3.25 V).
43
+3.25 V
R3
2.2K
U1A 1 FM-RTFQ1 6
En EA
PIC Tx (0 and 5 V)
1 2 2 5
3 In GND 4
GND Vcc
74LS07
Transistor Circuit
In a similar manner of the previous approach, the transistor circuit shown in fig 4.5 and
supplied by a Vcc= 3.25 volts will always bring out a maximum of less than 3.25 V-level signal.
VCC = +3 V
9.7 k 9.7 k
V out
2.7 k
Q2
2.7 k
V in Q1
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.
1 FM-RTFQ1 6
En EA
2 5
3 In GND 4
GND Vcc
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 44
4.3 The PIC and the RF Modules
FM1
1 FM-RTFQ1 6
En EA
2 5
3 In GND 4
GND Vcc
PIC18C425
1 40
2 MCLR/Vpp RB7 39
3 RA0/AN0 RB6 38
RA1/AN1 RB5
RF Tx 4
5 RA2/AN2/VREF- RB4
37
36
TX 6 RA3/AN3/VREF+ RB3/CCP2 35 FM2
7 RA4/T0CKI RB2/INT2 34 FM-RRFQ1
RX 8 RA5/AN4/SS/LVDIN RB1/INT1 33
PIC
GND
GND
GND
Dout
RE0/RD/AN5 RB0/INT0
Vcc
9 32
Din
NC
NC
PD
10 RE1/WR/AN6 VDD 31
11 RE2/CS/AN7 VSS 30
VDD RD7/PSP7
11
12
13
14
15
12 29
1
2
3
7
13 VSS RD6/PSP6 28
14 OSC1/CLKI RD5/PSP5 27
RF Rx 15 OSC2/CLKO/RA6 RD4/PSP4 26
16 RC0/T1OSO/T1CKI RC7/RX/DT 25
17 RC1/T1OSI/CCP2 RC6/TX/CK 24
18 RC2/CCP1 RC5/SDO 23
19 RC3/SCK/SCL RC4/SDI/SDA 22
20 RD0/PSP0 RD3/PSP3 21
RD1/PSP1 RD2/PSP2
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.
45
4.4 RF Link Protocol
After the Master PIC of the NCN extracts the SMS message, it should reshape the task
included in this message to a form that can be understood at the CCU side. For this reason, a
simple RF-Link Protocol was developed to be respected in every conversation between the
NCN and any of its CCUs through the RF channel. Any task alert sent from the NCN to the
CCU must take the following format
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@
46
Data Gathering
& Process Controlling
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.
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.
0110010101
ADC
Currnet LPF Accumulate
Consumed
Instantaneous Average Energy
Power Power
0110010101
ADC
Voltage
Communication between the PIC and the ADE7756 is made by requesting something
then taking the response after that; e.g. when the PIC needs to know the consumed energy by
the load; it sends 02h (Read AENEGY register) to the Communication register in the
ADE7756 to indicate so. The ADE7756 then lets the PIC read (one byte at a time) the 40-bit
consumed energy register AENERGY. Refer back to Chapter 2 or to the ADE7756 datasheets
on the companion CD.
Master
PIC18C425
1 40 220V
2 MCLR/Vpp RB7 39
3 RA0/AN0 RB6 38 1
4 RA1/AN1 RB5 37
5 RA2/AN2/VREF- RB4 36
6 RA3/AN3/VREF+ RB3/CCP2 35
7 RA4/T0CKI RB2/INT2 34
8 RA5/AN4/SS/LVDIN RB1/INT1 33 220/12
9 RE0/RD/AN5 RB0/INT0 32
10 RE1/WR/AN6 VDD 31
11 RE2/CS/AN7 VSS 30 SDI 20 1
12 VDD RD7/PSP7 29 SDO 19 DIN RESET 2 20K
13 VSS RD6/PSP6 28 SCK 18 DOUT DVDD 3
14 OSC1/CLKI RD5/PSP5 27 CS 17 SCLK AVDD 4
15 OSC2/CLKO/RA6 RD4/PSP4 26 16 CS V1P 5
SPI 16
17
RC0/T1OSO/T1CKI RC7/RX/DT
RC1/T1OSI/CCP2 RC6/TX/CK
25
24 SDO
15
14
CLKOUT V1N
CLKIN V2P
6
7 10K
SCK 18 RC2/CCP1 RC5/SDO 23 SDI 13 IRQ V2N 8
RC3/SCK/SCL RC4/SDI/SDA SAG AGND
PIC
CS 19 22 12 9
ADE7756 CS 20 RD0/PSP0
RD1/PSP1
RD3/PSP3
RD2/PSP2
21 11 ZX
CF
REF
DGND
10
ADE7756 100K
Figure 5.2: The PIC is interfaced with the ADE7756 through SPI
One of the SPI settings that the PIC must properly set so that valid SPI communication
is to be established is the Idle Clock Polarity; the datasheet of the ADE7756 specifies that the
idle state of the clock of the serial communication (SCK) should be low (0V). This condition is
met with the PIC by setting the SSPCON1<CKP> bit to 0. Other settings are set using this
register and the SSPSTAT register.
The ADE7756 is interfaced in both the NCN and the CCU. The chip-select signal is
used in the SPI connection; this is because the chip select resets the ADE7756 serial interface
and puts it in the communication mode. The chip-select signal for the ADE7756 is active low
(while it is active high for the 93C56). Appendix A contains full schematics for the NCN and
CCU.
93C56
4 3
DO DI
2
CLK M20
RF Module Tx CS
1 Tx Rx
Rx
220V
Slav e Master
PIC18C425 PIC18C425 1
1 40 1 40
2 MCLR/Vpp RB7 39 2 MCLR/Vpp RB7 39
3 RA0/AN0 RB6 38 3 RA0/AN0 RB6 38
4 RA1/AN1 RB5 37 4 RA1/AN1 RB5 37
5 RA2/AN2/VREF- RB4 36 5 RA2/AN2/VREF- RB4 36
6 RA3/AN3/VREF+ RB3/CCP2 35 6 RA3/AN3/VREF+ RB3/CCP2 35
CS 7 RA4/T0CKI RB2/INT2 34 7 RA4/T0CKI RB2/INT2 34
8 RA5/AN4/SS/LVDIN RB1/INT1 33 8 RA5/AN4/SS/LVDIN RB1/INT1 33 220/12
9 RE0/RD/AN5 RB0/INT0 32 9 RE0/RD/AN5 RB0/INT0 32
10 RE1/WR/AN6 VDD 31 10 RE1/WR/AN6 VDD 31
11 RE2/CS/AN7 VSS 30 11 RE2/CS/AN7 VSS 30 CS SDI 20 1
12 VDD RD7/PSP7 29 12 VDD RD7/PSP7 29 SDO 19 DIN RESET 2 20K
13 VSS RD6/PSP6 28 13 VSS RD6/PSP6 28 SCK 18 DOUT DVDD 3
14 OSC1/CLKI RD5/PSP5 27 14 OSC1/CLKI RD5/PSP5 27 CS 17 SCLK AVDD 4
15 OSC2/CLKO/RA6 RD4/PSP4 26 15 OSC2/CLKO/RA6 RD4/PSP4 26 16 CS V1P 5
16 RC0/T1OSO/T1CKI RC7/RX/DT 25 16 RC0/T1OSO/T1CKI RC7/RX/DT 25 15 CLKOUT V1N 6
17 RC1/T1OSI/CCP2 RC6/TX/CK 24 SDO 17 RC1/T1OSI/CCP2 RC6/TX/CK 24 SDO 14 CLKIN V2P 7 10K
SCK 18 RC2/CCP1 RC5/SDO 23 SDI SCK 18 RC2/CCP1 RC5/SDO 23 SDI 13 IRQ V2N 8
19 RC3/SCK/SCL RC4/SDI/SDA 22 CS 19 RC3/SCK/SCL RC4/SDI/SDA 22 12 SAG AGND 9
20 RD0/PSP0 RD3/PSP3 21 CS 20 RD0/PSP0 RD3/PSP3 21 11 ZX REF 10
RD1/PSP1 RD2/PSP2 RD1/PSP1 RD2/PSP2 CF DGND
ADE7756 100K
Figure 5.3: Master PIC in the NCN Interfaces the ADE7756, the Slave PIC and the 93C56 Using SPI. Each device
has its Own Chip Select Signal. There are Other Control Signals between the Master and the Slave not Shown
49
The NCN also uses SPI to interface the Slave PIC (to use its USART to communicate
with the CCUs as explained in Chapter 2) alongside with the ADE7756 and the 93C56. A
separate Chip Select signal is given to each device.
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.
The ADE7756's basic operation mentioned in the beginning is BASIC. There are still
more steps and operations to go through to yield the final output. These steps need
configurations and settings to be made, this is done through writing to some registers in the
ADE7756 (mainly the MODE register). We will mention some of these registers and the values
assigned to each.
• MODE (16-bit): This register controls most of the settings (refer to chapter 2 for
details); we will set it to zero (0000h). This setting does the following: select the output
to be the active energy, the sampling rate to the maximum (CLKIN/128), enable HPF
in channel 1 (to remove any DC offset errors), enable LPF2 after the multiplier (the
result is the average power), and enable frequency output at CF. See the figure for more
information.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ADDR: 06H
TEST 1 DISHPF
(TEST MODE SELECTION SHOULD BE SET TO 0) (ENABLE HPF IN CHANNEL 1)
WAVSEL 00 = LPF2 DISLPF2
(ENABLE LPF2 AFTER MULTIPLIER)
DTRT (WAVE FORM SAMPLES OUTPUT DATA RATE) DISCF
00 = 27.9kSPS (CLKIN/128) (ENABLE FREQUENCY OUTPUT CF)
SWAP DISSAG
(DON'T SWAP CH1 AND CH2 ADCs) (ENABLE SAG OUTPUT)
DISCH2 ASUSPEND
(DON'T SUSPEND CH1 AND CH2 ADCs)
(DON'T SHORT THE ANALOG INPUTS ON CHANNEL 2)
TEMPSEL
DISCH1 (STOP TEMPERATURE SENSING)
(DON'T SHORT THE ANALOG INPUTS ON CHANNEL 1)
SWRST
(USED FOR SOFTWARE RESET)
CMODE
(USED IN CALIBRATION MODE)
• SAGLVL (7-bit): Sag Voltage Level. This register determines at what peak signal level
on channel2 (line voltage) the SAG pin will become active (set to 0). The signal must
remain low for the number of cycles specified in the SAGCYC register before the SAG
pin is pulled low. We set this register to zero or to any small value; this means that the
SAG pin will only go low if the voltage level is zero or very small (i.e. no voltage or line
failure).
50
• SAGCYC (7-bit): Sag Line Cycle Register. This register specifies the number of half
line cycles the signal on channel2 must be below SAGLVL before the SAG output is
activated. We set this register to 06h, indicating that 6 half line cycles must happen
before setting the SAG pin low at a SAG event.
• APOS (12-bit): Active Power Offset Register. This register contains a constant energy
offset that will always be added to the accumulated energy in the AENERGY register,
this register helps in correcting errors that cannot be corrected by any of the other 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.
11 APOS [11:0] 0
CURRENT
CHANNEL LPF2 WAVEFORM [23:0]
23 0
VOLTAGE 39 AENERGY[39:0]
0
CHANNEL ACTIVE POWER
SIGNAL P
4 WAVEFOR
T
CLKIN REGISTER
OUTPUT LPF2
TIME nT
There are still other registers to set. Examples are the CH1OS (channel 1 offset),
CH2OS (channel 2 offset), APGAIN (active power gain) and other registers. Such registers
depend on the calibration process mentioned ahead, this means that the values of such registers
could change from one ADE7756 to another.
All these registers are set by the connected PIC. Again, setting the registers is made by
writing to the Communication register the address of the desired register to write to, then
sending the value to that register. The following listing is part of an assembly code that shows
how to set the MODE register to 0040h (software-reset the ADE7756).
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
Listing 5.1: Assembly Code for Setting the MODE register to 0040h
Although the accumulated energy in the ADE7756 is put in the AENERGY register, we
are reading the RSTENERGY register instead; this register is a copy of the AENERGY
register. The difference is that the RSTENERGY will reset the accumulated energy reading to
zero after each reading process.
The RSTENERGY register can be simply read by writing 03h to the Communication
register. We then keep accumulating this reading in a larger 80-bit register in the PIC. We will
call this new 80-bit register the Total Accumulated Energy register (TAE).
51
At full load (inputs are at max range = 1V); the ADE7756 could take up to 5 seconds to
fill the RSTENERGY 40-bit register (depending on the ADE7756 settings), this means that we
should read the energy in this register before it is full and data is lost; this is done periodically
by the connected PIC every predefined time elapse.
We have set the PIC to interrupt every 2 seconds (using the Timer0 module). On each
interrupt; the PIC will read the energy from the ADE7756 and accumulate the reading into the
TAE register. The following workflow diagram shows part of the PICs operation when
connected to the ADE7756.
ADE7756 PIC
Calculate
Main
Energy
No Comm. Other
Interrupt Check Other
Reg?
Timer0
Yes
Interrupt
Read 40-bit
Ready Data for Add to 80-bit
Active Energy
the PIC TAE Register
(RSTENERGY)
Figure 5.6: the PIC Accumulating the Energy from the ADE7756
Every 40 seconds, the PIC saves the TAE register in the 93C56 EEPROM (along with
other data); this is done to insure no data is lost at a power down situation. At startup, the PIC
loads this stored energy in the 93C56 and keeps accumulating the ADE7756 energy over this
reading.
NVR PIC
Main
Other
Interrupt Check Other
Timer0
No Interrupt
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.
The last step in calculating the energy from the ADE7756 is to convert the value
received from the TAE register into a more meaningful reading of watt-hour energy. This is 52
done by multiplying the output by the energy constant; it has the units of (watt-hour/LSB). The
process of calibrating the ADE7756 will yield this energy constant.
The process of calibrating the ADE7756 is simple; we apply a fixed load (known 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.
Example: If we put a lamp bulb (energy = 60 watt-hour) at the inputs of the ADE7756, and after an hour
we read the TAE register from the PIC and found it to be 000000000013B4BF8E26h, then the Energy
Constant for that particular ADE7756 will be:
Example
• If (at normal operation) we find that the TAE register reads 0000000004B4ACE7AF32h, then the
consumed energy can be found like this:
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:
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
53
Addresses J and K are not registers on the ADE7756, they are registers on the PIC. J is
the 2 byte register the user stores his data in, and K is the 10 bytes TAE register. Any address
entered outside the above range will be ignored. Please note that the calibration program is case
sensitive.
Example: if you want to set the MODE register to 1808h, just type 1808, W, 6.
Example: if you want to read the SAGCYC register, just type R, F.
The data going to the ADE7756 is right justified; this means that if you enter 1506, W,
F. this will fill the SAGCYC register with the value 06h. The schematic diagram for the
calibration hardware is shown in appendix A.
The PIC18XXXX family is the newest family of MCUs from Microchip, and support
for this family is not yet fully complete. Older MCU families (like the PIC17XXXX) have full
support from Microchip. Support includes publishing libraries to be used with the MCU (like
the math libraries we need). Our PIC18C452 doesn't have any library from any kind, and
trying to build a toolbox such as the math library from scratch would be tedious and very hard.
Yet, the power factor can still be found using the PIC and the ADE7756 with no real
DSP involved. This is done by finding the phase difference between the current and voltage
signals going into the ADE7756.
We shall use a simple algorithm that scans for the zero crossing of both the current and
the voltage. When the zero crossing of one channel is found; we start a counter that stops at the
zero crossing of the other channel. The value in this counter represents the phase difference
between the two channels. This counter is converted to a phase difference in degrees, and the
cosine of this phase difference is calculated to be the power factor.
Start Counter
Stop Counter
Current Voltage
(Channel1) (Channe2)
We can read the current and voltage signals from the ADE7756 using WAVEFORM
register. The data source sampled in this register is selected by data bits 14 and 13 in the Mode
Register (WAVSEL bits).
54
The WAVEFORM register is a 24-bit two's complement register; this means that the
24th bit determines whether the total value in the register is positive (0) or negative (1). This is
how we scan for zero crossings in each signal; we just keep monitoring the last bit in the
waveform.
The scanning process here is not made as the scanning process for a new incoming
message from the M20 (i.e. to store the whole data in a memory bank then scan it); this is
because the number of samples to store here is very large and there is no enough memory space
to save them all. Instead, we will do real time scanning for the samples; each sample (from each
channel) will be scanned immediately after it is read.
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.
PIC18C425
1 40
2 MCLR/Vpp RB7 39
3 RA0/AN0 RB6 38
4 RA1/AN1 RB5 37
5 RA2/AN2/VREF- RB4 36
6 RA3/AN3/VREF+ RB3/CCP2 35
7 RA4/T0CKI RB2/INT2 34
8 RA5/AN4/SS/LVDIN RB1/INT1 33
9 RE0/RD/AN5 RB0/INT0 32
10 RE1/WR/AN6 VDD 31
RE2/CS/AN7 VSS
11
VDD RD7/PSP7
30 A
12 29 4 3 2 1
13 VSS RD6/PSP6 28
OSC1/CLKI RD5/PSP5
14
OSC2/CLKO/RA6 RD4/PSP4
27 B
15 26
16 RC0/T1OSO/T1CKI RC7/RX/DT 25
17 RC1/T1OSI/CCP2 RC6/TX/CK 24
RC2/CCP1 RC5/SDO
18
RC3/SCK/SCL RC4/SDI/SDA
23 C
19 22
20 RD0/PSP0 RD3/PSP3 21
RD1/PSP1 RD2/PSP2
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.
For the sake of demonstration; we will wirelessly control a switch connected to a regular
DC lamp bulb. The switch is a transistor-based switch were a CMOS signal from an I/O port of
the PIC is going to control the switching. See the figure.
55
+5V
PIC18C425
1 40
2 MCLR/Vpp RB7 39
3 RA0/AN0 RB6 38
4 RA1/AN1 RB5 37
5 RA2/AN2/VREF- RB4 36
6 RA3/AN3/VREF+ RB3/CCP2 35
7 RA4/T0CKI RB2/INT2 34
8 RA5/AN4/SS/LVDIN RB1/INT1 33
9 RE0/RD/AN5 RB0/INT0 32
10 RE1/WR/AN6 VDD 31 LAMP 1
11 RE2/CS/AN7 VSS 30
12 VDD RD7/PSP7 29
13 VSS RD6/PSP6 28
14 OSC1/CLKI RD5/PSP5 27
15 OSC2/CLKO/RA6 RD4/PSP4 26
16 RC0/T1OSO/T1CKI RC7/RX/DT 25 C945
17 RC1/T1OSI/CCP2 RC6/TX/CK 24 2.7K
18 RC2/CCP1 RC5/SDO 23
19 RC3/SCK/SCL RC4/SDI/SDA 22 2N3053
20 RD0/PSP0 RD3/PSP3 21
RD1/PSP1 RD2/PSP2
This DC lamp needs about 300 mA of current to lighten, thus a special transistor
(2N3053) is used. This transistor handles large currents than the usual ones. Another regular
BJT transistor is used as the driving base for the above transistor, thus forming a Darlington
pair. The diodes are used because the lamp operates at a lower voltage level than the 5V.
The Central Office controls the switch wirelessly (as everything else), but when a power
failure happens and no power supply is feeding the digital circuits, the status of this switch is
saved in the 93C56, and in the next startup the switch will be set to the last state the Central
Office desired.
As simple this switch-control process seems; it forms the basic idea for controlling a
state of an AC line at the customer side.
56
Central Office
6.1 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.
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.
Nokia 8210 is not a GSM modem (it cannot be accessed directly with regular AT
commands). An interpreting medium was needed to establish the connection with the mobile.
This problem was solved using the Nokia Data Suite; this utility installs a virtual modem (with
a new COM Port number) on the Host Computer. This virtual modem is the interpreting
medium used to communicate with the Nokia 8210 (Connected to a physical port).
Virtual Physical
COM COM
Nokia Specific
Central AT Commands
Nokia Data Commands
Office Suite
Nokia 8210
Figure 6.2: Nokia Data Suite is used to Communicate with the Nokia 8210
With the Data Suite; the 8210 can be accessed using special AT commands (which are
very similar to those used with the M20, this is because AT commands are standardized).
Menu Bar, Use it to exit the User Control Area, here the user
program or to see the Help About performs actions and sees results
We will introduce the main features of the Central Office system as walkthrough steps.
We shall introduce the following features:
Figure 6.4: Initializing the Central Office from the Settings Tab
5. Click the button (it will be enabled once a COM port number is selected)
*If the COM port is opened (the status bar indicates so), all controls in the system will be
enabled. Otherwise, a message pops showing that the desired port can't be opened.
6. To initialize the Nokia 8210; in the Mobile Settings click the button, this
will software-initialize the Nokia 8210 (and the Nokia Data Suite) by sending specific
AT commands in a row to the mobile (this is similar to initializing the M20 with the
PIC). Please note that not clicking this button will result in invalid messages read from
the mobile. The system is now partially initialized, but there are still more steps to go
7. The Task Reply Number field must be filled with a valid mobile number (this is the
number to which the NCN will reply)
8. the Default Message Index combo box determines the index of the incoming message to
read (the Nokia 8210 doesn't give indication for new messages arrival like the M20, so
the user has to manually click a "Read Task" button when a message arrives. This
scenario was faced because of the use of the Nokia 8210 and it will not happen if an
M20 was used)
Now the Central Office is fully initialized and ready to Send Tasks (our next section)
60
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.
The Send Task group box holds all task information that must be sent to an NCN
(these information makeup the SMS that will be sent to the NCN). All tasks to send are sent
from here.
1. Specify the NCN Security Code in its respective field. It is a 6-digit code
2. Specify the NCN Mobile Number in its respective field; it is the number of the M20 at
the NCN side. It is a numeric field of any length
3. Specify the CCU ID in its respective field; it is the ID for the specific CCU the user
wishes to access. It is a 2-digit ID
4. From the Required Task combo box, select the required task to perform. Each selected
task opens its own specific task box for the user (this task box contains either notes
about the task or further information needed to perform the task). figure 6.6 shows all
tasks available along with their task boxes
5. After selecting the required task and specifying any further information needed by that
task (if any); the task is now ready to be sent to the targeted NCN. Sending the task is
made by simply clicking the Send Task button (you won't miss it)
Please note that all controls in the Central Office have validation criteria assigned to
them, e.g. the user can't input 07788G4717 in the NCN Mobile Number field, the software
will not allow him to send the task unless the number field is corrected and filled with numbers
only. This applies for most of the fields in the system.
61
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:
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).
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
62
scanning the message. The output of this scanning process is displayed in the Receive Tasks
group box. The figure below shows a valid response for the task sent in the previous section.
The Received Task Details shows the details of the message received; it shows the CCU
ID, Task Index and the Extra Data (if any) received from the NCN unit. The example shown
in the figure above indicates that CCU 55 has received the task of switching on the line and it
did perform this task.
The Received Task Details also indicates an unrecognized received message or a 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:
The message analysis procedure is simple and straightforward. In a real system scenario;
the output of this message analysis process should drive other data-based subroutines and
procedures to maintain the CCUs' data and transactions.
63
All valid analyzed tasks are stored in a log file for demonstration only. This log file can
be viewed from the tab.
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
64
If it helps to overtake the communication between the Central Office and the mobile to
solve errors, then the user can use the "Send Custom AT Command" feature in the Mobile
Setting group box. This lets the user to force specific AT commands to be sent to the mobile.
Emptying unwanted messages avoids errors due to messages waiting in queues to arrive
to the mobile.
65
Total System Implementation
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.
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.
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.
68
To Main
PIC
Master PIC
NVR
Main
No
Send interrupt
Receive Data from
INT1 to Master to
the Mater PIC
Read this data
Send Message (i) To Main
Yes
Send Data to Give Data
USA RT (RF) Through SPI Ready Send
Read New Run Protoc ol
Again Message(i) Check Message
69
Reply to NCN
through RF
Transmitter
Transmitter
Disable RF
Enable RF
Receive Message
New Task
Perform the
from the RF
acquired
Task
USART
PIC
CCU PIC
Interrupt
Main
Timer0
93C56 EEPROM
Add to 80-bit
TAE Register
Register in
Store TAE
NVR
Passed?
Yes
40 Sec
No
To Main
Active Energy
(RSTENERGY)
Send 0x03 to
Read 40-bit
Comm. Reg.
Check Comm.
Energy
Yes
Register
Comm.
the PIC
Reg?
ADE7756
No
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.
70
7.3 The System Through an Example
Our scenario can be presented as follows:
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?!
71
@151@
AT+CMGS=”077910803"
@077884717 ID1234 151@
Cellular Base
Station
PIC PIC PIC ADE7756
M20
RF Module RF Module ADE7756 Electrical Load
Nokia 8210 M20 Master Slave PIC
@151 00000037F2ED24B56B54@
72
Conclusion
We have chosen to implement the Fixed-Network AMR system because it seemed the
best solution for the problem of wireless electricity metering. We tried to give as much as
possible to open an eye on the endless capabilities of such system.
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.
• 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.
• Software Management: The work flowchart for the Master PIC in the NCN unit was
full of interrupts and interconnected branches of software modules. Developing such a
complex structure was hard especially because Assembly language was used. However,
even if the development language was a higher-level language (e.g. C) and hence easier
to manage; the size of the final hex dump file could be larger and could not fit the PIC's
memory space (we are already using 2/3 the PIC's memory).
74
8.3 Further Suggestions
We have introduced a basic design of a Fixed-Network AMR system. Yet there are
more ideas and suggestions that can be integrated within this design.
The figure below shows one simple design using the 7805 voltage regulator and a
regular 5V rechargeable battery.
+12V 7805 +5V Power Supply
1 3 Feeding the
VIN VOUT
System
GND
R
2
RECHARGEABLE BATTERY
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).
Examples are many; water and gas consumption, real time security alarm systems,
wireless control systems…
75
References
References:
77
Appendix A
Tx Rx
+5 V
+3.25 V 05 05 05 +5 V
LM317
3 2 FM4
VIN VOUT FM-RRFQ1
1
ADJ 100 uF
Vcc
GND
Din
GND
GND
NC
NC
Dout
PD
93C56
4 3 150 1 FM-RTFQ1 6
DO DI En EA
1
2
3
7
11
12
13
14
15
2 2 5
CLK 3 In GND 4
1 GND Vcc
CS
240 100 uF
100 uF
Enable Tx
PIC18C425 PIC18C425
2.7K 1 40 1 40 300 LED
2 MCLR/Vpp RB7 39 2 MCLR/Vpp RB7 39
3 RA0/AN0 RB6 38 3 RA0/AN0 RB6 38
4 RA1/AN1 RB5 37 100 4 RA1/AN1 RB5 37
5 RA2/AN2/VREF- RB4 36 5 RA2/AN2/VREF- RB4 36
C945 100 6 RA3/AN3/VREF+ RB3/CCP2 35 6 RA3/AN3/VREF+ RB3/CCP2 35
7 RA4/T0CKI RB2/INT2 34 7 RA4/T0CKI RB2/INT2 34
+5V RA5/AN4/SS/LVDIN RB1/INT1 RA5/AN4/SS/LVDIN RB1/INT1
8 33 8 33
2N3053 9 RE0/RD/AN5 RB0/INT0 32 VCC 9 RE0/RD/AN5 RB0/INT0 32 VCC
10 RE1/WR/AN6 VDD 31 10 RE1/WR/AN6 VDD 31
11 RE2/CS/AN7 VSS 30 11 RE2/CS/AN7 VSS 30
12 VDD RD7/PSP7 29 CS 12 VDD RD7/PSP7 29
VSS RD6/PSP6 93C56 VSS RD6/PSP6
0.1 uF
0.1 uF
100 uF
100 uF
LAMP 13 28 13 28
14 OSC1/CLKI RD5/PSP5 27 14 OSC1/CLKI RD5/PSP5 27
15 OSC2/CLKO/RA6 RD4/PSP4 26 15 OSC2/CLKO/RA6 RD4/PSP4 26
3.6864 Mhz 16 RC0/T1OSO/T1CKI RC7/RX/DT 25 3.6864 Mhz 16 RC0/T1OSO/T1CKI RC7/RX/DT 25
17 RC1/T1OSI/CCP2 RC6/TX/CK 24 SDO Reset Slave 17 RC1/T1OSI/CCP2 RC6/TX/CK 24
18 RC2/CCP1 RC5/SDO 23 SDI 18 RC2/CCP1 RC5/SDO 23
OFF RC3/SCK/SCL RC4/SDI/SDA RC3/SCK/SCL RC4/SDI/SDA
1 2 3 4 19 22 Disable Receive 19 22
20 RD0/PSP0 RD3/PSP3 21 to Salve Interrupt1 20 RD0/PSP0 RD3/PSP3 21
20 pF
20 pF
20 pF
20 pF
CS Slave
CS ADE7756
SCK
ON
to MasterInterrupt1
U5
13 12
8 R1IN R1OUT 9
R2IN R2OUT 220V
M20 11 14
10 T1IN T1OUT 7 1
SIEMENSE 1 uF T2IN T2OUT
1
C1+
+
1 uF 3 4.7 uF
1 4 C1-
Tx C2+
+
5
2 2 C2- 10K 220/12
Rx V+ U2
+
6
3 4 1 uF V- ADE7756
GND Antenna 16 20 1 20K
VCC VCC DIN RESET VCC
15 19 2
+ TC232 18 DOUT DVDD 3
1 uF 17 SCLK AVDD 4
CS V1P
16
15 CLKOUT V1N
5
6
NCN Schematic
1 uF 14 CLKIN V2P 7
+
3.6864 Mhz 13 IRQ V2N 8
12 SAG AGND 9
ZX REF
33 pF
11
CF DGND
10
10K
Diagram
33 pF
100K
300
VCC
79
Tx Rx
+5 V
+3.25 V 05 05 05 +5 V
LM317
3 2 FM4
VIN VOUT FM-RRFQ1
1
GND
GND
GND
Dout
ADJ
Vcc
100 uF
Din
NC
NC
PD
150 1 FM-RTFQ1 6
En EA
11
12
13
14
15
1
2
3
7
2 5
3 In GND 4
+5V GND Vcc
240 100 uF
100 uF
Enable Tx
ChildPIC
LAMP 1 300 LED
PIC18C425
1 40
2 MCLR/Vpp RB7 39
3 RA0/AN0 RB6 38
4 RA1/AN1 RB5 37
RA2/AN2/VREF- RB4
5
RA3/AN3/VREF+ RB3/CCP2
36 A
C945 100 6 35 4 3 2 1
7 RA4/T0CKI RB2/INT2 34
RA5/AN4/SS/LVDIN RB1/INT1
2N3053 2.7K 8
RE0/RD/AN5 RB0/INT0
33 B
9 32 VCC
10 RE1/WR/AN6 VDD 31
11 RE2/CS/AN7 VSS 30
0.1 uF
100 uF
VDD RD7/PSP7
12
VSS RD6/PSP6
29 3
DI DO
4 C
13 28
14 OSC1/CLKI RD5/PSP5 27 2
15 OSC2/CLKO/RA6 RD4/PSP4 26 CLK
3.6864 Mhz 16 RC0/T1OSO/T1CKI RC7/RX/DT 25 1
17 RC1/T1OSI/CCP2 RC6/TX/CK 24 CS
SCK 18 RC2/CCP1 RC5/SDO 23
19 RC3/SCK/SCL RC4/SDI/SDA 22 93C56
20 pF
20 pF
20 RD0/PSP0 RD3/PSP3 21
RD1/PSP1 RD2/PSP2
CS 93C56
CS ADE7756 220V
4.7 uF
10K
U2 220/12
ADE7756
20 1
DIN RESET VCC
19 2
18 DOUT DVDD 3 20K
17 SCLK AVDD 4
16 CS V1P 5
CCU Schematic
15 CLKOUT V1N 6
14 CLKIN V2P 7
3.6864 Mhz 13 IRQ V2N 8
12 SAG AGND 9
ZX REF
Diagram
11 10
CF DGND
33 pF
33 pF
10K
300
100K
VCC
80
U4
300 LED
PIC18C425
1 40
2 MCLR/Vpp RB7 39 220V
3 RA0/AN0 RB6 38
4 RA1/AN1 RB5 37 1
5 RA2/AN2/VREF- RB4 36
100 6 RA3/AN3/VREF+ RB3/CCP2 35
7 RA4/T0CKI RB2/INT2 34
8 RA5/AN4/SS/LVDIN RB1/INT1 33
9 RE0/RD/AN5 RB0/INT0 32 VCC
10 RE1/WR/AN6 VDD 31
11 RE2/CS/AN7 VSS 30 4.7 uF
12 VDD RD7/PSP7 29
VSS RD6/PSP6
0.1 uF
100 uF
13 28
14 OSC1/CLKI RD5/PSP5 27 10K
15 OSC2/CLKO/RA6 RD4/PSP4 26 U2
3.6864 Mhz 16 RC0/T1OSO/T1CKI RC7/RX/DT 25 ADE7756 220/12
17 RC1/T1OSI/CCP2 RC6/TX/CK 24 20 1
RC2/CCP1 RC5/SDO DIN RESET VCC
18 23 19 2
19 RC3/SCK/SCL RC4/SDI/SDA 22 18 DOUT DVDD 3
20 RD0/PSP0 RD3/PSP3 21 17 SCLK AVDD 4 20K
20 pF
20 pF
RD1/PSP1 RD2/PSP2 16 CS V1P 5
15 CLKOUT V1N 6
14 CLKIN V2P 7
3.6864 Mhz 13 IRQ V2N 8
12 SAG AGND 9 10K
11 ZX REF 10
CF DGND
33 pF
33 pF
100K
U5
13 12
8 R1IN R1OUT 9
R2IN R2OUT 300
11 14
10 T1IN T1OUT 7
1 uF T2IN T2OUT
1
C1+
+
1 uF 3 VCC
4 C1-
C2+
+
5 1
2 C2- 6
V+
+
6 2 PC Rx
1 uF V- 7
16 3 PC Tx
VCC VCC
15 8
ADE7756 Calibration
+ TC232 4
1 uF 9
5 GND Schematic Diagram
+ 1 uF
PC Serial Connector DB9
81