You are on page 1of 74

Project (E) 448

Integration of a 3-phase energy meter and


data modem for online data visualisation

Candidate: EC Brink (15714101)


Study Leader: JM Strauss

November 2013

Report submitted in partial fulfilment of the requirements of the module Project (E) 448
for the degree Baccalaureus in Engineering in the Department of Electrical and
Electronic Engineering at the University of Stellenbosch
Acknowledgements

The author would like to thank:

Mr JM Strauss for his insights, guidance and support,

Mr Thinus Booysen for his contribution and support,

MTN and Trinity Telecoms, who enabled and supported this work with their technical and
financial assistance,

Mr Ashley Cupido for manufacturing the printed circuit board,

Mr Arendse for his excellent soldering work,

My family for their moral and financial support.

ii
Plagiarism Declaration
I, the undersigned, hereby declare that the work contained in this report is my own original
work unless indicated otherwise.

Signature: Date:

iii
Executive Summary
Over the last decade the demand for electricity has shown significant growth worldwide.
This increase in demand has resulted in the rise of electricity tariffs to an alarming level.
The aim of this project is the development of a hardware based environment capable of
extracting data from an electricity meter and passing this data to a cellular data modem. The
data modem then passes this data to a server platform, which is responsible for depicting
the information graphically on the internet. With the widespread implementation of such
systems important information can be presented to electricity consumers and suppliers
alike. The project made use of extensive hardware and software development to create a
microcontroller environment capable of achieving the aim presented. The system was tested
and verified to perform adequately. The system was found to be a viable option for use in
electricity consumption information reporting.

iv
Uitvoerende Opsomming
Tydens die laaste dekade het die aanvraag vir elektrisiteit wêreldwyd merkwaardige groei
getoon. Hierdie groei in aanvraag het gelei tot bekommerende stygings in die tariewe van
elektrisiteit. Die doel van hierdie projek is die skep van ‘n hardeware omgewing met die
vermoë om data vanaf ‘n elektrisiteitsmeter te onttrek en daarna die data na ‘n sellulêre
data modem te stuur. Die data modem stuur dan die data na ‘n bediener platform wat
verantwoordelik is om die inligting grafies op die internet te vertoon. Deur die
wydverspreide implementasie van sulke stelsels kan beide elektrisiteitsverbruikers en
voorsienners van belangrike inligting verskaf word. Die projek maak gebruik van uitgebreide
hardeware en sagteware ontwikkeling om ‘n mikroverwerker omgewing te skep wat in staat
is om die voorgeskrewe doel te bereik. Die stelsel is getoets en daar is geverifieer dat dit
aanvaarbaar uitvoer. Daar is gevind dat die stelsel ‘n lewensvatbare opsie is vir terugvoer oor
elektrisiteitsverbruik.

v
Contents
Acknowledgements................................................................................................................ ii
Plagiarism Declaration .......................................................................................................... iii
Uitvoerende Opsomming ....................................................................................................... v
List of figures .......................................................................................................................viii
List of tables .......................................................................................................................... ix
List of abbreviations ............................................................................................................... x
1. Introduction ................................................................................................................... 1
1.1. Project Background .................................................................................................. 1
1.2. Problem Description ................................................................................................ 1
1.3. Project Aims............................................................................................................. 2
1.4. Report Summary ...................................................................................................... 2
2. Background Study .......................................................................................................... 3
3. Technology Overview ..................................................................................................... 4
3.1. Introduction ............................................................................................................. 4
3.2. Key Components ...................................................................................................... 4
3.2.1. Electricity Meter ............................................................................................... 4
3.2.2. Data Modem ..................................................................................................... 6
3.2.3. SMART Platform ............................................................................................... 7
3.3. Component Integration ........................................................................................... 8
4. Hardware Design ............................................................................................................ 9
4.1. Introduction ......................................................................................................... 9
4.2. System Overview .................................................................................................. 9
4.3. Component Selection and Design .......................................................................... 10
4.3.1. Microcontroller............................................................................................... 10
4.3.2. RS232 Line Drivers .......................................................................................... 12
4.3.3. Optical Isolation .............................................................................................. 14
4.3.4. Power supply .................................................................................................. 21
4.3.5. LEDs ................................................................................................................ 22
5. Software Design ........................................................................................................... 23
5.1. Introduction ........................................................................................................... 23
5.2. PC Software Design ................................................................................................ 24
vi
5.2.1. Software structure .......................................................................................... 24
5.2.2. Software Description and Evaluation .............................................................. 25
5.3. Microcontroller Software ....................................................................................... 30
5.3.1. Software Overview and Structure ................................................................... 30
5.3.2. Software Description and Evaluation .............................................................. 32
6. Measurements and Results .......................................................................................... 39
Hardware ......................................................................................................................... 39
Complete System ............................................................................................................. 40
7. Conclusion and Recommendations............................................................................... 43
Appendix A: Project Planning Schedule ................................................................................ 45
Appendix B: Project Specification ......................................................................................... 46
Appendix C: Outcomes Compliance ..................................................................................... 47
Appendix D: Software Protocol Description ......................................................................... 49
D.1. Introduction ........................................................................................................... 49
D.2. IEC62056 Protocol ................................................................................................. 49
D.2.1. Character Transmission................................................................................... 49
D.2.2. Data transmission protocol ............................................................................. 50
D.2.3. Calculation of the block check character ......................................................... 52
D.2.3. AT and AT+AWTDA Commands ......................................................................... 53
Appendix E: Enermax Instantaneous Register Memory Layout ............................................. 56
Appendix F: Full Circuit Schematics ...................................................................................... 59
Appendix G: PCB Layout ....................................................................................................... 62
Works Cited ......................................................................................................................... 63

vii
List of figures
Figure 1: Enermax Electricity Meter ....................................................................................... 5
Figure 2: Block Diagram of GL6100 Modem [7] ...................................................................... 6
Figure 3: Overview of SMART system [8] ................................................................................ 7
Figure 4: Component Integration [6], [7], [8] .......................................................................... 8
Figure 5: System Overview ..................................................................................................... 9
Figure 6: MAX232 IC Overview [11] ...................................................................................... 13
Figure 7: Optical Isolator Design A........................................................................................ 15
Figure 8: Optocoupler Circuit ............................................................................................... 16
Figure 9: Normalised CTR [12] .............................................................................................. 17
Figure 10: Simulated Transient Response of Design A .......................................................... 18
Figure 11: MAX 250 [13]....................................................................................................... 19
Figure 12: MAX 251 [13]....................................................................................................... 19
Figure 13: Block diagram of Optical Isolator Design B ........................................................... 20
Figure 14: Flow chart of parseInstant ................................................................................... 27
Figure 15: PC Software Output ............................................................................................. 29
Figure 16: Flow Chart of modem_Send function .................................................................. 34
Figure 17: Flow Chart of modem_Upload function ............................................................... 35
Figure 18: Flow Chart of Main function ................................................................................ 38
Figure 19: Optical Isolator at 9.6kHz..................................................................................... 39
Figure 20 Optical Isolator at 56kHz....................................................................................... 39
Figure 21: RS232 line driver at 9.6kHz .................................................................................. 40
Figure 22: Rs2322 line driver at 56kHz ................................................................................. 40
Figure 23: Phasor Diagram Gadget ....................................................................................... 41
Figure 24: Temperature Gadget ........................................................................................... 41
Figure 25: Frequency Gadget ............................................................................................... 42
Figure 26: Other Instantaneous Registers Gadgets ............................................................... 42
Figure 27: Example Data Uploaded to SMART Platform........................................................ 42
Figure 28: calculation of the Block Check Character [3] ........................................................ 52
Figure 29: Schematics Part 1 ................................................................................................ 59
Figure 30: Schematics Part 2 ................................................................................................ 60
Figure 31: Schematics Part 3 ................................................................................................ 61

viii
List of tables
Table 1: Microcontroller Design Constraints ........................................................................ 11
Table 2: TTL versus RS232 Voltage Levels [10] ...................................................................... 12
Table 3: Typical Values for Optocoupler Circuit [9], [12] ....................................................... 17
Table 4: Required Transformer Parameters [13], [14] .......................................................... 21
Table 5: Total Current Calculation ........................................................................................ 21
Table 6: PC Software Structure............................................................................................. 24
Table 7: Microcontroller Software Structure ........................................................................ 31
Table 8: Truth table of flag variables .................................................................................... 33
Table 9: Practical Measurements ......................................................................................... 40
Table 10: IEC52056 Character Transmission [3] .................................................................... 49
Table 11: IEC62056 Request Message Content Description [3] ............................................. 50
Table 12: IEC62056 Identification Message Content Description [3] ..................................... 51
Table 13: Acknowledgement Message Content Description [3] ............................................ 51
Table 14: Programming Message Content Description [3] .................................................... 52
Table 15: Notable AT Commands [16] .................................................................................. 53
Table 16: Description of AWTDA data message contents [17] .............................................. 54
Table 17: Description of AWTDA data message substring content [17] ................................ 54
Table 18: Messages from modem [17] ................................................................................. 55
Table 19: Enermax Instantaneous Register Memory Layout ................................................. 58

