DM AnthonyPeleman 2016 MEESE
DM AnthonyPeleman 2016 MEESE
DM AnthonyPeleman 2016 MEESE
ANTHONY PELEMAN
Junho de 2016
Modbus TCP/IP connection of power analysers
for real-time monitoring of a demonstration
microgrid: A Simulink approach
Master degree in Electrical Engineering – Power Systems
Anthony Peleman
6-6-2016
Abstract
The demand for energy is growing more than ever and energy consumption is higher than the natural
resources are able to supply. Therefore it becomes necessary that companies start reducing their
energy consumption. Governments are creating more stringent environmental regulations, which
raise energy costs for polluting companies and makes energy-saving measures more attractive.
Companies are constantly searching for methods to lower their energy costs. Hereby energy
monitoring can offer a solution, as companies can examine their energy consumption at any time and
every consumer can be watched separately.
By linking the measurement devices via a Modbus TCP/IP connection it is possible to make numerous
measurements in various places. The software program proposed in this work does not depend on a
specific brand of power analyser, making it an interesting and very flexible tool.
The Matlab/Simulink software provides a perfect program environment, giving a transparent and
clear overview of the measured values. The software is easy to handle, even for beginners and makes
it possible to make changes really fast.
In several case studies the program was tested on different types of consumers. This way the
accuracy and the reliability of the program could be concluded.
1
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Contents
Abstract ................................................................................................................................................... 1
Contents .................................................................................................................................................. 2
List of figures ........................................................................................................................................... 4
Abbreviations .......................................................................................................................................... 5
1. Introduction ..................................................................................................................................... 6
1.1 Motivation ............................................................................................................................... 6
1.2 Energy monitoring ................................................................................................................... 9
1.3 Matlab / Simulink .................................................................................................................. 10
1.4 Thesis organization ................................................................................................................ 10
2. Measurement devices and network.............................................................................................. 11
2.1 Power analyser ...................................................................................................................... 11
2.1.1 Specifications ................................................................................................................. 11
2.1.2 Installation ..................................................................................................................... 12
2.2 MODBUS ................................................................................................................................ 13
2.2.1 MODBUS Application Protocol ...................................................................................... 13
2.2.2 MODBUS TCP/IP ............................................................................................................ 19
3. Monitoring an electrical grid ......................................................................................................... 22
3.1 Electrical grid ......................................................................................................................... 22
3.1.1 Location ......................................................................................................................... 22
3.1.2 Details of the grid .......................................................................................................... 22
3.2 Monitoring an electrical grid ................................................................................................. 23
3.2.1 Overall Model ................................................................................................................ 23
3.2.2 Power Analyser .............................................................................................................. 25
3.2.3 Switchable network configuration ................................................................................ 27
3.2.4 Real time simulation platform ....................................................................................... 28
3.2.5 Other busses .................................................................................................................. 30
3.2.6 Cable L2A-L2B ................................................................................................................ 32
3.3 Matlab code for the MODBUS TCP/IP connection ................................................................ 33
3.3.1 Communication between Matlab and the power analyser .......................................... 33
3.3.2 Convert value from float to decimal. ............................................................................ 35
3.3.3 Closing port and communication between Matlab and Simulink ................................. 35
4. Case studies ................................................................................................................................... 37
2
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
3
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
List of figures
FIGURE 1.1 2013 SHARES OF WORLD ELECTRICITY CONSUMPTION. (IEA, 2015) ..................................................................... 6
FIGURE 1.2 MATLAB LOGO (MATHWORKS, 2016) .......................................................................................................... 10
FIGURE 2.1 JANITZA UMG 96RM EL (JANITZA, 2016) .................................................................................................... 11
FIGURE 2.2 CONNECTION DIAGRAM VOLTAGE MEASUREMENT (JANITZA, OPERATING INSTRUCTIONS AND TECHNICAL DATA, 2016) 12
FIGURE 2.3 CONNECTION DIAGRAM CURRENT MEASUREMENT (JANITZA, OPERATING INSTRUCTIONS AND TECHNICAL DATA, 2016) . 12
FIGURE 2.4 MODBUS (MODBUS, 2012)...................................................................................................................... 13
FIGURE 2.5 MODBUS PROTOCOL DESCRIPTION (MODBUS, 2012) .................................................................................... 14
FIGURE 2.6 MODBUS PROTOCOL WITHOUT ERROR (MODBUS, 2012) ............................................................................... 14
FIGURE 2.7 MODBUS PROTOCOL WITH ERROR (MODBUS 2012) ...................................................................................... 14
FIGURE 2.8 IMPLEMENT FUNCTION CODE (MODBUS, 2012) .............................................................................................. 15
FIGURE 2.9 IMPLEMENT FUNCTION CODE (MODBUS 2012) ............................................................................................... 15
FIGURE 2.10 MODBUS PUBLIC FUNCTION CODES (MODBUS, 2012) ................................................................................ 16
FIGURE 2.11 MODBUS FUNCTION CODE CATEGORIES (MODBUS, 2012) .............................................................................. 17
FIGURE 2.12 EXAMPLE TO READ HOLDING REGISTERS 108-110 (MODBUS, 2012) ................................................................ 17
FIGURE 2.13 FUNCTION FOR READING THE HOLDING REGISTER (MODBUS, 2012) .................................................................. 18
FIGURE 2.14 TYPES OF MESSAGES IN TCP/IP NETWORKS (MODBUS, 2006) ......................................................................... 19
FIGURE 2.15 MODBUS APPLICATION PROTOCOL HEADER (MODBUS, 2006) ....................................................................... 19
FIGURE 2.16 MODBUS APPLICATION DATA UNIT (MODBUS, 2006) .................................................................................. 20
FIGURE 3.1 ELECTRICAL GRID OF THE GECAD LABORATORY ............................................................................................... 22
FIGURE 3.2 SIMULINK MODEL FIRST VIEW ....................................................................................................................... 24
FIGURE 3.3 SIMULINK MODEL POWER ANALYSER .............................................................................................................. 25
FIGURE 3.4 SIMULINK MODEL POWER ANALYSER SUBSYSTEM.............................................................................................. 26
FIGURE 3.5 TCP/IP RECEIVE BLOCK (MATHWORKS, 2016) .............................................................................................. 26
FIGURE 3.6 INTERPRETED MATLAB FUNCTION BLOCK ........................................................................................................ 26
FIGURE 3.7 SIMULINK MODEL SWITCHABLE NETWORK CONFIGURATION ................................................................................ 27
FIGURE 3.8 SIMULINK MODEL BUS B1 ............................................................................................................................ 28
FIGURE 3.9 SIMULINK MODEL BUS B1 SUBNETWORK ........................................................................................................ 28
FIGURE 3.10 SIMULINK MODEL BUS B1 CALCULATIONS ..................................................................................................... 29
FIGURE 3.11 CALCULATION CURRENTS ........................................................................................................................... 30
FIGURE 3.12 CALCULATION POWERS ............................................................................................................................. 30
FIGURE 3.13 SIMULINK MODEL BUS B4 SUBNETWORK ...................................................................................................... 31
FIGURE 3.14 SIMULINK MODEL CABLE L2A-L2B ............................................................................................................. 32
FIGURE 3.15 SIMULINK MODEL CABLE L2A-L2B CALCULATIONS ......................................................................................... 32
FIGURE 3.16 CONNECTION SIMULINK / MATLAB / POWER ANALYSER .................................................................................. 33
FIGURE 3.17 MODBUS ADDRESS LIST FOR JANITZA UMG 96RM-EL (MATHWORKS, 2016) ................................................. 35
FIGURE 3.18 FLOW CHART OF MATLAB CODE THE MODBUS TCP/IP CONNECTION .............................................................. 36
FIGURE 4.1 SCREENSHOT OF WIRESHARK CAPTURING 1 REQUEST AND ANSWER OF METER POWER SUPPLY................................. 37
FIGURE 4.2 SIMULATION OF A RESISTANT LOAD OF 1KW ................................................................................................... 40
FIGURE 4.3 SIMULATION OF A CAPACITIVE LOAD OF 4KVA ................................................................................................. 42
FIGURE 4.4 SIMULATION OF AN INDUCTIVE LOAD OF 0.37KW COS(Φ)=0.69 ........................................................................ 43
FIGURE 4.5 SIMULATION OF THE LOAD OF CABLE L1A-L1B ................................................................................................ 44
FIGURE 4.6 SIMULATION OF ALL LOADS BUS B1, B2 AND B4.............................................................................................. 46
FIGURE 4.7 SIMULATION OF ALL LOADS TOTAL GRID CONSUMPTION ..................................................................................... 47
4
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Abbreviations
A = ampere
ADU = Application Data Unit
ANSI = American National Standards Institute
bit = binary digit
Dec = decimal
EC = European Commission
EIA = Energy Information Administration
EU = European Union
FPF = fundamental power factor
GECAD = Research Group on Intelligent Engineering and Computing for Advanced Innovation
GHG = Greenhouse Gas
Hex = hexadecimal
IEA = International Energy Agency
IEC = International Electro-technical Commission
IP =internet protocol
IPCC = Intergovernmental Panel on Climate Change
kWh = kilowatt hour
kWh-class = effective energy class
MBAP = MODBUS Application Protocol Header
P = real power, active power
PDU = Protocol Data Unit
PLC = Programmable Logic Controller
Q = reactive power
RMS-value = Root Mean Square value
S = apparent power
s = second(s)
TCP = Transmission Control Protocol
V = voltage
VA = volt-ampere
VAR = volt-ampere reactive
W = watt
5
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
1. Introduction
1.1 Motivation
The demand for energy is growing more than ever and energy consumption is higher than the natural
resources are able to supply. The greenhouse gas (GHG) emissions, like energy related CO2 emission
is estimated by the Energy Information Administration to increase from 31.2 billion metric tons in
2010 to 36.4 billion metric tons in 2020 and 45.5 billion metric tons in 2040 (EIA,2013). The human
population is growing and countries are developing, this increases the demand for energy. At the
current rate, the Intergovernmental Panel on Climate Change expects the energy demand to increase
by 65% from 2004 to 2030 (IPCC, 2007). They also state that global warming is the most important
environmental problem of our time and reducing energy consumption seems a solution of handling
the emission problem. The EU has set itself a target of 20% energy savings by 2020 compared to the
projected use of energy in 2020, equivalent to turning off 400 power stations. For 2030 the EU
countries agreed on an energy efficiency target of 27% or greater, a little bit under the proposed 30%
of the European Commission (EC, 2014).
The report of the International Energy Agency puts forward that the industry uses 42.3% of the world
electricity consumption (IEA, 2015).
6
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Figure 1.1 shows that the industry is not the biggest consumer anymore, as other sectors have largely
increased their consumption. Looking only at the EU, the EC made the same conclusions based on
their annual data provided by each member state in their annual Eurostat. In the service sector the
electricity consumption doubled and in the residential sector it increased by around 41%. The
industry on the other hand was more influenced by the economic cycle. From 1994 until 2008 the
energy consumption yearly decreased by 2.1% and in 2009 with 13.6%. In 2010 and 2011 there was a
little growth of respectively 6.6% and 0.7%, but in 2012 and 2013 the consumption decreased again
with respectively 3.0% and 0.7% (Eurostat, 2015).
Energy saving is clearly not only a must for companies, but a necessity for all energy consumers.
Governments are creating more stringent environmental regulations, which makes energy-
consumption more expensive and energy-saving more attractive.
In bigger scale grids, like the power-grid of a country, all users have a power analyser that sends the
data to a monitor. The analysers are called smart meters and the developed system got the name
Smart grid. The aim is to develop an energy network that can automatically monitor energy flows and
adjust to changes in energy supply and demand accordingly. Throughout the day, energy prices
change according to the demand and the production of energy at that exact moment. In this way,
consumers will adapt their energy usage to different energy prices and save money by consuming
more energy in low price periods. The smart grid also allows the grid operators to better plan the
production of energy and balance their networks. The EC already published a report about the
deployment of smart meters in 2014. It is expected that almost 72% of European consumers will
have a smart electricity meter by 2020. The installation cost is between €200 and €250 and the EU is
planning a placement of 200 million meters by 2020, which represents an investment of €45 billion.
The EC expects that Portugal will have around 6.500 million electricity smart meter systems and
Belgium around 5.975 million. This investment may save energy up to 3%, offering potential for load
shifting and overall benefits in the order of €309 per meter point (EC, 2014).
In smaller scale grids, like companies, energy monitoring can be done by implementing analysers in
the company’s power-grid. This is an easy way to get an overview of the energy consumption of all
company sections. The company is able to balance out their network and push their production to
the very maximum if needed. In case of errors in the network, the measured values will indicate the
cause of the failure. Energy monitoring can also help to better integrate renewable energy. If the
company possesses wind turbines or solar panels, anemometers and solar analysing tools can be
7
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
added to the system. This way, the consumption of energy can be adjusted to the company’s energy
production, resulting in ‘greener’ and cheaper electricity.
The market for energy monitoring system has been booming for several years. Doing research about
this topic will help to improve the current systems and gives great opportunities for the future.
This particular research focusses on creating a monitoring system for small scale grids that does not
depend on any specific brand. The measurement devices are connected via a Modbus TCP/IP
connection. This communication protocol is openly published and royalty-free, making it perfectly
qualified for creating an open system. The software tool used is the Matlab/Simulink. This
environment is able to create a transparent and comprehensible overview of the measured values.
The software is easy to handle, even for beginners and makes it possible to make changes really fast.
8
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Energy monitoring is a technique that was first implemented in the United Kingdom in 1980. It is a
way of controlling energy-usage, it permits companies to get informed about the energy-
consumption of their power grid in real-time, but may also predict how much energy they will
consume under different circumstances. It allows making adaptations to increase the productivity
and reduce energy waste.
How it works
First of all, it is necessary to group consumers, for example office, compressors, heating, lighting… .
An electrical scheme of the company’s power grid is indispensable for doing this. Second, secondary
analysers must be determined, like temperature analysers for heating installation or sunlight-
measurement devices for lighting installations. When all these variables are set, the necessary
measurement devices can be installed at the right places and energy monitoring can start. The data
retrieved by the measurement devices has to be captured and saved by the software.
The data will be plotted in a graph to define a base-line for the energy consumption. The
consumption can also be used in a scatter pot against other variables like temperature or light-
intensity. The best fit line is an image of the general energy consumption. The interception of this
line with the y-axe gives an idea of the minimum energy consumption. If this is very high, there could
be faults in the power grid causing unnecessary energy consumption. The slope gives an idea of the
efficiency and the scatter gives an idea of variability.
The difference between measured values and expected values can now be monitored. Possible
variations can be identified and the company is now able to set new goals for the future. This all has
to be repeated at specific time points, resulting in adjustments that will lead to a lower energy-
consumption as well as a lower energy-cost.
Following data retrieval from the measurement devices, the cycle starts all over again. This way, the
company will keep improving and the newest technologies will be implemented.
9
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Matlab is an easy-to-use environment for numerical calculation and simulation. It is also usable for
programming as it has its own programming language, called ‘M-code’. The software is developed by
THE MATHWORKS in 1984 and is commonly used in companies as well as academic institutions.
Several extensions in the Matlab-software, called ‘Toolboxes’, make it possible to calculate and
simulate problems without the need of writing Matlab code. This makes the software very easy to
use, fast and inviting.
As mentioned previously, Matlab has several extensions, one of those ‘Toolboxes’ is called Simulink.
In Simulink the user can create block diagrams for the simulation of divers problems. It is most of all
used as a computer model for dynamical systems, but can also be used for complex math problems.
The biggest advantage of Simulink is the user friendliness, it gives the opportunity to construct
complicated models in a clean and transparent way and makes it possible for outsiders to quickly
understand and adjust the program.
This thesis is organized in 5 chapters. This chapter is the introduction. The second chapter provides
the information about the power analysers and the used communication protocol for connecting the
power analysers with the software. Chapter three gives an overall look at the electrical grid, explains
the components of the Simulink model and the Matlab code. In chapter four case studies where
done to check the reliability of the program. Chapter five concludes the work and gives a word of
appreciation to the people involved in this work.
10
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
The power analysers used for this thesis are of the type JANITZA UMG 96RM EL. The analysers are
suitable for measuring, recording and monitoring electrical parameters in low and medium voltage
networks, 1 and 3-phase systems and with a neutral conductor. The device has a compact
construction, high data security and a large measured data memory.
2.1.1 Specifications
Measurement accuracy
It has a reliable measurement accuracy of 0.2% (V) and effective energy class (kWh-class) of 0.5.
The kWh-classes are defined and used in IEC and ANSI standards. kWh-class of 0.5% means that the
power analyser has an accuracy better than ± 0.5% of the nominal reading (Janitza, 2016). The max
current is 5 A effective.
Communication options
Numerous interfaces and protocols, guaranteeing an easy system connection over Ethernet, Profinet,
Modbus, M-Bus, … (Janitza, 2016). In this project the Ethernet (TCP/IP) communication is used.
Harmonics analyser
It can measure up to the 40th harmonic and provides information about the power quality, grid
disturbances and possible “network polluters”.
11
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
2.1.2 Installation
The UMG 96RM-EL can be used for voltage measurement in TN, TT and IT systems. Voltage
measurement in the UMG 96RM-EL is designed for the 300 V overvoltage category CATIII (4 kV rated
pulse voltage). Figure 2.2 shows the principle circuit diagram of how the measurement device is
connected for the voltage measurements.
The current measurement is done with use of 50/5 A current transformers (Figure 2.3).
Figure 2.2 Connection diagram voltage measurement Figure 2.3 Connection diagram current measurement
(Janitza, Operating instructions and technical data, 2016) (Janitza, Operating instructions and technical data, 2016)
12
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
2.2 MODBUS
In 1979 the company Modicon developed a serial communication protocol for their programmable
logic controllers (PLCs). From that moment this protocol was expected as the unofficial standard
because of its simplicity and robustness. It offers communication between client /server on various
networks or many different buses, it even is despite its old age still the standard today.
Nowadays MODBUS is still growing and is able to work with Ethernet and TCP/IP. The protocol is very
easy to implement as it uses the same application layer for all the different physical layers, as shown
in Figure 2.4.
13
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
When a client requests to connect with a server, the function code field consists of 1 byte and tells
the server what kind of action it must perform. A value of “0” is not valid. Sometimes sub-function
codes are added to define multiple actions. The data field contains, in this situation, additional
information needed for the action that the server must execute. A value of “0” is valid for the data
field, in this case the function code alone specifies the action and addition information is not
required.
The server will send the requested data to the client and the server simply echoes the original
function code (Figure 2.6). This only when there are no errors. When an errors does occur, the PDU
will contain an exception code which matches the error (Figure 2.7).
14
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
The model is based on a series of tables that have distinguishing characteristics. The four primary
are:
The user needs to implement different function codes for all four blocks. For example the function
code (0x02) is needed to write data to the discrete input and code (0x05, 0x0F) could be used to
write data to the coils. (Figure 2.8)
It is possible to consider all 4 tables as overlaying one another, if this is the best way of interpreting
the target machine in question. In this case the user can implement the function code (0x04) to get
the statuses for the whole register or he can ask just for one bit in the register using the function
code (0x02) for the read discrete input. (Figure 2.9)
Figure 2.8 Implement function code (Modbus, 2012) Figure 2.9 Implement function code (Modbus 2012)
15
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
the PDU. Decimal codes in the range 1 … 255 are valid, but those In the range of 128 … 255 are
reserved for exception responses.
The public function codes are validated by the MODBUS.org community and therefor guaranteed to
be unique. The codes are well defined and publicly documented. (Figure 2.10)
The User defined function codes can be applied by anyone and are not supported by the
specifications. There is no guarantee that this code is unique and therefor it could already be
implemented by another user. Two ranges are assigned to this code, in particular range 65 to 72 and
100 to 110. (Figure 2.11)
The reserved function codes are used by companies for legacy products and are not available for
public use.
16
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
As an example of how a MODBUS PDU message is assembled, the reading of holding register from a
remote device will be fully explained. The request message to the server is assembled as followed:
the first byte is the function code, in this case 03 (hexadecimal), the following 2 bytes are the starting
address and the last 2 bytes are the quantity of holding registers. The starting address starts at “0”,
therefor numbers 1 to 16 are addressed as 0 to 15.
The response’s first byte consists of a function byte equally to the one in the request. The second
byte gives information about the byte count, which specifies the quantity of complete bytes of data.
The remaining bytes are the register value which contains N x 2 bytes, with N defined as the quantity
of bytes that the byte count register specifies.
17
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Figure 2.13 Function for reading the holding register (Modbus, 2012)
Figure 2.13 shows a read holding register function. The server receives a request from a MODBUS
client and checks if the server supports the send function code. If the code is not valid, an exception
code is send. If it’s valid, 3 more checks are done. If all are good, a response message is send to the
client.
18
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
1. MODBUS request: the message sent on the network by the client to initiate a
transaction.
19
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
The Transaction Identifier determines a MODBUS request or response. It is initialized by the client
and recopied by the server. The identifier must be unique, as it is used to associate the future
response with the request.
The Protocol Identifier is used for intra-system multiplexing (Transmit a number of separate signals
simultaneously over a single channel or line). This is always “0” as there is always only 1 signal
transmitted. This field is also recopied by the server from the received request.
The Length defines the number of following bytes, including the Unit Identifier and the PDU. The field
is initialized by the server for the response.
The Unit Identifier carries the MODBUS slave address of the remote device if the device is part of a
MODBUS serial line sub-network. With TCP/IP the server is addressed with an IP address, therefor
the Unit Identifier is useless and the value must be set to 0xFF. The field is set by the MODBUS client
in the request and must be returned with the same value in the response by the server.
20
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Example: MODBUS request ADU encoding for reading the register #5 in a remote server.
MODBUS Request ADU encoding :
Transaction Identifier is randomly chosen as 0x1501, the only condition is that the client as well as
the server uses the same value for the request and the response. The Protocol Identifier is “0” as
always in TCP/IP communication. The Length is here “6” this because there are 6 bytes needed for
the following fields. 1byte Unit Identifier, 1 byte Function Code, 2 bytes Starting Address and 2 bytes
Quantity of Registers. The Unit Identifier is always “0xFF” for TCP/IP. The Function Code is here 0x03
as it is a request to read the holding registers (see Figure 2.10). The Starting Address is “0x004”
because the intension is to read register “5”. As the count of registers starts with “0”, meaning that
register 1-5 becomes address 0-4. The quantity of Registers is “1” as there is only 1 register
requested.
21
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
GECAD, Research Group on Intelligent Engineering and Computing for Advanced Innovation and
Development, is a research unit settled in the Institute of Engineering - Polytechnic of Porto
(ISEP/IPP) having as mission the promotion and development of scientific research in the Knowledge
and Decision Sciences domains, having Information Technologies as support. It involves 2 main areas:
Intelligent Systems and Power Energy Systems. GECAD is known worldwide in its areas of research,
leading some research domains. (GECAD,2016)
22
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
In this chapter the entire created solution is presented in an overview and the parts are explained in
detail. As it is not easy to give a full explanation of a Simulink model, nether trying to understand it,
without using it. Dividing the program in a lot of small chapters seemed to be the best approach. The
explanation starts with analysing the overall model and all its components in chapter 3.2.1. These
components have underlying layers of sub-models called subsystems. The chapters 3.2.2, 3.2.3, 3.2.4,
3.2.5 and 3.2.6 each explain such a subsystem. These subsystems contain some sub sub-models,
therefor these chapters contain smaller chapters.
23
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
24
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
25
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Why not use a ‘TCP/IP Receive block’ (Figure 3.6) instead of writing a total new code? The code in
this block has been developed specially for this project, because a normal TCP/IP Receive block does
not support every brand of power analyser. The block can only function if there is a support block
implemented. These blocks are downloadable from the brand’s website, but there is no support
block for a JANITZA power analyser. The Matlab code used in “Interpreted Matlab Function block” is
fully explained in chapter “3.3 Matlab code for the MODBUS TCP/IP connection”.
Figure 3.5 TCP/IP Receive block (MathWorks, 2016) Figure 3.6 Interpreted Matlab Function block
26
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
27
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
28
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
The big advantage of using Simulink is that the user can simply adjust the model and measure all the
things he wants. For example: By implementing an extra scope and connecting it with a current, a
graph of the current and time can be created. This graph is visible during the simulation and can
provide important information.
In the middle three identical calculation are made, in particular the calculations for the current in
each Phase. See Figure 3.11 for the calculation of the current in the first phase (L1) of bus B1, the
calculations for phase 2 and 3 or similar. The current flowing through bus B1 is the difference of the
current in power analyser L2B and power analysers L1A, L4A_2. This can be easily verified by
watching “3.1.2 Details of the grid / Figure 3.1”. The calculations have to be performed with complex
numbers as the currents are complex.
29
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
The next step is to calculate the true power and reactive power in every line, The total true and
reactive power, the total apparent power and the total cos(𝜑). (Figure 3.12)
“3.1.2 Details of the grid” clarifies that the current flowing through bus B2 is the current coming from
the power supply reduced with the current flowing through meter L2A, L3B and L4B_1.
30
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
The current flowing through bus B3 is the difference of the current in meter L3A and meter L4B_2.
Bus B4 has a current that depends on the configuration of the network. In normal circumstances it is
directly connected to meter L1B, but if necessary the power can also be delivered from the lines
connected to meter L4A_1. As there is no meter after this bus, the voltage drops can’t be measured
here.
Important for the measurements in this bus is that the connected line is always specified in the
Simulink model. Therefor a switch block is used, giving the model displayed in Figure 3.13.
31
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
The Voltage drops over the cable can be calculated by decreasing the voltages measured by the two
meters. Therefor an extra part has to be implemented in the calculation sub network. This part is
presented in figure 3.15.
32
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
In chapter “3.2.3 Power analyser subnetwork” the Simulink block “Interpreted Matlab Function
block” has been introduced. This block is used to connect the Simulink model with the Matlab file
used for the MODBUS TCP/IP connection. The Simulink block transfers a value of “800” to the Matlab
file, the Matlab file runs his code and afterwards an array of 10 values is send to the Simulink model.
The array contains values that where measured by the power analysers and transferred to the user
using a MODBUS TCP/IP connection. (Figure 3.16)
The complete Matlab code can be found in the appendix on the last pages of this work. The flow
chart of the Matlab code is visualised in Figure 3.18.
The IP address of the analyser where the data is retrieved from is in this case meter L1A. By default,
the TCP/IP object has an Inputbuffersize of 512, which means it can read 512 bytes at a time. The
object doesn’t have to be this big, but leaving it on the default value is easier and doesn’t cause any
consequences. MODBUS TCP/IP always uses port 502 and a ‘big-Endian’ representation for addresses
and data items.
An error occurs when the program fails to connect with the power analyser.
Transaction ID: This can be any arbitrary number. Typically the value is incremented by 1 every time
a message is send. The power analyser will mirror this number in its response to
specify which request is answered, see chapter “2.2.1 MODBUS application protocol
header”.
33
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Length: The Length is here “6” this because there are 6 bytes needed for the following fields.
Unit ID: The Unit Identifier is always “0xFF” for TCP/IP in theoretical models. But this didn’t
work in the lab of GECAD. By testing the discovery of other working values was done.
with the value “0”, the connection was easily made. A reason for the malfunctioning
with a unitID of “0xFF” (Hex) or “255” (Dec), could be that this value is reserved for
communication with a particular device in the subnetwork.
Function Code: This is a number that corresponds to a specific function code that instructs the device
what to do. In this case the goal is to read the holding registers of the power analyser
and therefor the value is 3 (see chapter 2.2.1.3 Function codes).
Add: The address of the starting register is set by the value that the Simulink model
transferred at the beginning of the run. For this project it is always “800” as it’s the
first register needed. Information about the registers of the Janitza UMG 96RM-EL
power analyser is available in the product datasheets. Figure 3.17 shows a fragment
of the datasheet with all the information needed for assigning the registers.
(Janitza electronics GmbH, Power Analyser UMG 96RM Modbus-address list and Formulary).
Val: Here all the registers needed for the simulation are chosen. The last register needed
is “864: Current I3 L3”. This means there are 65 registers needed. Every register is 2
bytes so the reading starts at register 800 and contains 130 bytes of information.
The message is now composed and the program can write it to the device (line 37).
The program will first wait for the response using a while-loop. When the response is available the
while-loop is ended and the program continues running. The received data is than saved as a variable
“res”.
10 values have to be retrieved from the meters to have all the information requested for the
simulation. Consequently the frequency (registers 800-801), the RMS-values (Root Mean Square
value) of the line-neutral voltages (registers 808-813), the cos(ϕ) or fundamental power factor
(registers 820-825) and the RMS-values of the currents of the three phases (registers 860-865). The
demanded values are retrieved from the response by searching the corresponding bytes. The value
of the first register will start at byte 10 and every value takes 4 bytes. Meaning that the demanded
values are found as followed.
34
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Figure 3.17 MODBUS address list for Janitza UMG 96RM-EL (Janitza, Power Analyser UMG 96 RM-EL , 2016)
For converting all the other values the same code is used, with different variables. (line 79-272)
35
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Figure 3.18 Flow chart of Matlab code the MODBUS TCP/IP connection
36
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
4. Case studies
By testing the program for different kinds of loads, the reliability and accuracy of the program can be
rated. Starting with small simple loads and building up to big divers ones make it possible to figure
out where the program has difficulties.
Testing this connection can be done very easily by using a network protocol analyser. The one used in
this case was WireShark version 2.0.2 because it is free and easy to use. Figure 4.1 contains a
screenshot while WireShark captures one request and one answer from a pc to the meter “power
supply” with IP-address 192.168.2.245 and the total transaction took about 20 ms (from 9.287370 s
to 9.307585 s).
Figure 4.1 Screenshot of Wireshark capturing 1 request and answer of Meter Power Supply
To determine the ideal fixed-step size, a test was done with a value of 10 ms. The captured data from
Wireshark made clear that every new request was done after more than 10ms, meaning that the
ideal fixed-step size will be bigger. To determine the time, an average time between request was
calculated (Table 4.1). The Average time between requests for 30 requests was 0.178492345 s,
meaning that a fixed-step size of 0.15 s will be ideal.
37
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
The simulation step time of the Simulink model can be put to “inf” (infinitive) this way the simulation
can run as long as needed. To stop the simulation, a simple push on the “stop” button is enough.
38
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
For the implementation of the resistant load bus B1 was used. The results of the test are visible in
Figure 4.2.
The total simulation time was 100 seconds (s), meaning that the scale of the horizontal axe for this
simulation is 1/18 s. The chosen fixed-step time (fundamental sample time) was 0.15 s, meaning that
every 150 milliseconds new values where requested and received from the power analysers. The
load was implemented in the grid after 40 s. The graph of the measured currents shows that there is
already some energy consumption after 20 s, before the implementation of the load. The explanation
for this is that the installation of the resistant load contains fans to keep the temperature at a normal
level. The fans start working as soon as the installation gets connected with the grid. Another
observation is that the fans only seem to work on one line, more specific line 2. The measured
current after the implementation of the load is 2 ampere (A) for line 2 and 1.3 A for lines 1 and 3.
When the consumption of the fans is not taken in account, the current is 1.3 A and the same for each
line. The measured active power (P) is 1149 watt (W) this is very close to the theoretical value (1kW)
of the load. The Fundamental power factor (cos(ϕ)) and the reactive power (Q) is almost negligible
and is caused by the fans.
Overall can be concluded that the measured powers and currents are trustable for this kind of loads.
39
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
40
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
The measurement was done in 100 seconds, meaning that the horizontal axes have a scale of 1/18
seconds. The fixed-step size was 0.15 s. Based on the retrieved data during the simulation (see Figure
4.3) can be concluded that the apparent power is almost entirely defined be the reactive power,
respectively 7504 VAR and 7520 VA. The cos(ϕ) is close to zero and the real power is negligible in
comparison with the reactive power. The apparent power is not 4kVA as could be expected, this
because the load wasn’t fully used. Some peaks can be spotted around 18 s and 36 s, the peak at 18 s
was caused by connecting the capacitive load installation to the power grid and the peak at 36 s has
the implementation of the capacitive component as cause.
The measured values match perfectly with the theoretically expected values and seem trustable.
The results of the simulation are presented in Figure 4.4 with a horizontal axis scale of 1/15. Fixed-
step size 0.15 s. After 20 s the engine was connected with the power grid. The cos(𝜑) is 0.16 and the
apparent power is defined by the reactive power. The copper losses cause an active power
consumption of 101 W. All possible values for an inductive load.
41
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
42
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
43
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
44
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Figure 4.6 shows the consumption of all the loads plus the 2 cables. As the load of the cables is
negligible to that of the loads in the busses, the measured values depend only on the loads. The
resistive load (Bus B2) has a total power of 1149 W and 92 VAR (values from previous measurement
in chapter ‘4.2 Resistant load’ ), the capacitive load (Bus B1) has a total power of 440 W and 6000 VA
(CAP) (see left graphs on Figure 4.5) and the inductive load 101 W and 641 VAR (IND). This should
give a total of √(1149 + 440 + 101)2 + (92 + 6000 + 641)² = 6941 VA, 1690 W and 6733 VAR
and that is very near to what the middle graph of Figure 4.7 shows.
Given this, the program can be described as trustable and accurate for the real time simulation of a
power grid.
45
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
46
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
47
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
5. Conclusion
This thesis work focused on developing a real-time simulation tool for monitoring an electrical grid.
The monitoring was done by JANITZA UMG 96RM EL power analysers, the connection was done over
Ethernet using MODBUS TCP/IP as communication protocol and the programmable environment was
Matlab/Simulink. As it is a simulation tool that does not depend on a specific brand of power
analysers, the program can be used for all types of power analysers.
In a world where the demand for energy is growing and energy consumption is higher than the
natural resources are able to supply, all help is welcome to find solutions and this work is one. Via
the energy monitoring system developed in this work, the users are able to check their energy
consumption and adept where needed.
This work can serve as a foundation for companies to develop a same system in their environment. It
is also much more user friendly than the software program Janitza developed. Furthermore, extra
studies can use the same techniques in different programmable environments. GECAD can use this
work for measurements in their laboratory and can further develop it in the scope of future energy
monitoring systems.
48
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Bibliography
49
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
50
Anthony Peleman
Modbus TCP/IP connection of power analysers for real-time monitoring of a demonstration microgrid: A Simulink approach
Appendix
Note: The appendix is not publicly published, for looking into this please contact ISEP or
GECAD.
51
Anthony Peleman