ix
List of abbreviations
AT Hayes Command Set
CTR Current Transfer Ratio
DC/DC DC to DC
EEPROM Electrically Erasable Programmable Read Only Memory
GPL General Public License
GPRS General Packet Radio Service
GSM Global System for Mobile communications
IC Integrated Circuit
IDE Integrated Development Environment
IEC International Electrotechnical Commission
LED Light Emitting Diode
OBIS Object Identification System
PC Personal computer
PSTN Public Switched Telephone Network
RTC Real Time Clock
TQFP Thin Quad Flat Pack
TTL Transistor–Transistor Logic
UART Universal Asynchronous Receiver/Transmitter
Universal Synchronous/Asynchronous
USART Receiver/Transmitter
USB Universal Serial Bus

x
1. Introduction

1.1. Project Background

Asset management is defined as the management of physical assets, with the intent of
optimising processes and making better decisions regarding the performance and
profitability of these assets. In the context of this project, asset management refers
specifically to the online monitoring and control of an individual physical asset or system. [1]

With the widespread introduction and development of cellular communication


infrastructure throughout most of the developed world, wireless asset management has
become simple and cost-effective. The application of cellular data to asset monitoring has
resulted in convenient, effective, and affordable asset monitoring solutions.

Energy meters are ideal candidates to make use of this wireless asset management
technology. These meters are normally troublesome to manage, as they are vastly
distributed geographically, and often have limited network capability. The use of wireless
cellular communications solves this problem in areas where cellular infrastructure is
available.

1.2. Problem Description

In South Africa the development of electricity meter monitoring solutions is especially critical
at the moment. Electricity usage has increased considerably over the last few years and this
has resulted in an increased electricity tariff of 8% per year for the next 5 years [2]. The
effective utilisation of electrical energy has become a major concern for consumers and
power distributors alike. The need for information about the country’s energy consumption
is of great priority.

By remote monitoring of electricity meters, consumers and power distributors will be


provided with detailed information about the current energy consumption for a specific
location. This allows the relevant party to make informed decisions about the location’s
electricity consumption. Consumers will be aided in minimising their energy costs and
spotting abnormalities such as electrical faults, and electricity distributors will have much
more data available for use in their energy management and distribution strategies.

1
It is necessary to integrate electricity meters with asset management solutions to achieve
the goal of better energy utilisation. This project attempts to create a platform that is
capable of aiding this goal.

1.3. Project Aims

The project objective is to develop a hardware based environment capable of extracting data
from an electricity meter and passing this data on to a cellular modem. The data should then
be accessible from the internet and displayed in a user-friendly manner. The device should
be able to function independently.

1.4. Report Summary


This report discusses the implementation of the system described by the previous
subsection.

Chapter 1 one provides an introduction to the problem and states the aims for the project.

Chapter 2 provides a background study and shows the relevant research that was done
before the project was developed.

Chapter 3 gives a broad overview of the major components used in the project and the
overall integration strategy.

Chapter 4 explains the hardware development and gives insight into the hardware designs.

Chapter 5 explains the software development and explains the software functions in detail.

Chapter 6 shows the results for the system as a whole.

Chapter 7 discusses the conclusions that were made, and states recommendations for future
work.

2
2. Background Study

The first aim of the background study was to become acquainted with the standard
protocols that electricity meters and use for communication. It quickly became evident that
the majority of electricity meters available used the IEC-62056 set of protocol standards.

The following IEC documents were studied:

IEC 62056-21:2002 Electricity metering – Data exchange for meter reading, tariff and load
control – Part 21: Direct local data exchange.

IEC 62056-61:2006 Electricity metering – Data exchange for meter reading, tariff and load
control – Part 61: Object Identification System (OBIS)

Part 21 of IEC 62056 describes hardware and protocol specifications for local meter data
exchange [3]. A synopsis of the parts of this document relevant to the project can be found
in appendix D.

Part 61 of IEC 62056 describes the object identification system (OBIS) and the identification
codes used for commonly used data variables in electricity metering equipment [4]. This
system, however, was not implemented in the specific electricity meter used and served
only as background information.

The second aim of the background study was to become acquainted with AT commands that
data modems use for communication. For this study, the AT Commands Interface Guide
published by Sierra Wireless was used.

Furthermore, background studies were done on similar projects or products that are already
available. No notable information was gained from this part of the study – apart from the
fact that similar products already exist in South Africa and abroad [5].

3
3. Technology Overview

3.1. Introduction

In this chapter a broad overview is given over the proposed system. Firstly, the major
components that were used are introduced and discussed. Secondly, the way in which the
integration was implemented is discussed at a systems engineering level.

3.2. Key Components

3.2.1. Electricity Meter

The electricity meter to be integrated with was specified and supplied by Trinity Telecoms.
The meter is an Enermax E+MA–454000 manufactured by the local company Strike
Technologies. The energy meter has the following features: [6]

• Three phase energy and demand measurement.


• Four quadrant power and energy measurement.
• A head for optical communication and data reading.
• Two docking bays two accept expansion modules. These modules are able to provide
communication via RS232, RS484, PSTN or GSM.
• Auxiliary I/O Inputs and outputs.

The meter is fitted with an E+EA – RS2324 expansion module capable of expanding the
functionality of the meter to include RS232 communication.

Figure 1 on page 5 shows a diagram of the front of the electricity meter with the safety cover
removed.

4
Figure 1: Enermax Electricity Meter

5
3.2.2. Data Modem

A Sierra Wireless GL6100 modem was specified and supplied by Trinity Telecoms. It is the
core component of the wireless system, and integrates with the SMART platform described
in section 3.2.3. The Modem has the following features and specifications related to the
project: [7]

• 1800/1900Mhz GSM Radio with class 1 (1W) output power.


• Class 10 GPRS.
• RS-232 serial interface with autobauding.
• 1.8V/3V SIM interface
• AT command set based on V.25 ter and GSM 07.05 & 07.07
• Data transmission at up to 14400bit/s with MNP Class 2 error correction and V42.bis
data compression.
• Real Time Clock with calendar.
• On board development with the aid of the Sierra Wireless Software Suite. This
includes native execution of embedded standard ANSI C applications, Custom AT
command creation, Custom application library creation and standalone operation.

Figure 2 shows the block diagram of the GL6100 Modem.

GL6100

RS232
Interface
FM
VCC
Internal
VIn DC/DC
VCC WMP 1x0
Power
GND
Supply

Operating
Sim Card Status LED
Holder

Figure 2: Block Diagram of GL6100 Modem [7]

6
3.2.3. SMART Platform

The SMART platform, created by Trinity telecoms, provides a customisable online wireless
asset management solution. The system is designed to give users easy access to critical data
about their assets. Data from an asset such as an electricity meter is captured, uploaded to
the SMART platform by the data modem and displayed in a graphically appealing manner to
the user. Figure 3 shows an overview of the SMART system.

Asset

Asset

Device
SMART Platform Online Data
Visualisation
Asset

Figure 3: Overview of SMART system [8]

It is important to note that the system has been designed in such a way that one device (or
modem) is capable of uploading the data from multiple assets. This allows data from
multiple assets at a single location to be uploaded to the SMART platform by a single data
modem.

The online SMART platform has numerous features that enable online data visualisation to
be implemented with much greater ease. These include: [8]

• Online creation of data metrics, gadgets and dashboards.


• Data metrics enable online manipulation of data variables. Many powerful math
functions are available to the user and are easily and graphically implemented.
• Gadgets display variable data to the user in a graphically appealing manner. The
gadgets are made with vector graphics and are very customisable.
• Dashboards include grouped sets of gadgets. These are also very easy to create
online.

7
3.3. Component Integration

The integration of the key components discussed in the previous subsection is accomplished
by means of a device capable of querying the electricity meter for data, interpreting the
data, and sending the data to the data modem in the required format. The data can then be
processed by the SMART platform and finally posted online in visually appealing manner.
Figure 4 shows a diagram of the required duties of such a device.

Enermax
Device Electricity Meter

Sierra Wireless SMART Platform


Data Modem
Figure 4: Component Integration [6], [7], [8]

8
4. Hardware Design

4.1. Introduction

In this section the hardware used to implement the integration of the various key
components mentioned in the previous section is described. The section starts by showing
the overview of the system that was implemented. Next the hardware that was chosen to
fulfil the requirements is described. Detailed designs of notable parts of the hardware are
then discussed.

4.2. System Overview

Figure 5 shows a block diagram depicting an overview of the system.

Supply Voltage

Voltage VCC UART RS232 Line


Regulator Driver RS232

Microcontroller

LED Status UART Optical


Indicators Isolator

Isolated
UART

Real Time RS232 Line


RS232
Clock Driver

Figure 5: System Overview

The integration of the data modem and electricity meter is accomplished by using a
microcontroller. The microcontroller queries the modem for data. This data is processed and
sent to the modem for upload to the SMART platform. The use of the RS232 line driver and
optical isolator is discussed in sections 4.3.2 and 4.3.3. The voltage regulator and light
emitting diodes (LEDs) are discussed in sections 4.3.4 and 4.3.5.

9
4.3. Component Selection and Design

4.3.1. Microcontroller

For this project, the microcontroller forms the most important part of the integration
solution. The microcontroller is responsible for handling the majority of tasks required.

There are thousands of microcontrollers available on the market, but many lack the features
required for a specific setup. Others may be more than suitable, but come at a higher cost.
The balance between the required features and component cost must be kept in mind when
choosing this component.

The following design goals play a major role in this component’s selection:

Communication with the Electricity Meter and Data Modem


The Electricity meter is equipped with an RS232 port that allows serial data transmission. It is
therefore essential that the microcontroller be equipped with an UART interface. In order to
communicate with the electricity meter, the UART has to be capable of operating in 7-bit
data mode, with an even parity check, as specified within the IEC-62056 standard [3].

The data modem is also equipped with an RS232 port, and therefore requires serial
communication with the microcontroller. This presents an interesting problem to the project
design, as the majority of smaller less costly microcontrollers available on the market only
have a single UART interface, and the project requires communication with two RS232
devices. Initially a design was formulated to multiplex the UART interface. This design was
scrapped, as the modem sends status message updates asynchronously. This presents a
large opportunity for data transmission errors and missed transmissions. 2 UART interfaces
on the device is therefore a requirement.

System Status Output


The microcontroller should be able to provide a user with information about the current
status of the system. The system uses LEDs to inform the user of the current system state.
There is no need for other output options such as a USB connection or an LCD screen. The
ability to drive information LEDs on output pins is therefore also a requirement.

10
Scheduling of tasks
The microcontroller is required to schedule various tasks. The task specifics should be stored
in a user customisable area, such as in EEPROM memory. It was therefore decided that on
board EEPROM memory also be a requirement. Early implementation strategies also
required the use of a Real Time clock (RTC).

Program Memory
The amount of program memory required is difficult to determine before software
implementation starts. It was estimated that 32KB program memory would be adequate.

Design Constraints

The most important design constraints with regards to the microcontroller are summarised
in table 1:

Function Type Specific requirements


Program Memory 32KB
UART 2 UART Interfaces
Output Pins 6 Output Pins capable of driving standard LEDs
EEPROM Onboard EEPROM
RTC RTC Capability
Table 1: Microcontroller Design Constraints

Another design constraint to be kept in mind is the package type that the IC is produced in. It
was decided that the project’s PCB would make use of surface mount components. A TQFP
package was selected as the ideal package for the microcontroller.

With the design constraints in hand, it was decided to use the Atmel ATmeg324PU
microcontroller. The microcontroller is from a well-known family of microcontrollers and
conforms to the design constraints provided in table 1. [9]

11
4.3.2. RS232 Line Drivers
The specified microcontroller has two USART serial interfaces capable of serial
communication at Transistor–transistor logic (TTL) data voltage levels. The electricity meter
and data modem, however, have serial interfaces that work on the RS232 standard. This
standard makes use of different voltage levels when compared to TTL devices. Table 2
compares these typical voltage level differences:

TTL RS232
Typical Logical Low 0 V to 0.8 V +5V to +15V
Typical Logical High 2 V to 5.25 V -5V to -15V
Table 2: TTL versus RS232 Voltage Levels [10]

In order for serial communication to be possible between the various devices, it is necessary
to convert the voltage levels from TTL to RS232 and vice versa. The device to handle this task
was chosen as a MAX232 IC, as this device is the absolute industry standard solution to this
specific voltage level translation problem. The device is reliable, affordable and simple to
implement. [11]

The MAX232 IC is a dual line driver intended for use in designs where a single +5V supply is
the only available. The IC contains three major sections: Dual DC/DC converters, Dual RS232
Drivers and Dual RS232 Receivers, as shown in figure 6 on the following page. [11]

The first DC/DC converter within the IC is a voltage doubler and is responsible for converting
the +5V input voltage to +10V by means of a charge-pump operation. The second DC/DC
converter is a voltage inverter and inverts the +10V to -10V. The first and second DC/DC
converters make use of capacitors C1 and C2 respectively. [11]

The RS232 Drivers section is responsible for inverting and amplifying Transistor-to-Transistor
level (TTL) voltage levels to that of RS232. An output voltage swing of ±8V is guaranteed
under nominal conditions, and an output swing of ±5V is guaranteed under worst case
conditions. Both inputs to the drivers section are pulled high internally and force the RS232
output low, even if left unconnected. [11]

The RS232 receivers section is responsible for translating the received RS232 signals to TTL
voltage level compatible signals. The voltage thresholds for are set at 0.8V and 2.4V for
logical high and low, respectively. The receivers section also inverts the signals as required.
Both inputs to the receivers section are pulled low internally and force the TTL output high,
even if left unconnected. [11]

12
Figure 6: MAX232 IC Overview [11]

13
4.3.3. Optical Isolation
The project makes use of optical isolation for the serial communication with the electricity
meter. This is for various reasons:

• The electricity meter is connected to a high voltage supply. Any electrical faults
within the meter can result in total destruction of the interface board and the data
modem, resulting in a financial loss and a fire hazard.
• The meter operates in an electrically harsh environment.
• The interface board should be designed for safety. When installing or servicing the
electricity meter or interface board, an accidental contact may occur and destroy the
entire system. Optical isolation protects the interface board and modem from such
events.

The design of an optically isolated RS232 interface presents two very different problems.

• The UART data signals have to transmitted and received optically. The optical
transmissions have to be noise free and detectable at frequencies up to 19.2kHz.
• RS232 interfaces operate at different logic voltage levels to that of the
microcontroller’s UART. Therefore the signals have to be converted from TTL levels
to RS232 levels.

A major problem when designing optically isolated circuitry getting a power supply to the
optically isolated side. To solve this problem, two designs were considered. The first makes
use of an optically isolated DC/DC converter. The second makes use of a push-pull
transformer stage.

The following sections describe these designs in detail.

14
4.3.3.1. Design A
Design A relies on the use of optocouplers, a voltage translation IC, and an isolated DC/DC
converter. In the design TTL voltage level data signals are transmitted from the non-isolated
side of the device to the isolated side and vice versa by means of optocouplers. On the
isolated side, the signals are translated from TTL to RS232 voltage levels and vice versa by
means of a MAX232 IC, as discussed in the previous chapter. The optically isolated side is
powered by means of an isolated DC/DC converter. Figure 7 shows a block diagram of this
solution:

Isolation Line

Isolated DC/DC
Converter
Isolated VCC & GND

Optocoupler
UART Circuit
Isolated
MAX232 RS232
UART Line Driver
Optocoupler
Circuit

Figure 7: Optical Isolator Design A

Because of easy availability and industry knowledge, the design was based on 4N25 optical
isolators. These optical isolators have the best suited characteristics in their device family
and within simulation proved able to provide acceptable operation at up to 19200 baud. The
4N25 is tested to have optical isolation at voltages exceeding 5000V RMS. Figure 8 shows the
optocoupler configuration designed for. [12]

This configuration allows for non-inverting data transmission without the use of additional
switching transistors. It should be noted that this configuration requires that the device
responsible for data transmission be able to sink current on a logical low.

15
Figure 8: Optocoupler Circuit

To start the design process of the optical isolators, the following equation describing the
effectiveness of current transfer from the non-isolated to non-isolated side is considered:

 =  /

Where

 = 


 
 

 =   

 =   

Figure 9 shows the Normalized Non-Saturated and Saturated CTR vs. LED Current for the
4N25 optocoupler at 25°C.

16
Figure 9: Normalised CTR [12]

As the CTR reaches a maximum at  = 10, this was chosen as the starting input current.
The corresponding output current can be estimated at 7.5mA.

It was decided to design for typical operating conditions. With the selected microcontroller
and RS232 line driver in mind, the typical values for the circuit’s operation were estimated as
follows:

Designator Description Typical Value


 Diode Supply Voltage 5V
 Transistor Supply Voltage 5V
 Diode Forward Voltage 1.4V
Logic High 4.5V
IN
Logic Low 0.5V
Table 3: Typical Values for Optocoupler Circuit [9], [12]

 acts as a current limiting resistor for driving the optoisolator’s LED. The value of the
resistor can be calculated from ohm’s law as:

    
 =


17
At logic Low:

5  1.4  0.5
 =
10 # 10$%

 = 310'

These values were simulated with LTSpice. During simulation the value of  was found to be
too small, and in turn resulted in the current  becoming larger than required. This had
unwanted effects on the circuit, such as an increased voltage drop over collector and emitter
on the opposite side of the optical isolator. By experimentation  was selected as 470Ω.

( is used as a pull-up resistor. Originally it was selected as 4.7kΩ, but during simulation it
was found that smaller values for ( resulted in a much better transient response at higher
frequencies. ( was selected to be 1kΩ.

Figure 20 shows the simulated output versus input of the optocoupler configuration at
19.2kHz.The optical isolator design proved questionable. The voltage swing is acceptable,
but the rise and fall times are poor.

Figure 10: Simulated Transient Response of Design A

In order to achieve better performance and reliability, an industry standard solution to the
optical isolation problem was researched. A solution was found in the form of the MAX250
and MAX251 IC pair, and lead to design B.

18
4.3.3.2. Design B
Design B relies on an integrated circuit pair to form a complete isolated UART to RS232
transmitter/receiver. The circuit makes use of the MAX250 and MAX251 isolated RS232
driver/receiver ICs, a small telecoms transformer, and 6N136 optocouplers.

The MAX250 and MAX251, when combined, provide a simple solution to the problem of
optical isolation and TTL to RS232 voltage level conversion. In addition to driving the circuitry
for the optocouplers, the pair also includes a push-pull transformer driver to supply the
required power on the isolated side. This is all possible form a single +5V supply voltage. [13]

Figures 11 and 12 show detailed block diagrams of the working of this IC pair, whilst figure
13 shows the IC pair’s implementation.

Figure 11: MAX 250 [13] Figure 12: MAX 251 [13]

19
Isolation Line

Transformer AC and
drive signal Transformer Isolated
GND

UART
MAX250 Optocouplers MAX251 RS232

VCC &GND VCC & GND


BYP and Isolated
GND

Figure 13: Block diagram of Optical Isolator Design B

The MAX250 is responsible for handling incoming and outgoing UART communication, and
for driving the transformer responsible for powering the MAX 251 which resides on the
isolated side. The MAX251, in turn, is responsible for transmitting and receiving data via the
RS232 standard, and relaying this information via the optocouplers.

The MAX 250 contains four non-inverting drivers, which may be used to drive an
optocoupler’s LED or to drive TTL signals. These drivers, in a typical configuration, source
7mA of current, and can sink up to 25mA. The drivers also contain internal Schmitt triggers
which prove quite useful at higher frequencies. [13]

An internal 300kHz Oscillator and a frequency divider are used to generate a 150kHz, 50%
duty cycle square wave which drive the transistors associated with D1 and D2. These are the
open-drain N-channel MOSFETs responsible for driving the transformer in a push-pull
fashion. [13]

The MAX251 connects to the isolated side of the circuit. The IC contains two line drivers and
receivers, as well as the circuitry required to transform the associated signals to be
compatible with the optocouplers. [13]

The IC configuration requires a telecoms transformer with specific parameters. Murata


Power Solutions’s 78250 series of transformers meets these standards. Table 4 shows the
required parameters.

20
Parameter Required 78250M (Typical)
Primary Inductance 1 mH – 2.5mH 2mH
Primary leakage Inductance 30µH 2µH
Turns Ratio 1:1 Centre Tapped 1:1 Centre tapped
Volt Time Product, ET 50Vµs 50Vµs
Interwinding Capacitance <100pF 69pF
DC Resistance <2Ω 1Ω
Ipk 300mA 300mA
Table 4: Required Transformer Parameters [13], [14]

The design uses 6N136 optocouplers over the slower 4N25 optocouplers designed for
previously. This results in a much higher maximum data rate, and with the MAX250/MAX251
configuration may be usable at up to 90kHz. [13]

The completed circuited is shown in figure X in appendix X.

4.3.4. Power supply


The power supply to the board is based on a 7805 5V linear regulator. This regulator is
capable of delivering 1A of peak output current [15]. In order to ensure this limit is not
exceeded, an estimated current calculation was done. The peak current is considerably less
than 1A.

Component Idle Current Peak current


Microcontroller 6mA 15mA
LEDs 0 60mA
Optical isolator 1mA 255mA
RS232 Line drivers 5mA 15mA
Total 12mA 345mA
Table 5: Total Current Calculation

21
4.3.5. LEDs
Six identical LEDs are used as a method of providing the user with output. They are driven
directly from the microcontroller and require current limiting resistors.

The current limiting resistor for each resistor can be calculated from ohm’s law as:

 − 
 =


Where

 = ) *   +, -


-
))

 = .
/
0 ) * 1


 = .
/
0 

With  chosen as 10mA,  as 2.2V and  as 4.5V:

 = 230Ω

 was chosen as 220Ω

22
5. Software Design

5.1. Introduction

The software created for this project went through various stages of development. First, in
order to explore the protocol of the electricity meter, software was written for a pc to
communicate with the device. The software was written in standard C, with the goal of
software portability to the microcontroller.

An application for interfacing and querying data from the electricity meter was implemented
completely, and proved very reliable during testing. This program simply extracts data from
the electricity meter, interprets this data and displays it to the screen. PC software was not
written to communicate with the data modem, as this communication can be tested with a
terminal client.

After familiarisation of communication with both the electricity meter and the modem,
software was developed for the microcontroller to interface to both devices. Reusing the C
code from the PC version of the software proved troublesome. This was mostly because of
the use of different compliers, different libraries and because of the limited memory of the
microcontroller compared to that of the PC. The architecture of the microcontroller is also
different to that of the PC.

Efforts to port the code were abandoned. A new program was written for the
microcontroller. The program is similar in structure to the PC version, but most methods
have been revised and rewritten.

Before reading this chapter the reader is strongly encouraged to study appendix E. This
appendix introduces the reader to the protocols and commands for the communication with
the energy meter and the modem. This base of knowledge is essential if the software is to be
understood.

Section 5.2 of this chapter describes the PC software design. Section 5.3 moves on to discuss
the microcontroller software.

23
5.2. PC Software Design

The PC software was written in C using the Code::Blocks Integrated Development


Environment (IDE). The code was compiled by the GNU C compiler under Windows 7. The
software makes use of a modified General Public License (GPL) licensed RS232 library for
handling the basic RS232 communication.

The PC software has functions for basic communications with the Enermax electricity meter
device by means of an implementation of the IEC62056 protocol as discussed in Appendix D.
The software is capable of interpreting the ASCII coded raw data that is received from the
energy meter when a raw read is performed.

5.2.1. Software structure

In the software, several files were created, with the goal of each file representing a
collection of functions for a similar process at a similar layer in the software topology. Table
6 describes the function of each of these files.

File Name Function


RS232.c Responsible for controlling the low level RS232 communications. This is a
slightly modified version of the GPL licensed file written by Teunis van Beelen.
Serial.c Responsible for controlling the high level RS232 communication.
Enermax.c Responsible for handling Strike’s implementation of the IEC62056 protocol
and data communication with the Enermax electricity meter.
Instant.c Contains the code necessary to interpret the raw data read from the Enermax
device’s instantaneous data registers.
Utils.c Contains various short utility functions required mostly for data type
transformation.
Main.c This file implements the functions in the files listed above to communicate
with the meter. It is used mostly for purpose of testing of other functions.
Table 6: PC Software Structure

24
5.2.2. Software Description and Evaluation

This section describes each of the files in greater detail and evaluates the performance
found during testing.

5.2.2.1. RS232
As this is not the work of the author this file will not be discussed in detail. The file contains
basic functions for controlling serial ports, such as sending and receiving bytes.

5.2.2.2. Serial
Serial.c essentially implements the functions of RS232.c to create higher level access to the
serial port. The function stores information about the specific serial setup in its local
variables. The following functions enable this high level access:

• Port_Setup is used to select the serial port and baud rate for use.
• Open_Port attempts to open the specified port to the program.
• Send_Msg sends a String via the serial port.
• Wait_Response receives incoming characters from the serial port and writes them to
a buffer. This is done by polling the serial port until a certain number of characters
have been received. When the function completes, the buffer is null terminated.
• Close_Port is used to close the port.

The functions were tested at baud rates of 2400, 9600 and 19200. Generally the functions
perform well, with the exception of the Wait_Response receive function. It was found that
the method of counting characters until the expected amount was received is a poor
implementation and caused the program to enter an endless loop if data transmission errors
occurred. This was especially likely when testing at higher baud rates. This knowledge was
kept in mind during the software design of the microcontroller.

5.2.2.3. Enermax
Enermax.c contains all the functions required to read raw data from the Enermax electricity
meter by means of the IEC62056 protocol. The operations specified and explained in
Appendix D of this document are implemented by the following functions:

• Emax_Request sends the opening request to the electricity meter as described in


Appendix D.
• Emax_Ack_Select sends the Ackowledgement/Option select message as described in
Appendix D. The function requires arguments to set the parameters of protocol,
baud and mode for communication.
25
• Emax_Raw_Read performs a raw data read as described in Appendix D. The function
requires arguments to set the start address to begin reading and the amount of data
to read.

The functions perform adequately at the tested baud rates of 2400, 9600 and 19200baud.

5.2.2.4. Instant
Instant.c comprises of a single function, parseInstant, which parses an input character array.
This function was specifically written to parse the raw data received when reading the
instantaneous registers of the Enermax meter into the distinct variables encoded within.

Appendix E shows the memory locations and data types of the instantaneous registers on
the Enermax electricity meter. This set of memory locations is updated once every second
with instantaneous metering information. To prevent garbage being read, the instantaneous
registers must be read as a block. This block of raw information is parsed by Instant.c.

Local arrays with information about the variables encoded within the block of raw data are
declared within Instant.c. These arrays serve as lookups for the parsing process and include
the length and type of every individual variable. For the sake of explanation, let these arrays
be called LENGTH and VARIABLE TYPE. These arrays have 47 elements, as there are 47
instantaneous variables encoded into the local variables data block.

An element of LENGTH can be either 1, 2, or 4 raw bytes, which translates to 2, 4 or 8 ASCII


bytes. An element of VARIABLE TYPE can represent an IEEE754 Float, unsigned short, signed
short, unsigned char, or signed char.

Figure 14 shows a simplified flow chart of parseInstant. Every variable in the raw data block
is copied to temporary buffer. This buffer must then be converted from little to big endian.
Thereafter VARIABLE TYPE is evaluated by a switch statement and a suitable variable
populated with the converted data. Data conversion occurs either through a suitable C
function or one of the functions created in Utils.c. When data conversion has finished the
variable is printed to the screen. Here the function can easily be modified to perform other
actions with the variable.

The function performs adequately at the tested baud rates of 2400, 9600 and 19200baud.

26
Get LENGTH and VARIABLE TYPE
from lookup arrays.

From raw input data copy


LENGTH characters between
INDEX and INDEX + LENGTH to

Convert from Little to Big Endian.

Do this for every variable


encoded in the raw data. INDEX
Evaluate
VARIABLE
TYPE

Convert raw data and store in


appropriate variable according
to evaluation. Print variable to

Increment INDEX with N

Figure 14: Flow chart of parseInstant

27
5.2.2.5. Utils
Utils.c contains various utility functions. These are described below:

• calculateBCC calculates the block check character as described in Appendix D. The


only required parameter is a pointer to an input array consisting of a full data
message as described in Appendix D (excluding the BCC). The function automatically
calculates the BCC from this array in places it in the correct spot.
• littleToBig performs conversion from little endian to big endian on a character array.
• stringToInt converts a string representation of a raw hexadecimal number to an
integer variable.
• stringToFloat converts a string representation of a raw IEEE754 Float to an floating
point variable.
• longToAscii converts a long integer to character array representing a hexadecimal
number.

The functions perform adequately in the environment they were written, but are very likely
to fail when compiled for other architectures or by other compilers. This was seen first-hand
when trying to port this code to the microcontroller. This knowledge enabled a much more
portable focus when software was developed for the microcontroller.

5.2.2.6. Main
Main.c, at the time of writing, performs iterative reading from the energy meter by
constantly polling it for instantaneous data. This data is interpreted and printed to screen.
Figure 15 shows the result of running Main.c. It should be noted that not all these variables
being printed are entirely correct – many have to be scaled or converted as described in
appendix D. This conversion, in the microcontroller application, is done online by the SMART
platform.

The program was tested at 2400, 9600 and 19200 baud. The program performs adequately,
although the addition of better error handling code would be of service. The results are as
expected.

28
Figure 15: PC Software Output

29
5.3. Microcontroller Software

5.3.1. Software Overview and Structure


The software structure of the microcontroller is very similar to the software designed for the
PC. The main difference with regard to the structure is the addition of files required to
handle communication with the modem. In the software developed for the microcontroller,
the main function also performs the vital role of driving and scheduling the other functions.
Other differences include the addition of hardware interrupts into the code.

One key aspect to address is the handling of serial data transmission. In addition to polling
for data, which involves sending data to a device and checking the receive buffer until an
adequate response was received, the microcontroller also supports interrupt based data
transmission. Although the method of polling works to a satisfactory level with the electricity
meter, it does not with the modem. This is because the modem can send information on its
status at any time, as discussed in Appendix D. With the electricity meter, data is expected
only after a message has been sent to it. It was therefore necessary to implement interrupt
driven transmission to handle these unexpected status message updates.

Another important aspect discovered during the software development was the limited
availability of memory to the microcontroller. The microcontroller showed erratic behaviour
whenever too much memory was being used by variables within the software. This project
makes extensive use of large data transmission strings, and is extremely susceptible to such
memory errors. Possible solutions to this problem were researched. It was found that large
data variables had to be:

a) Defined globally, or
b) Defined at the start of the main method, and passed only by reference.

Option b was implemented. Two large transmit and receive buffers are defined at the start
of the main method and are passed by reference. The same buffers are used for
communication with the modem and electricity meter.

A unique file was created for each aspect of the software to keep the structure of the project
organised. Table 7 describes the use of each file:

30
File Name Function
USART.c Responsible for controlling the high level UART communication.
Enermax.c Responsible for handling Strike’s implementation of the IEC62056 protocol
and data communication with the Enermax electricity meter.
Modem.c Responsible for communication with the Sierra Wireless data modem.
Interpret.c Contains the code necessary to interpret the raw data read from the Enermax
device’s instantaneous data registers, as well as formatting the data to the
form required by the modem.
Utils.c Contains various short utility functions required mostly for data type
transformation.
Main.c Responsible for the main software loop and scheduling of functions.
Table 7: Microcontroller Software Structure

31
5.3.2. Software Description and Evaluation

This section describes each of the files in greater detail.

5.3.2.1. USART
USART.c is used to drive the USART serial communication by the device. The file includes
functions for setting up the communication, sending characters and strings, and polling for
characters and strings:

• USART0_Setup and USART1_Setup are used to setup the microcontroller for serial
transmission on its USART0 and USART1 interface. The arguments they require are a
value for the baud rate register, number of data bits, type of parity, and number of
stop bits. These functions, by default, set the registers of the microcontroller to
enable data transmission in UART mode.
• USART0_sendByte and USART1_sendByte are used the send a character via the
respective UART interface. These methods also control the output LED’s that
indicate data transmission.
• USART0_sendString and USART1_sendString are used to send Strings via the
respective UART interface.
• USART0_receiveByte and USART1_receiveByte are used to receive a character via
the respective UART by means of waiting until the next character is read into the
microcontroller’s receive buffer. These methods also control the output LED’s that
indicate data reception.
• USART0_receiveString and USART1_receiveString use the method of polling to
receive a String via the respective UART interface. These methods wait for a
specified termination character, after which a break operation occurs and the String
is null terminated.

The value for the baud rate register can be calculated from the following equation:

67
455 = −1
16 ∙ 541

Where UBBRn is the value required within the USART register. The chosen baud rates were
9600 and 2400 baud for the data modem and electricity meter, respectively. These baud
rates are considered relatively slow, but were chosen because of the lower rate of
transmission errors at these frequencies. The entire device operates in an electrically noisy
environment and therefore this was of importance.

32
5.3.2.2. Enermax
This file is very similar to the Enermax.c file developed for the PC application but implements
the memory reduction strategy discussed in section 5.3.1. The file contains all the functions
required to read raw data from the Enermax electricity meter by means of the IEC62056
protocol. The operations specified and explained in Appendix D of this document are
implemented by the following functions:

• Emax_Request sends the opening request to the electricity meter as described in


Appendix D. This function requires a pointer to send- and receive buffer described in
section 5.3.1.
• Emax_Ack_Select sends the Ackowledgement/Option select message as described in
Appendix D. The function requires arguments to set the parameters of protocol,
baud and mode for communication. This function also requires a pointer to the
send- and receive buffer described in section 5.3.1.
• Emax_Raw_Read performs a raw data read as described in Appendix D. The function
requires arguments to set the start address to begin reading and the amount of data
to be read.

5.3.2.3. Modem
Modem.c is responsible for handling all of the data communication and events related to the
modem. It has functions for uploading data to the SMART platform, as well as functions for
handling interrupts generated by the modem status updates. The following functions are
implemented:

modem_Update is responsible for processing modem status update messages as described


in section X. This function is called when an interrupt is generated indicating that new data is
available on the UART interface connected to the modem. The function can evaluate
between the boot, up and down messages as described in section X. These messages cause
the global flag variables AWTDA_Status and modem_Status to be set. Table 8 summarises
the values of these flag variables under different modem conditions:

Modem Condition AWTDA_Status modem_Status


Boot 0 (Down) 0 (Busy)
Connected to SMART 1 (Up) 1 (Ready)
Disconnected from SMART 0 (Down) 1 (Ready)
Table 8: Truth table of flag variables

33
modem_Send is used to send a command to the modem. The function then waits for the
modem to respond and evaluates the response. Should the command have been successful,
1 is returned. Should the command have failed or timed out, 0 is returned. The timeout time
is specified in the EEPROM.

Figure 16 shows the flow chart for this function.

Send command

Wait for Modem


Timeout
Response
Timeout at X

Evaluate OK
Return 1
Response

ERROR

Return 0

Figure 16: Flow Chart of modem_Send function

The function modem_Upload is responsible for uploading data to the SMART platform.
Figure 17 shows a flow chart for this function.

The function starts by doing two checks on the modem. The first is to check if the modem is
ready and responsive. This is done checking the modem_Status global flag variable (as
described in earlier in this section) and by sending the ‘AT’ command (as described in
Appendix D) with the modem_Send function to the modem. The second check is to see
whether the modem is up (i.e. connected to the SMART platform). This is done by checking
the AWTDA_Status variable.

34
Should the modem be unresponsive, it is reset using the AT command described in Appendix
D. Should the modem be down, the function waits until the modem reports that it is once
again connected to the SMART platform, or until a timeout occurs on the microcontroller.

The data is then sent to the modem in the form of the command discussed in Appendix D.
The microcontroller then waits until the modem responds, or until a timeout occurs on the
microcontroller.

The modem’s response is evaluated by the microcontroller. If the data upload was
successful, the function returns 1. If the data upload causes a timeout on the modem, the
data is resent up to 3 times. Should all 3 times fail the function returns 0.

If a timeout occurs on the microcontroller at any point during the communication with the
modem, the function returns 0. The timeout time is specified in the EEPROM.

Modem Up Down or
Reset Modem
& Ready? No Error? Error

Yes Down

Send command with Wait until Modem Up


data Timeout at X min

Wait for Modem Evaluate OK


Return 1
Response Response
Timeout at X

TIMEOUT

ERR_COUNT Increment
No = 3? ERR_COUNT

Yes

Return 0

Figure 17: Flow Chart of modem_Upload function

35
5.3.2.4. Interpret
Interpret.c is similar to the Instant.c file created for the PC version of the software. The file
contains two functions for interpreting the raw data received from reading the
instantaneous registers of the Enermax electricity meter. These functions also convert this
raw data to the data message format required by the data modem (as described in Appendix
D) for data upload.

During the software development is was found that the data modem started acting
erratically when data uploads with more than 30 variables took place. The modem would
simply freeze or restart itself. To minimise the risk of this occurring, the raw data is
converted and uploaded by two separate data messages to the modem. These two
functions, when combined, work very similarly to the function described in section 5.2.2.4.
However, there are notable changes.

The first function within the class, parse_Floats, is responsible for parsing and formatting all
the IEE754 floating point numbers extracted from the raw data. The raw data to floating
point conversion is done using a custom function implemented in Utils.c and discussed in
section 5.3.2.5. As the data modem is only capable of uploading integers, the values of
these floats are multiplied by 1000 and rounded. These values will be scaled back to their
correct value in the SMART platform.

The second function, parse_Other, is responsible for parsing and formatting the remainder
of the data variables. By using a custom function implemented in Utils.c and discussed in
section 5.3.2.5 the data variables are converted to signed shorts.

In both these functions the variables have to be converted to ASCII strings and formatted for
upload to the SMART platform. This is done by means of lookup arrays containing the
variable names defined in the asset model on the SMART platform.

5.3.2.5. Utils
Utils.c contains various utility functions used mostly for raw data to variable conversion. The
file is almost completely different when compared to the Utils.c file developed for the PC
application. This is mostly because the functions compiled for the PC architecture did not
port correctly to to the microcontroller. The functions were re-written and used more
portable coding conventions.

In order to perform the conversions from raw data to variables, direct manipulation of the
bits was used. This was accomplished by creating structures with the C struct assignment
and sharing these structures memory by means of the union operator. This direct bit

36
manipulation also removed the need for the little to big endian conversion required in the
PC software.

The following functions are available in the Utils.c file:

• calculateBCC is used to calculate the Block Check Character implemented by the


IEC52056 protocol. Its usage is exactly the same as that of the PC version.
• AsciiValue returns the integer value represented by a single hexadecimal character.
• AsciiToFloat returns the value represented by a raw data string as a float.
• AsciiToSignedShort returns the value represented by a raw data string as a signed
short.

5.3.2.6. Main
Main.c contains the functions for setting up the microcontroller environment and schedules
the various tasks of the microcontroller. It also contains the main loop for the embedded
software. A simplified version of the software flow of the main software is shown in figure
18.

The first part of the main program sets the microcontrollers registers to enable it to drive
the output LEDs and communicate with via UART. The microcontroller initialisation also sets
the pins 0-5 port A as output pins enabling them to drive the information LEDs.

Next the main routine initialises all the required variables. Variables such as error counters
are set to zero, and timeout times are loaded from the EEPROM.

The device then waits for the modem to come online and connected to the SMART platform.
Once this connection is confirmed, the device reads data from the electricity meter,
interprets it and uploads it to the SMART platform. Should either of the operations be
unsuccessful 3 times in a row, the microcontroller enters an error state. Should the
operations be successful, the device waits a certain time (programmable in the EEPROM)
before attempting to read data from the electricity meter and upload it again.

The error state is indicated to the user by means of an error LED. In the error state, the
microcontroller ceases to communicate with any device and requires a manual reset by a
user.

37
Power On

Set up hardware
registers

Initialise global
variables

Wait for modem to


come online

Read data from False ERR_COUNT


electricity meter = 3?

True

Reading No Increment ERR_COUNT Error State


successful? Wait T_EM_ERR s

True
Yes

Wait T_UPLOAD Reset ERR_COUNT False ERR_COUNT


seconds Upload data to modem = 3?

Upload No Increment ERR_COUNT


successful? Wait T_WM_ERR s

Yes

Reset ERR_COUNT

Figure 18: Flow Chart of Main function


38
6. Measurements and Results

Hardware
Hardware measurements were taken to assess the RS232 line drivers and the RS232 optical
Isolator. Table 9 shows and comments on these measurements.

Operating Conditions/Comments Result


Figure 19 shows the output of the
optical isolator when a 5V block wave
is input at 9.6kHz

The optical isolator works well at


9.6Khz. The rise and fall time are
small when compared to on time. The
output voltage swing is acceptable

Figure 19: Optical Isolator at 9.6kHz

Figure 20 shows the output of the


optical isolator when a 5V block wave
is input at 56kHz

The optical isolator performs poorly


at 56kHz. The rise and fall time are
large and the one time very short.
The output voltage swing is also poor.

Figure 20 Optical Isolator at 56kHz

39
Figure 21 shows the output of the
RS232 line driver when a 5V block
wave is input at 9.6kHz

The RS232 line driver works well at


9.6Khz. The rise and fall time are
small when compared to on time. The
output voltage swing is acceptable.

Figure 21: RS232 line driver at 9.6kHz


Figure 20 shows the output of the
RS232 line driver when a 5V block
wave is input at 56kHz

The RS232 line driver performs


adequately at 56kHz. The rise and fall
time are acceptable. The output
voltage swing is also acceptable.

Figure 22: Rs2322 line driver at 56kHz


Table 9: Practical Measurements

Complete System
The project was found to be successful overall. It is, however, not very possible to show this
in formal writing.

The final product of this project is the online visualisation of data of data by the SMART
platform. On this platform, data is displayed to the user by means of a dashboard that is
populated by various gadgets containing easy to read graphics. The dashboard can be
updated every 15 seconds and will be refreshed with data at a rate set within the EEPROM
configuration of the microcontroller.

40
The dashboard for this project is designed to be used by a typical commercial electricity user
for monitoring the present electricity consumption statistics for a certain location. Figures 19
through 21 display the gadgets that were implemented.

Figure 19 shows the phasor diagram gadget that Trinitel has designed specifically for use
with electricity meters. The phasor diagram shows the phase and amplitude of the RMS
voltage and RMS current for each of the 3 phases. In the figure the phase diagram has been
populated with test data to clearly illustrate the capability.

Figure 23: Phasor Diagram Gadget

Figure 20 shows the gadget that was used to display the current temperature inside the
electricity meter.

Figure 24: Temperature Gadget

Figure 21 displays the gadget that was used to show the current line frequency measured by
the electricity meter.

41
Figure 25: Frequency Gadget

Figure 21 displays the gadget that was used to display all the other instantaneous values.

Figure 26: Other Instantaneous Registers Gadgets

Figure 27 shows an example of data that was uploaded to the SMART platform.

Figure 27: Example Data Uploaded to SMART Platform

42
7. Conclusion and Recommendations
The aim of this project was to develop a hardware environment capable of extracting data
from an electricity meter and supplying this data to a data modem. This data would then
have to be made available on the internet in a graphically appealing manner.

The aim was accomplished by developing a microcontroller environment with two serial
interfaces for communication with the electricity meter and data modem. Data is extracted
from the electricity meter by means of the IEC62056 serial protocol. The data is then
interpreted and supplied to the data modem by means of serial AWTDA commands. The
data modem uploads this information to the SMART platform, which is capable of displaying
the data visually.

The voltage levels output by the microcontroller’s serial interface is not compatible with
those of the RS232 serial standard. A RS232 line driver IC was implemented to translate the
voltage levels from TTL to RS232 compatible levels. The line driver IC was tested and found
to work adequately.

It was found that the serial interface with the electricity meter required optical isolation for
safety reasons. Various optical isolation designs were considered. An industry tested
solution was implemented, tested and verified to work adequately.

In an effort to become familiarised by the software protocol that is implemented in the


electricity meter, software was developed for a PC to communicate with the electricity
meter. The software was developed in the standard C language with portability to
microcontroller in mind. The software provides a set of functions for communications with
the electricity meter. These functions are implemented to read and interpret instantaneous
data from the electricity meter. The PC software was tested and showed acceptable results.

Software was developed for the microcontroller to communicate with both the data modem
and the electricity meter. Software development on the microcontroller was not as easy as
expected. Compiler and architecture differences made code written for a PC difficult to port
to the microcontroller. Efforts to port the code were abandoned and the majority of
functions were rewritten.

The software on the microcontroller is independent and provides functions for


communicating with both the electricity meter and the modem. The functions are
implemented to read the instantaneous registers on the electricity meter, interpret this data
and send it to the data modem for upload to the SMART platform. The software was tested
and verified to work to an acceptable standard.

43
It is concluded that the project was successful. The project shows that electricity usage
information can be extracted reliably and efficiently. It also shows that this data can be
presented in a visually exciting manner on the internet.

Recommendations on the project are as follows:

• The addition of hardware circuitry to physically reset the modem by disabling its
power supply. The modem has a tendency to become unresponsive.
• Additional software to read other registers on the device. This can easily be
implemented with the functions already provided.
• The introduction of half-duplex communication, so that parameters on the electricity
meters may be set.

44
Appendix A: Project Planning Schedule

Week Date Planning


1 22/07 Investigate problem and problem background; Study Required background
technical information.
2 29/07 Attend Trinity Telecoms training. Investigate possible implementations
and solutions to problem.
3 05/08 Identify hardware design constraints and start designing hardware.
4 12/08 Finalise hardware development. Order components and begin designing
PCB.
5 19/08 Finalise PCB Design and submit to be made. Identify software
requirements.
6 26/08 Software development - implement required protocals on PC software.
7 02/09 Testweek.
8 09/09 Finalise PC software development and start testing.
9 16/09 Develop microcontroller software.
10 23/09 Develop microcontroller software.
11 30/09 Finish microcontroller software development and start testing.
12 07/10 Finalise Testing
13 14/10 Start Writing Report
14 21/10 Write Report
15 28/10 Finalise Report

45
Appendix B: Project Specification
The project specification, as discussed with the study leader, is as follows:

Title: Integration of a 3-phase energy meter and a data modem.

Goals: The design and implementation of a microcontroller platform to withdraw


information from from a 3-phase energy meter and supply this information to the SMART
platform.

46
Appendix C: Outcomes Compliance
Outcomes Compliance Achieved
1. Problem solving: Sections 1, 4 and 5.
Demonstrate competence to identify, Identification of problems in hardware and
assess, formulate and solve convergent software; Finding adequate solutions.
and divergent engineering problems
creatively and innovatively.
2. Application of scientific and Section 4.
engineering knowledge: Design of hardware from first principles.
Demonstrate competence to apply
knowledge of mathematics, basic science
and engineering sciences from first
principles to solve engineering problems.
3. Engineering Design: Sections 4 and 5.
Demonstrate competence to perform Design of hardware and software.
creative, procedural and non-procedural
design and synthesis of components,
systems, engineering works, products or
processes.
4. Investigations, experiments and Sections 2,4 and 6.
data analysis: Background studies; Investigations into
Demonstrate competence to design and different hardware solutions; Hardware
conduct investigations and experiments. simulations; Hardware measurements
5. Engineering methods, skills and Section 4, 5 and 6.
tools, including Information Development of PC Software; Hardware
Technology: simulations; Hardware measurements
Demonstrate competence to use
appropriate engineering methods, skills
and tools, including those based on
information technology.
6. Professional and technical Entire Report and Oral presentation.
communication:
Demonstrate competence to communicate
effectively, both orally and in writing, with
engineering audiences and the community
at large.
9. Independent learning ability: Appendix D.

47
Demonstrate competence to engage Familiarisation and implementation of
inindependent learning through IEC62056 protocol; familiarisation and
welldeveloped learning skills. implementation of AT commands.

48
Appendix D: Software Protocol Description

D.1. Introduction

In order to understand the software developed in the project, the reader needs to be
familiarised with certain protocols that are essential to the functioning of the device. In this
chapter the IEC62065 protocol used by the energy meter is discussed. It is followed by a
description of the AT and AT+AWTDA commands used for the modem. The work in this
appendix is purely a summary of the IEC62056 protocol and the AT and AWTDA command
set. This appendix is not the original work of the author and should not be treated as such.

D.2. IEC62056 Protocol

This protocol is a standard protocol to a majority of energy meters. The protocol permits
reading and programming of tariff devices. It is essentially a serial data transmission protocol
that makes use of extended formatting characters and some error detection mechanisms.
This section describes the specifications and implementations of this protocol, with regards
to the Enermax electricity meter. [3]

The protocol offers five alternative protocol modes, which can be used by the tariff device:
A, B, C, D and E. Mode C was selected, as it is the only mode the electricity meter is
compatible with. It also the most common mode implemented in the industry. [3]

D.2.1. Character Transmission

Table 10 describes the character transmission as defined by the IEC documentation.

Type of Asynchronous serial bit (Start-Stop) transmission according to ISO/IEC


transmission 1177:1985, half-duplex.
Transmission speed Standard baud rates – 300, 600, 1200, 2400, 4800, 9600, 19200.*
Character Format Character format according to ISO/IEC 1177:1985
(1 start bit, 7 data bits, 1 parity bit, 1 stop bit)
Character Security Even parity bit according to ISO/IEC 1177:1985
Table 10: IEC52056 Character Transmission [3]

*The IEC documentation defines the initial baud rate to be 300 for data communication. In
the strike implementation however, the initial baud rate is programmed when configuring

49
the energy meter. By experimentation it was found that the device does not respond to an
initial baud rate of 300.

D.2.2. Data transmission protocol

This section describes the data transmission. There are various message types that can be
sent and received from the device. There are various messages defined within the IEC62056
the IEC document, however only a few are implemented by the Strike electricity meter. The
messages used in this project will now be discussed. Brackets indicate more than one
character.

D.2.2.1. Request Message

The request message is the opening message from the reading device to the energy
message. The message has the following form: [3]

/ ? [Device Address] ! CR LF

A description of the message contents is given in table 7.

/ Start character "/" (forward oblique, code 2FH)


? Transmission request command "?" (question mark, code 3FH)
Device Address Device Address*
! End character "!" (exclamation mark, code 21H)
CR Completion character (carriage return, code 0DH)
LF Completion character (line feed, code 0AH)
Table 11: IEC62056 Request Message Content Description [3]

*Within the IEC specification it is stated that the device address is optional. On the Strike
implementation however, the device would not reply without an address. A general address
of “00000000” was found to be compatible by experimentation.

D.2.2.2. Identification message


The identification message is the first response from the energy meter. [3]

/ [X] Z \ W [Identification] CR LF

A description of the message contents is given in table 8.

50
/ Start character "/" (forward oblique, code 2FH)
X Manufacturer's identification*
Z Baud rate identification. See Section
\ Sequence delimiter "\" (backslash code 5CH)
W Optional enhanced baud rate and mode identification character
Identification Identification, manufacturer-specific.
CR Completion character (carriage return, code 0DH)
LF Completion character (line feed, code 0AH)
Table 12: IEC62056 Identification Message Content Description [3]

D.2.2.3. Acknowledgement/Option select message

The identification message must be acknowledged by the device reading the electricity
meter. This message is also used to select advanced features. [3]

ACK V Z Y CR LF

A description of the message contents is given in table 9.

ACK Acknowledge character (ACK, acknowledge, code 06H)


V Protocol control character see Section
Z Baud rate identification. See Section
Y Mode control character See section
CR Completion character (carriage return, code 0DH)
LF Completion character (line feed, code 0AH)
Table 13: Acknowledgement Message Content Description [3]

D.2.2.4. Programming command message

Used for programming and block oriented data transfer. [3]


SOH C D STX Data Set ETX BCC

A description of the message contents is given in table 10.

51
SOH Start-of-header character (SOH, start-of-header, code 01H)
C Command message identifier. See Section
D Command type identifier. See Section
STX Frame start character (STX, start of text, code 02H)
Data Set Data Set, See Section
BCC Block check character. See section
Table 14: Programming Message Content Description [3]

D.2.3. Calculation of the block check character


A block check character(BCC) is used to perform a simple data integrity check when device
data is written or read. The block check character must comply with ISO/IEC 1155:1978 [3].

The scope of the block check character BCC is as specified in ISO/IEC 1745:1975, and is from
the character immediately following the first SOH or STX character detected up to and
including the ETX character which terminates the message. The calculated BCC is placed
immediately following the ETX. The BCC is calculated by adding the 7-bit numbers and
ignoring overflow from the most significant bit. [3]

An example of the block check character calculation is given below.

Figure 28: calculation of the Block Check Character [3]

52
D.2.3. AT and AT+AWTDA Commands

To control and monitor the status of the modem, certain commands are sent and received
via a serial connection. The notable commands used in this project can either be classified as
an AT or AT+AWTDA commands. The AT commands are responsible for setting modem
parameters, while the AT+AWTDA commands are used for uploading and receiving data and
events to the SMART platform.

Table11 lists the most notable AT commands used within the project to control the Sierra
Wireless modem.

Command Description
AT This command enquires on the status of the modem.
AT +CFUN=1 A complete software reset occurs. The GSM stack is cleared and GSM
Functionality is restarted. Modem parameters are reset if they have not
been saved to EEPROM.
AT+IPR=<rate> By changing the value of <rate> the baud rate at which the modem will
receive commands are set. This value can also be set to 0 to enable
autobauding.
AT&W The parameters that have been set on the modem are written to the
EEPROM. Consequently, they will be loaded from the EEPROM into memory
when the modem is reset or powered on the next time.
Table 15: Notable AT Commands [16]

The standard form of an AT+AWTDA command for a data message to the SMART platform is
composed in the following format: [17]

AT+AWTDA=d , " [Identifier] . [Path] " , N , [Variables]

A description of the message contents is given in table X.

53
AT+AWTDA=d AWTDA data message identifier
, Comma, code 2CH
" Quotation mark, code 22H
[Identifier] Unique asset identifier. See section
. Full stop ,code 0DH
[Path] Variable path in asset model. See
[N] Number of variables.
[Variables] A string containing the variable names, types and values.
Table 16: Description of AWTDA data message contents [17]

[Identifier] relates to the unique asset id on the SMART platform. [17]


[Path] relates to the variable path within the asset model on the SMART platform. [17]

[Variables] is a string containing all the variable names, types and values. The string is
composed of various smaller strings representing each of the data variables to be uploaded.
The strings are separated with the “,” (comma, code 2CH) character. It is important to
ensure the correct number of the smaller substrings is used, as an incorrect match with [N]
will generate an error, and no data will be uploaded. The smaller substring is composed of
the following characters: [17]

" [Variable Name] , [Variable Type] , [Value] , "

A description of the substring contents is given in table 13.

" Quotation mark, code 22H


, Comma, code 2CH
[Variable Name] Unique variable name declared in asset model.
[Variable Type] Variable type. The following variable types are supported:
‘INT32’ – Signed 32 bit integer
‘INT64’ – Signed 64 bit integer
‘STR’ – String
‘BOOL’ – Boolean
[Value] The value of the variable. For Booleans, use ‘T’ and ‘F’.
Table 17: Description of AWTDA data message substring content [17]

54
When the messages described in this section are sent, the modem responds with some
information as to whether the command was successful. The modem also regularly sends
messages about its current network status. Table 14 shows these messages.

Message Occurrence Meaning


+AWTDA: BOOT On power up or reset. May also The modem is busy with the
sporadically occur if the modem’s required functions for it to start
firmware generates an error it is not working.
capable of handling.
+AWTDA: UP After a successful boot; thereafter The message informs the
+AWTDA: DN every 60 seconds. controlling unit of the current
network status. The network is
either functioning(UP), or there is
an error with the connection(DN).
OK After a successful AT or AT+AWTDA The command given to the
command. modem has been successful.
+AWTDA: A few seconds after an AT+AWTDA The AT+AWTDA command has not
TIMEOUT command, should the command been successful and the system
have failed. has timed out while trying to
transmit the data.
ERROR After an unsuccessful AT or The command given to the
AT+AWTDA command. modem has been unsuccessful.
This generally means there was a
syntax or logical error within the
command sent.
Table 18: Messages from modem [17]

55
Appendix E: Enermax Instantaneous Register Memory Layout
Addres Data Set Data Type Bytes Unit To get true value

300000 Volts: L1 RMS IEEE754 Float 4 V -


300004 Volts: L2 RMS IEEE754 Float 4 V -
300008 Volts: L3 RMS IEEE754 Float 4 V -
300012 Amps: L1 RMS IEEE754 Float 4 A -
300016 Amps: L2 RMS IEEE754 Float 4 A -
300020 Amps: L3 RMS IEEE754 Float 4 A -
300024 Watts: L1 IEEE754 Float 4 W Divide by
accumulate
counter (Ref:23)
300028 Watts: L2 IEEE754 Float 4 W Divide by
accumulate
counter (Ref:23)
300032 Watts: L3 IEEE754 Float 4 W Divide by
accumulate
counter (Ref:23)
300036 Watts: Total IEEE754 Float 4 W Divide by
accumulate
counter (Ref:23)
300040 VAR: L1 IEEE754 Float 4 var Divide by
accumulate
counter (Ref:23)
300044 VAR: L2 IEEE754 Float 4 var Divide by
accumulate
counter (Ref:23)
300048 VAR: L3 IEEE754 Float 4 var Divide by
accumulate
counter (Ref:23)
300052 VAR: Total IEEE754 Float 4 var Divide by
accumulate
counter (Ref:23)
300056 VA: L1 Harmonic IEEE754 Float 4 VA -
300060 VA: L2 Harmonic IEEE754 Float 4 VA -
300064 VA: L3 Harmonic IEEE754 Float 4 VA -
300068 VA: Total Harmonic IEEE754 Float 4 VA -

56
300072 VA: L1 IEEE754 Float 4 VA Divide by
accumulate
counter (Ref:23)
300076 VA: L2 IEEE754 Float 4 VA Divide by
accumulate
counter (Ref:23)
300080 VA: L3 IEEE754 Float 4 VA Divide by
accumulate
counter (Ref:23)
300084 VA: Total IEEE754 Float 4 VA Divide by
accumulate
counter (Ref:23)
300088 Accumulate unsigned short 2 - -
counter
300090 L1 quadrant unsigned char 1 - -
300091 L2 quadrant unsigned char 1 - -
300092 L3 quadrant unsigned char 1 - -
300093 Total quadrant unsigned char 1 - -
300094 PF : RV-I signed short 2 PF Divide by 1000
300096 PF : YV-I signed short 2 PF Divide by 1000
300098 PF : BV-I signed short 2 PF Divide by 1000
300100 PF : TV-I signed short 2 PF Divide by 1000
300102 PHI : RV-I unsigned short 2 Degrees Divide by 10
300104 PHI : YV-I unsigned short 2 Degrees Divide by 10
300106 PHI : BV-I unsigned short 2 Degrees Divide by 10
300108 PHI : TV-I unsigned short 2 Degrees Divide by 10
300110 PHI : RV-YV unsigned short 2 Degrees Divide by 10
300112 PHI : RV-BV unsigned short 2 Degrees Divide by 10
300114 Line frequency unsigned short 2 Hz Divide by 100
300116 Internal signed short 2 Celcius Divide by 10
temperature C
300118 RTC year unsigned char 1 - Add 2000
300119 RTC month unsigned char 1 - -
300120 RTC day unsigned char 1 - -
300121 RTC hour unsigned char 1 - -
300122 RTC min unsigned char 1 - -
300123 RTC sec unsigned char 1 - -

57
300124 RTC dow unsigned char 1 - 1=Mon,7=Sun
300125 Internal signed short 2 Fahrenheit Divide by 10
temperature F
Table 19: Enermax Instantaneous Register Memory Layout

58
Appendix F: Full Circuit Schematics

59

Figure 29: Schematics Part 1


Figure 30: Schematics Part 2
60
Figure 31: Schematics Part 3

61
Appendix G: PCB Layout
Note: Not to scale.

Figure 32: PCB Top Layer

Figure 33: PCB Bottom Layer

62
Works Cited
[1] The professional body for whole life management of physical assets. (2013, October)
What is asset management? [Online]. http://theiam.org/what-asset-management

[2] Deshnee Subramany. (2013, February) Mail&Guardian. [Online].


http://mg.co.za/article/2013-03-07-fuel-and-electricity-increases-the-rides-not-over-yet

[3] International Electrotechnical Commision, "Electricity metering – Data exchange for


meter reading, tariff and load control – Part 21: Direct local data exchange,"
International Electrotechnical Commision, Geneva, Switzerland, International Standard
0-626-14878-2, 2002.

[4] International Electrotechnical Commision, "Electricity metering – Data exchange for


meter reading, tariff and load control – Part 62: Interface classes," International
Electrotechnical Commision, Geneva, International Standard 2002.

[5] Meteringonline. (2013, October) Meteringonline. [Online].


http://www.meteringonline.co.za/mol/

[6] Strike Technologies, "Enermax+ Hardware and Installation Manual," Strike


Technologies, Midrand, Hardware and Installation Manual 2007.

[7] Sierra Wireless, "GL61x0 Product Technical Specification and User Guide," Sierra
Wireless, Richmond, Product Technical Specification and User Guide
WA_DEV_GL6100_PTS_001, 2010.

[8] Trinity Telecoms. (2013, October) Trinity. [Online]. http://www.trintel.co.za

[9] Atmel Corporation, "ATmega324PA," Atmel Corporation, San Jose, Data Sheet 8272A–
AVR–01/10, 2010.

[10] Joakim Ögren. (2013, October) HardwareBook. [Online].


http://www.hardwarebook.info/Serial_(PC_9)

[11] Maxim Integrated Products, "MAX220 - MAX249," Maxim Integrated Products,


Sunnyvale, Data Sheet 19-4323, 2010.

[12] Vishay Intertechnology, Inc., "4N25, 4N26, 4N27, 4N28," Vishay Intertechnology, Inc.,

63
Malvern, Data Sheet 91000, 2010.

[13] Maxim Integrated, "MAX250/MAX251," Maxim Integrated, San Jose, Data Sheet 1989.

[14] Murata Power Solutions, "78250 Series," Murata Power Solutions, Mansfield, Data
Sheet KMP_78250C_C03, 2009.

[15] ON Semiconductor, "NCV7805," ON Semiconductor, Phoenix, Data Sheet MC7800/D,


2005.

[16] Sierra Wireless, "AT Commands Interface Guide," Sierra Wireless, Interface Guide
WM_DEV_OAT_UGD_079, 2011.

[17] Trinity Telecoms. AT+AWTDA. Document.

64

You might also like