Design and implementation of a plug-in power metering device

90
Design and implementation of a plug-in power metering device Carlos de Almeida Santos de Castro e Abreu Thesis to obtain the Master of Science Degree in Electronics Engineering Supervisors: Prof. Pedro Miguel Pinto Ramos Examination Committee Chairperson: Prof. Paulo Ferreira Godinho Flores Supervisor: Prof. Pedro Miguel Pinto Ramos Members of the Committee: Prof. S´ onia Maria Nunes dos Santos Paulo Ferreira Pinto September 2020

Transcript of Design and implementation of a plug-in power metering device

Page 1: Design and implementation of a plug-in power metering device

Design and implementation of a plug-in power meteringdevice

Carlos de Almeida Santos de Castro e Abreu

Thesis to obtain the Master of Science Degree in

Electronics Engineering

Supervisors: Prof. Pedro Miguel Pinto Ramos

Examination Committee

Chairperson: Prof. Paulo Ferreira Godinho FloresSupervisor: Prof. Pedro Miguel Pinto Ramos

Members of the Committee: Prof. Sonia Maria Nunes dos Santos Paulo Ferreira Pinto

September 2020

Page 2: Design and implementation of a plug-in power metering device
Page 3: Design and implementation of a plug-in power metering device

Declaration

I declare that this document is an original work of my own authorship and that it fulfills all the require-

ments of the Code of Conduct and Good Practices of the Universidade de Lisboa.

i

Page 4: Design and implementation of a plug-in power metering device
Page 5: Design and implementation of a plug-in power metering device

Declaracao

Declaro que o presente documento e um trabalho original da minha autoria e que cumpre todos os

requisitos do Codigo de Conduta e Boas Praticas da Universidade de Lisboa.

iii

Page 6: Design and implementation of a plug-in power metering device
Page 7: Design and implementation of a plug-in power metering device

Acknowledgments

Gostaria de expressar toda a minha gratidao e apreco a todos aqueles que, directa ou indirecta-

mente, contribuıram para que este trabalho se tornasse uma realidade.

Ao Prof. Pedro Ramos e Sr. Pina por toda a orientacao, apoio e disponibilidade ao longo deste

processo.

Aos meus amigos, Sebas, Afonso, Pedro e Hugo, por todas as discussoes tecnicas e menos

tecnicas.

Aos meus amigos, Pico, Joana, Rita e Bruno por todo o companheirismo e palavras de incentivo.

Ao grupo de sempre (TG) por nunca me deixarem esquecer que existe sempre um lado bom da

vida.

Ao Rodrigo, pelas distracoes e incentivo ao desenvolvimento de um novo hobby.

As minhas irmas, Mariana e Sofia, por sempre acreditarem em mim mesmo quando eu nao o fiz.

Aos meus pais, Paula e Carlos, por sempre primarem pela minha educacao e por toda a forca e

carinho que me tem transmitido ao longo da vida.

A Lara, uma companheira eterna para a vida que nos espera, pela paciencia angelical.

A todos voces, os meus sinceros agradecimentos.

v

Page 8: Design and implementation of a plug-in power metering device
Page 9: Design and implementation of a plug-in power metering device

Abstract

This project focuses in developing and implementing a device capable of monitoring the electric

power consumption of an appliance connected to the 230 V, 50 Hz power grid.

The device presents a Schuko CEE 7/4 to connect to the grid and on the other end a Schuko CEE

7/3. The appliance maximum current is 16 A. A specific energy metering Integrated Circuit (IC) is used

and sensing circuitry is included for voltage and current, to attenuate the grid’s voltage to the Analog-

to-Digital Converter (ADC)’s input range of the IC and convert current drawn into a differential potential,

once again taking into consideration the input range.

The system includes a non-volatile memory where measured values are stored. The files format

will be readable by any modern device, for example a smartphone or a computer. The system also

comprises a wireless communication module, to offer system management (e.g. period between saved

values) and data analysis options (e.g. graphs) to the user without interrupting the data acquisition.

Avoiding the necessity to take the Secure Digital Card (SD Card) out of the metering device to view the

results, which requires the system to be halted.

The device is based on a Peripheral Interface Controller (PIC) microcontroller from Microchip, which

manages data processing and communication with the energy metering IC, SD Card and bluetooth

module.

Keywords

Energy metering, Single Phase, Embedded System.

vii

Page 10: Design and implementation of a plug-in power metering device
Page 11: Design and implementation of a plug-in power metering device

Resumo

Este projeto tem como foco o desenvolvimento e implementacao de um dispositivo capaz de moni-

torizar o consumo eletrico de um eletrodomestico ligado a rede eletrica de 230 V, 50 Hz.

O dispositivo apresenta-se ligado a rede eletrica atraves de um conector Schuko 7/4 e na outra

extremidade a um Schuko 7/3. A corrente maxima do eletrodomestico e de 16 A. Um IC especıfico para

a medicao de energia e usado bem como circuitos de condicionamento de tensao e corrente, com o

intuito de atenuar a tensao da rede para a gama de tensoes de entrada dos ADCs do IC e converter

a corrente consumida numa diferenca de potencial, mais uma vez tendo em consideracao a gama de

tensoes de entrada.

O sistema inclui uma memoria nao-volatil onde os valores medidos sao armazenados. O formato dos

ficheiros sera legıvel por qualquer dispositivo moderno, por exemplo, um smartphone ou computador. O

sistema tambem inclui um modulo de comunicacao sem fios, para disponibilizar ao utilizador a gestao

do sistema (ex. intervalo entre valores guardados) e opcoes de analise de dados (ex. graficos) sem

interromper a aquisicao de dados. Caso contrario, seria sempre necessario retirar o cartao de memoria

do dispositivo de medicao para visualizar os resultados, o que requer que o sistema seja interrompido.

O dispositivo e baseado num microcontrolador PIC da Microchip, que gere o processamento de

dados e a comunicacao com o IC medidor de energia, cartao de memoria e modulo bluetooth.

Palavras Chave

Contador de Energia, Monofasico, Sistema Embebido.

ix

Page 12: Design and implementation of a plug-in power metering device
Page 13: Design and implementation of a plug-in power metering device

Contents

1 Introduction 1

1.1 Purpose and motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.2 Goals and challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.3 Electric Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.4 Signal Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.5 Document organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2 State of the Art 11

2.1 Voltage Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.1.1 Hall effect Voltage Transducer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.1.2 Voltage Transformer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2.1.3 Resistive divider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2.2 Current Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2.2.1 Shunt resistor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2.2.2 Current Transformer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2.2.3 Hall Effect Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

2.2.4 Rogowski Coil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

2.3 Wireless Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.4 Non-volatile memory - SD Card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.5 Previous Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2.5.1 Intelligent Electric Energy Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2.5.2 Develop, implement and characterize an electric energy monitoring device . . . . 20

2.5.3 Electric energy meter for low voltage usage . . . . . . . . . . . . . . . . . . . . . . 21

2.5.4 A Low-cost Wi-Fi Smart Plug with On-off and Energy Metering Functions . . . . . 21

2.5.5 Data acquisition and control using Arduino-Android Platform : Smart plug . . . . . 22

2.5.6 Development of Embedded System for Making Plugs Smart . . . . . . . . . . . . . 23

2.5.7 Power-Efficient Smart Metering Plug for Intelligent Households . . . . . . . . . . . 24

xi

Page 14: Design and implementation of a plug-in power metering device

3 System Architecture 25

3.1 Microcontroller - Microchip PIC24F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

3.2 Energy meter IC - ADE7753 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3.3 Signal conditioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

3.3.1 Voltage sensor - Resistive divider . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

3.3.2 Current sensor - Shunt resistor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

3.4 Bluetooth module - Itead HC-05 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

3.5 Memory - SD Card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

3.6 Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

3.7 Mobile Application (APP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

3.8 Software - PIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

4 Results 51

4.1 Energy meter IC - ADE7753 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

4.2 SD Card and Real Time Calendar-Clock (RTCC) . . . . . . . . . . . . . . . . . . . . . . . 54

4.3 Bluetooth module - Itead HC-05 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

4.4 Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

4.4.1 Voltage Root Mean Square (RMS) and Current RMS . . . . . . . . . . . . . . . . . 56

4.4.2 Active and Apparent Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

4.4.3 Reactive Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

4.5 Final Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

5 Conclusions 61

xii

Page 15: Design and implementation of a plug-in power metering device

List of Figures

1.1 Power vectors triangle from [7]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1.2 Three examples of waveform sampling (6 samples) adapted from [11]. . . . . . . . . . . . 7

1.3 Replication of the signal spectrum to be acquired due to the signal sampling process [11]. 9

2.1 Operating principle of closed loop voltage transducer adapted from [15]. . . . . . . . . . . 14

2.2 Voltage sensor with resistive divider [7]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2.3 Implementation of a shunt resistor [7]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2.4 Implementing an integrator using an Operational Amplifier (OPAMP) [17]. . . . . . . . . . 17

2.5 System diagram adapted from [9]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2.6 Application Screens [7]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2.7 Network design [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

2.8 System block diagram [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.9 Voltage sensor circuit [18]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

2.10 Block diagram of the efficient smart plug [37]. . . . . . . . . . . . . . . . . . . . . . . . . . 24

3.1 Energy meter architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

3.2 PIC24FJXXXGA010 pin diagram [23]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

3.3 PIC24FJXXXGA010 clock diagram [23]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.4 ADE7753 functional block diagram [2]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3.5 ADE7753 channel 1 offset range with gain set to 1 [2]. . . . . . . . . . . . . . . . . . . . . 34

3.6 ADE7753 Active Power calculation [2]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

3.7 ADE7753 Active Power calculation block diagram [2]. . . . . . . . . . . . . . . . . . . . . . 35

3.8 ADE7753 Reactive Power calculation block diagram [2]. . . . . . . . . . . . . . . . . . . . 36

3.9 ADE7753 Apparent Power calculation block diagram [2]. . . . . . . . . . . . . . . . . . . . 36

3.10 HC-05 pin diagram [4]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

3.11 HC-05 module [4]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

3.12 SD Card Serial Peripheral Interface (SPI) interface [7]. . . . . . . . . . . . . . . . . . . . . 40

xiii

Page 16: Design and implementation of a plug-in power metering device

3.13 SD Card folder structure (red: folder path, yellow: file name). . . . . . . . . . . . . . . . . 41

3.14 Power Supply Unit (PSU) diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

3.15 IRM-15-12 block diagram [46]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

3.16 LM2575 block diagram [47]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

3.17 MCP1825 block diagram [48]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

3.18 Application screen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

3.19 Data review feature. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

3.20 Live data feature. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

3.21 Main loop flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

3.22 Data buffers management functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

3.23 ADE7753 interrupt function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

4.1 Software reset request. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

4.2 Successful software reset. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

4.3 Printed Circuit Board (PCB)’s front view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

4.4 PCB’s back view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

4.5 Alcor HS100. [50] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

4.6 Measured RMS voltage and RMS current from a resistive load. . . . . . . . . . . . . . . . 58

4.7 Measured apparent, active and reactive power from a resistive load. . . . . . . . . . . . . 58

4.8 Measured RMS voltage and RMS current from a rated 65 W laptop charger. . . . . . . . . 59

4.9 Measured apparent, active and reactive power from a rated 65 W laptop charger. . . . . . 60

xiv

Page 17: Design and implementation of a plug-in power metering device

List of Tables

1.1 System specifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.1 Main characteristics of wireless technologies. . . . . . . . . . . . . . . . . . . . . . . . . . 18

3.1 Oscillator configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.2 PIC Universal Asynchronous Receiver-Transmitter (UART) error rate for various baud

rates for high-speed and standard mode [23]. . . . . . . . . . . . . . . . . . . . . . . . . . 31

3.3 ADE7753 maximum input signal levels for channel 1 [2]. . . . . . . . . . . . . . . . . . . . 33

3.4 ADE7753 offset correction range for channel 1 and 2 [2]. . . . . . . . . . . . . . . . . . . . 33

3.5 HC-05 current consumption [43]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

xv

Page 18: Design and implementation of a plug-in power metering device

xvi

Page 19: Design and implementation of a plug-in power metering device

xvii

Page 20: Design and implementation of a plug-in power metering device

Acronyms

AC Alternate Current

ADC Analog-to-Digital Converter

AP Access Point

APP Application

ARM Advanced RISC Machine

ASCII American Standard Code for Information Interchange

BLE Bluetooth Low Energy

CPU Central Processing Unit

CRLF Carriage Return Line Feed

CSV Comma-Separated Values

CT Current Transformer

CTS Clear to Send

DC Direct Current

dsPIC Digital Signal Peripheral Interface Controller

EDR Enhanced Data Rate

FAT File Allocation Table

FRC Fast Internal Oscillator

GSM Global System for Mobile Communications

I2C Inter-Integrated Circuit

xviii

Page 21: Design and implementation of a plug-in power metering device

IC Integrated Circuit

IDE Integrated Development Environment

I/O Input/Output

IDE Integrated Development Environment

IEC International Electrotechnical Commission

IoT Internet of Things

LAN Local Area Network

LCD Liquid Crystal Display

LSB Least Significant Bit

LPF Low-Pass Filter

MCUs Microcontroller Units

OPAMP Operational Amplifier

PIC Peripheral Interface Controller

PCB Printed Circuit Board

PF Power Factor

PGA Programmable Gain Amplifier

PLC Power-line Communication

PLL Phase-Locked Loop

PSU Power Supply Unit

RMS Root Mean Square

RS-232 Recommended Standard 232

RTCC Real Time Calendar-Clock

RTS Request to Send

SD Card Secure Digital Card

SoC System-on-a-chip

xix

Page 22: Design and implementation of a plug-in power metering device

SPI Serial Peripheral Interface

SMD Surface Mounted Device

UART Universal Asynchronous Receiver-Transmitter

USB Universal Serial Bus

VT Voltage Transformer

WAN Wide Area Network

xx

Page 23: Design and implementation of a plug-in power metering device

1Introduction

Contents

1.1 Purpose and motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.2 Goals and challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.3 Electric Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.4 Signal Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.5 Document organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1

Page 24: Design and implementation of a plug-in power metering device

2

Page 25: Design and implementation of a plug-in power metering device

Introduction

1.1 Purpose and motivation

The XIX century was marked by the spread of electric energy starting with street lighting and later

on in households, to power telegraphs, telephones, radios and televisions succeeded by modern appli-

ances, such as fridges and washing machines. The demand for electric energy will only tend to increase

as the world moves to a more interconnected society with data centers working around the clock [1].

This consumption of the modern era comes as a service and with it came the need to meter it for billing

purposes. Two centuries passed by and nowadays the need to monitor the electric energy consumption

goes beyond billing. This includes balancing the power grid based on demand in real time and patterns

from previously logged information. Furthermore, the need of better knowing the load patterns of an

equipment; where it can be a steady load or its consumption may be arranged in short bursts, lead to

the development of more advanced plug-in power meters.

The objective of the prototype to be designed is a compact and remotely accessed energy metering

device, where the measured power consumption is limited to one single mains appliance. This project

describes the design, development and implementation of a plug-in power meter. Aside from the basic

role expected from an energy meter, other functionalities characterise this device, meaning real time

monitoring, long term logging, control of relevant parameters, wireless connectivity for an improved user

experience.

The energy metering device will work as a man-in-the-middle; where the device is connected to the

mains, and the load to a Schuko connector present on the developed device. Data about voltage, current,

instant and accumulated power consumption will be acquired. A non-volatile memory; a SD Card, is

present for long term logging up to a month. Moreover, the user will resort to an application on a

smartphone to review data and adjust parameters.

3

Page 26: Design and implementation of a plug-in power metering device

1.2 Goals and challenges

The primary objective of this work is to develop a compact device able to monitor the electrical

power consumption of an Alternate Current (AC) equipment. The project must acquire data for a long

period of time and register on non-volatile memory, connect to the mains through a Schuko CEE 7/4

connection and pass-through to the metered equipment with a Schuko CEE 7/3 connection. A metering

IC [2], current and voltage sensing circuitry is required for the measurement. As for processing unit, the

embedded system must be based on a PIC [3]. A wireless interface [4] in conjunction with a smartphone

application shall be integrated for live monitoring and download of the acquired data, improving the user

experience. As such, the goals for this project are to develop:

• An embedded measurement system;

• Firmware capable of performing processing and routing of data;

• Metering IC conditioning circuit;

• Power supply;

• Integration of non-volatile memory;

• Wireless interface;

• Smartphone APP.

The system specifications goal is presented in Table 1.1.

4

Page 27: Design and implementation of a plug-in power metering device

Table 1.1: System specifications.

Connector Schuko CEE 7/3 and 7/4

Input Voltage 230 V

Maximum Current 16 A

Wireless Communication Bluetooth or Bluetooth Low Energy (BLE)module

Non-volatile Memory Micro SD Card

Sampling Rate of Voltage and CurrentSensors 27.9 kSPS

Acquired Data active, reactive, and apparent power; currentand voltage RMS

Microcontroller Microchip 16-bit Microcontroller,PIC24FJ128GA010

Energy Meter IC Analog Devices single metering IC,ADE7753

1.3 Electric Power

In the XIX century a battle between two electric energy standards for mass distribution took place,

between Thomas Edison (Direct Current (DC)) and Nikola Tesla (AC). The high distribution cost of DC,

mainly linked to power losses in the line that forced the presence of a power plant no further than 1 mile

away from the end user, as well as the high cost and at the time lack of step-up and step-down voltage

technology for DC [5] encouraged three-phase AC to be implemented. [6]

A load with an impedance purely resistive is when all power consumed by the user is transformed

into transformed energy, light, mechanical, sound, etc. However, not all loads are resistive, and thus

may hold a reactive component, either capacitive and/or in most cases inductive (motors, transformers).

A reactive component generates a phase shift on the sine wave of current that feeds the load.

The power dissipated in terms of resisitive component is called Active Power (P ) expressed typically

in kilowatts (kW), and the reactive component, Reactive Power (Q) expressed in kilovolt ampere reactive

(kVAr). The later, is considered a loss, since it is not converted into other form of useful energy to the

load. Apparent power (S) expressed in kilovolt ampere (kVA) is the amount of electric energy required

to distribute a given (P ); thus S could be equal or higher than P . For a given sinusoidal voltage and

current, apparent power, described by active and reactive power (1.1 and 1.2) as represented in Figure

1.1, remains constant [7].

5

Page 28: Design and implementation of a plug-in power metering device

Figure 1.1: Power vectors triangle from [7].

~S = P + jQ. (1.1)

And

S2 = P 2 +Q2. (1.2)

For a P equal to S, the Power Factor (PF) is unitary; meaning there is no phase shift between

voltage and current. With a PF of one, all the work (P ) can be done with less current. Further is the

gap between voltage and current sine waves (lower PF), the lesser P is transferred in favor of Q. For a

given P , the lower the power factor, higher S is required to compensate Q, leading to a higher current

consumption [8].

Power factor is the ratio (1.3) between P and S,

PF =P

S. (1.3)

Where for sinusoidal waveforms, PF has a direct relationship with the phase shift (φ) between voltage

and current, given by

PF = cos(φ). (1.4)

S (1.5) is given by the RMS value of voltage and the RMS value of current,

S = V RMS × IRMS . (1.5)

6

Page 29: Design and implementation of a plug-in power metering device

From (1.4), a null power factor is characterized by 90 degrees phase shift either from a capacitive

load (-90) or an inductive load (90).

The energy meter should measure P and Q. The later is important specially for customers where

inductive loads are more common (AC motors and transformers) since these loads consume not only P

but also a considerable amount of Q. Since, in a case where the electrical energy distribution company

bills only for P instead of S, it would seem but deceitfully that the customer in question was drawing far

less energy. [9]

1.4 Signal Acquisition

Acquiring a signal is an analog to digital conversion of a time-varying signal, with a fixed sampling

rate. The acquisition of the power outlet will be done with uniform sampling, as the sole purpose is to

acquire a known signal, for example a test was conducted in Enschede (Netherlands) [10] where its

frequency rarely deviates more than 0.2 % from 50 Hz. This process will convert the continuous signal

into a discrete signal; result of the sampling with a small period (discrete time) defined by the sampling

rate and limited by the conversion time of the system.

An ADC deals with the discretization of the signal amplitude into binary code based on the analog

value at the input and resolution; the number of bits of the converter. This data is then processed and

turned into meaningful information through a Central Processing Unit (CPU).

On the other hand, the process of acquiring a waveform trough sampling loses any information be-

tween samples; the same discrete signal may characterize numerous continuous signal as demonstrated

in Figure 1.2.

Figure 1.2: Three examples of waveform sampling (6 samples) adapted from [11].

7

Page 30: Design and implementation of a plug-in power metering device

This phenomena can be explained by the Sampling Theory [11] also known as Nyquist Theorem,

Shannon Theorem or Nyquist-Shannon Theorem that was demonstrated in the first half of the XX cen-

tury [12] [13]. The baseline of this theory shows that for a signal with a limited bandwidth, if acquired

with a sampling rate of at least two times higher than its bandwidth, it is possible to rebuild the original

signal. This approach mitigates the event of sudden variations between samples [11].

The process of sampling corresponds to multiplying the signal desired to be acquired (x(t)) by a sum

of Dirac delta functions analogous to the sampling moments. This sum is also known as unit impulse

symbol is described by

d(t) =

∞∑n=−∞

δ(t− n∆t), (1.6)

where ∆t is the time interval between samples and corresponds to the inverse of the sampling rate

fs =1

∆t. (1.7)

Sampling a signal corresponds to multiply (1.6) by the signal x(t), where the signal value is only kept

at the sampling instants and between them all information is lost,

x(t)× d(t) = x(t)×∞∑

n=−∞δ(t− n∆t) =

∞∑n=−∞

x(n∆t)× δ(t− n∆t). (1.8)

In the frequency domain, (1.8) corresponds to applying a convolution function to the signal spectra

X(f) and the Dirac sum D(f),

TF [x(t)× d(t)] =X(f) ∗D(f)

2π= fs ×

∞∑k=−∞

X(f − kfs), (1.9)

with D(f) defined by

D(f) = TF [d(t)] = 2πfs

∞∑k=−∞

δ(2πf − k2πfs) = 2πfs

∞∑k=−∞

δ(f − kfs), (1.10)

Equation 1.9 describes that the sampled signal spectrum will correspond to the sum of spectral

replicas of the signal to be sampled, X(f). These replicas are centered at the on multiple frequencies

of the sampling frequency, as depicted in Figure 1.3.

In Figure 1.3 there is no overlap of the multiple spectral replicas of the signal to be acquired, since

there is enough margin between the end of the spectrum to be acquired and the start of of the first

spectral replica, present at fs − fmax. To ensure no superposition, fmax < fs − fmax thus leading to the

relation, defined by the Sampling Theory

8

Page 31: Design and implementation of a plug-in power metering device

Figure 1.3: Replication of the signal spectrum to be acquired due to the signal sampling process [11].

fs > 2× fmax, (1.11)

or the Nyquist frequency defined by

fN =fs2> fmax. (1.12)

1.5 Document organization

This document is organized as follows:

• Chapter 1 is a introduction about the project development, choices taken to tackle the the problem

and some considerations about electric power and signal sampling.

• Chapter 2 is the state of the art, in this chapter it is presented some of the work already done in

plug-in power meters with non-mechanical solutions.

• In Chapter 3 the architecture of the proposed system is shown and the selection of components is

detailed.

• Chapter 4 presents the project results.

• Chapter 5 presents the project conclusions and suggestions for future work.

9

Page 32: Design and implementation of a plug-in power metering device

10

Page 33: Design and implementation of a plug-in power metering device

2State of the Art

Contents

2.1 Voltage Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.2 Current Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2.3 Wireless Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.4 Non-volatile memory - SD Card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.5 Previous Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

11

Page 34: Design and implementation of a plug-in power metering device

12

Page 35: Design and implementation of a plug-in power metering device

State of the Art

2.1 Voltage Sensor

The national residential electric grid has an RMS voltage value of 230 V, and ADCs require lower

input voltage; thus there is a need to create a conditioning circuit. There are three methods that could

be implemented:

• Hall effect voltage transducer;

• Voltage Transformer (VT);

• Resistive divider.

2.1.1 Hall effect Voltage Transducer

On an Hall effect based voltage transducer, a primary winding is fed by a current proportional to the

voltage to be measured, generating a magnetic flux. Separated by a small air gap there is a Hall effect

sensor which senses this flux, causing a potential difference at the output. The output can be connected

in a open loop or closed loop [14]:

• in open loop the output of the Hall Effect sensor is the system output; the core can be easily

saturated and is characterized with greater nonlinearity in terms of error with respect to the closed

loop;

• in closed loop the Hall Effect sensor output feds current to a secondary winding, amplified by a

high-gain OPAMP and translated into voltage by a resistor with exactly the same waveform of the

primary current (Figure 2.1);

13

Page 36: Design and implementation of a plug-in power metering device

Figure 2.1: Operating principle of closed loop voltage transducer adapted from [15].

This setup offers galvanic isolation between the high voltage line and the data acquisition system,

providing remarkable linearity and bandwidth compared to transformers [14]. Although, its working

principle makes it susceptible to false readings due to external magnetic fields [16].

2.1.2 Voltage Transformer

A voltage transformer offers a simple solution to step-down the voltage to a suitable range; based

on induction between a primary and a secondary winding. Galvanic isolation can be guaranteed but

considerable volume and high cost must be taken into account. The voltage at the secondary is

VS =nPnS

VP , (2.1)

where VP is the voltage in the primary (RMS 230 V), VS the output voltage in the secondary winding. nP

and nS the number of turns in the primary and secondary winding, respectively [7].

14

Page 37: Design and implementation of a plug-in power metering device

2.1.3 Resistive divider

A resistive divider is a series of resistors to create an attenuation network placed in parallel with the

source. Resistors should be high valued to pull the least current possible; diminishing its effect on the

source. This setup is described by the source voltage, the series of resistors and the desired output

voltage; as shown in Figure 2.2 and defined by

Vout =R2

R1 +R2× VAC . (2.2)

Figure 2.2: Voltage sensor with resistive divider [7].

This configuration is the cheapest of them; although it requires R1 to be a series of multiple resistors

to share the dissipated power across them. The occupied area is small, especially if Surface Mounted

Device (SMD) resistors are used but lacks the advantage of isolating the output from the mains.

2.2 Current Sensor

The load voltage does not vary much contrary to current; thus it is required a wider measurement

dynamic range and frequency range due to rich harmonic contents in the current waveform. There are

several current sensor topologies, such as [17]:

• Low resistance current shunt;

• Current Transformer (CT);

• Hall effect sensor;

• Rogowski coil.

15

Page 38: Design and implementation of a plug-in power metering device

2.2.1 Shunt resistor

A shunt resistor is the cheapest solution for current sensing; with highly stable low values available

in the range of µΩ to mΩ. This resistor should be placed in series with the load, as shown in Figure 2.3.

The voltage across the resistor is proportional to the current flowing through it

I =U

R. (2.3)

Figure 2.3: Implementation of a shunt resistor [7].

Two disadvantages to take into consideration is parasitic inductance and dissipated power. When

performing high precision current measurements even at line frequency, the inductance is generally in

the order of nH but its effect in the phase can be significant enough to cause an error in case of a low

power factor. The heat dissipated by the resistor is proportional to the square of the current flowing and

the smaller its value lesser the heat generated [7] [17].

2.2.2 Current Transformer

A current transformer translates the current flowing through the primary winding, which is connected

in series with the load, into a lower current in the secondary. Among high currents measurements, this

topology is the most common. It’s a low power sensor, having little impact on the measured current and

deals great with high currents. It presents a low phase-shift if calibrated although in extreme cases of

current or substantial presence of DC component it may saturate due to the core characteristics. After

the ferrite core is magnetized, it will show hysteresis with negative repercussions on its accuracy, until

demagnetized [17].

16

Page 39: Design and implementation of a plug-in power metering device

2.2.3 Hall Effect Sensor

As in Hall effect voltage transducers there are open-loop and closed-loop implementations. The first

being the option with lower cost. The system withstands measuring very large current and has a good

frequency response. On the other hand, the output of the Hall effect sensor is sensitive to temperature

and usually requires a stable external current source [17].

2.2.4 Rogowski Coil

A Rogowski coil is an inductor which has mutual inductance with the conductor carrying the current

to be measured. This phenomena makes that a change in the current passing through the wire causes

an induced electromagnetic force in the coil, due to the magnetic field generated. Rogowski coil typically

has a core of air, so in theory there is no hysteresis, saturation or non-linearity. Its low inductance allows

for fast response to current changes and the lack of an iron core makes it respond linearly even at high

currents. These characteristic as well as its smaller size and cost compared to a CT make it a better

option for high current applications, such as, in electrical power transmission. Its output is proportional

to the time derivative of the current

Vout(t) = − 1

RC

∫vin(t) dt, (2.4)

therefore requires an integrator with an OPAMP as shown in Figure 2.4 [17].

Figure 2.4: Implementing an integrator using an OPAMP [17].

17

Page 40: Design and implementation of a plug-in power metering device

2.3 Wireless Communication

Wireless communication offers further flexibility to the system by removing the need of a cable and

by making it more versatile in terms of to what it can connect to. Smartphones lack ethernet ports

and even some laptops nowadays. For the device in development, a short range wireless connection

is ideal for system management since all data is saved locally there is no need to constantly upload

it elsewhere. Embedded systems in general implement short range wireless communication such as

Bluetooth, Bluetooth Low Energy (BLE), WiFi or ZigBee [18]. Table 2.1 presents the main characteristics

of these wireless technologies [19] [20].

Table 2.1: Main characteristics of wireless technologies.

Standard WiFi ZigBee Bluetooth Bluetooth LowEnergy

NetworkTopology Star Star/Mesh Star Star

Data Rate (Mb/s) 54 0.25 3 1

Maximum PowerConsumption 700 mW 75 mW 100 mW 50 mW

Range 100 m 30 m 100 m 30 m

WiFi would be useful for an Internet of Things (IoT) approach since it would be the only standard

implementation that would easily connect to an existing Access Point (AP) connected to the internet.

Although it is the fastest option and with high range, there is no benefit to include the system in a Local

Area Network (LAN) if there is no desire to implement a server to make it accessible outside (Wide Area

Network (WAN)). The current implementation of this project looks to include a wireless interface but not

to make it remote accessible since it would increase the total system cost and complexity.

ZigBee is a low power, highly resilient wireless network type, with range that could match WiFi and

can be further expanded through a mesh topology. But it isn’t commonly offered on smartphones and

laptops, external modules would need to be acquired [21].

Bluetooth or BLE offers enough range for the purpose of the developed system, it is low cost, low

power and is available in virtually any device making it ideal in terms of versatility.

2.4 Non-volatile memory - SD Card

A non-volatile memory allows the metering system to be independent in terms of data logging.

SD Card offers a good price per GB ratio, enough capacity for long term logging, basic and fast com-

munication through SPI interface. Furthermore, its popularity made available a number of abstraction li-

18

Page 41: Design and implementation of a plug-in power metering device

braries to simplify the programming necessary for the interaction between the embedded system and the

SD Card. These abstraction layers also implement a filesystem such as File Allocation Table (FAT); mak-

ing the SD Card compatible with a broad range of devices (computers, smartphones, tablets, etc.) [22].

2.5 Previous Work

This section presents some related projects developed in the last decade.

2.5.1 Intelligent Electric Energy Counter

This project [9] consist of an energy metering system capable of measuring the power consumption in

real-time. Based on a PIC24 microcontroller [23], it resorts to the built-in ADCs for sampling the voltage

and current sensing circuits (Voltage transformer TZ111V and Current transformer TC174V [24]), then

the live information is presented on a Liquid Crystal Display (LCD) display, as depicted in Figure 2.5.

This device accounts with the following major characteristics: possibility to miniaturize it, low power

consumption and the main advantage for the final user, the possibility to visualize the results through the

display.

Figure 2.5: System diagram adapted from [9].

19

Page 42: Design and implementation of a plug-in power metering device

2.5.2 Develop, implement and characterize an electric energy monitoring de-

vice

The objective of this thesis [7] was to develop an energy metering device. Based on a PIC24 micro-

controller [23] and a specific IC from Analog Devices (ADE7753 [2]) for sampling the voltage and current

sensing circuits, voltage divider and shunt resistor, respectively. Live information is presented on a LCD

display and in the developped android APP either live measurements or the previously logged data, as

depicted in Figure 2.6. There is also the possibility to transfer the raw data from the SD Card to any

electronic device runing any modern operating system (e.g. Microsoft Windows, Linux, Apple MacOS,

Android).

Figure 2.6: Application Screens [7].

20

Page 43: Design and implementation of a plug-in power metering device

2.5.3 Electric energy meter for low voltage usage

The work presented in [25] consists on the development, implementation and design of a single

phase energy meter for low voltage use. This device can be used in installations up to 30 A and has as

a CPU a Digital Signal Peripheral Interface Controller (dsPIC) from Microchip, which communicates with

a a specific IC for energy metering, capable of reporting RMS current, RMS voltage, and instantaneous

as well as accumulated power consumption. The voltage sensor is a resistive divider and the current

sensor a shunt resistor. The information is displayed on a LCD and can be sent through Universal Serial

Bus (USB) and/or Recommended Standard 232 (RS-232) interface. A transformerless power supply

was used to power-up the device which draws less than 2 W, meeting the requirements for IEC62053

standard [26].

2.5.4 A Low-cost Wi-Fi Smart Plug with On-off and Energy Metering Functions

The paper presented in [27] consist of a device based on a ESP-WROOM2 [28], a microcontroller

with a built-in WiFi module, another part consists of a relay driver with a voltage quadrupler (from 3.3 V

to 12 V) and a relay to latch the supply from the load. It operates with devices on the same network; such

as a home AP; making it easy to interact with virtually any modern mobile device through a WebApp as

shown in Figure 2.7.

Figure 2.7: Network design [27].

The system communicates internally through SPI between the microcontroller and the energy meter

(STPM01 chip [29]) and a couple IO pins to flag the relay driver and voltage quadrupler, as shown in

Figure 2.8.

21

Page 44: Design and implementation of a plug-in power metering device

Figure 2.8: System block diagram [27].

The STMP01 energy meter is capable of calculating RMS voltage, RMS current, apparent power,

frequency, power and power factor from the sampled data. The device was tested with a single-phase

AC power supply, CAL-SOURCE 200 [30], set at 220 VAC at 50 Hz and a phase angle fixed at 0 degree;

varying the current from 1 A up to 10 A the system accuracy of measurement resulted in magnitude

error less than 0.5 % [27].

2.5.5 Data acquisition and control using Arduino-Android Platform : Smart plug

In [31], a paper describes the development of a smart plug for remote monitoring. Implemented

on an open source microcontroller, the Arduino Duemilanove (ATmega168 or ATmega328 [32]) which

communicates via SPI interface with an ethernet module (enc28j60 [33]) to connect to the internet. The

system resorts to an non-invasive technique for current sensing with a current transformer (SCT-013-

030 [34]). It is capable of sensing up to 30 A and outputs a maximum of 1 V, acquired by the included

ADC which makes part of the Arduino peripherals. Furthermore, a server was required to be setup and

connected to the AP, as well as an Android APP [31].

22

Page 45: Design and implementation of a plug-in power metering device

2.5.6 Development of Embedded System for Making Plugs Smart

The project presented in [18] tackles the multiple attempts to create a smart plugs, points out the

multiples approaches to the wireless and non-wireless communication techniques for remote manage-

ment: Global System for Mobile Communications (GSM), Bluetooth, Power-line Communication (PLC),

ZigBee [35] and Ethernet. The embedded system is described as a microcontroller, Arduino mega

2560 [32], linked to the internet via an ethernet cable connected to the AP through an external Arduino

module, Ethernet shield [36]. Current sensing is done with the SCT-013-030 [34], a split core current

transformer. Arduino does not have any AC capable inputs, neither accepts inputs above 5 V, thus an AC

to DC and step down circuit was developed to create the voltage sensor based on a full-bridge rectifier

shown in Figure 2.9. An Android APP was developed to display information such as Apparent power,

AC voltage, AC current and control up to 8 devices in the network (turn on or off) [18].

Figure 2.9: Voltage sensor circuit [18].

23

Page 46: Design and implementation of a plug-in power metering device

2.5.7 Power-Efficient Smart Metering Plug for Intelligent Households

In [37] a power-efficient solution for smart metering plugs is described; it gives emphasis on the fact

that most smart plugs that are wireless use WiFi, a fairly inefficient solution [38] compared to BLE [39].

The proposed solution resorts to BLE due to its compatibility with a wide range of devices while keeping

the power consumption low. The project was focused on the following requirements:

• compactness - built-in type of smart plug.

• low power - power efficient solution.

• easy integration - compatible with other devices.

• increased security - a secure element integrated.

• low price - reasonable price for large scale deployment.

The system is built around a System-on-a-chip (SoC), a power efficient Advanced RISC Machine

(ARM) Cortex M0 core extended by a BLE transmitter and peripherals for SPI, Inter-Integrated Cir-

cuit (I2C) and UART communication. The metering front-end of the smart plug is based on Infineon’s

dual channel on-chip isolated ADC chip that provides serial data from two sigmadelta ADCs via a SPI

interface. On the high voltage side of the ADC, both channels are connected as voltage and current

monitors using a voltage divider and a current shunt, respectively. The whole smart plug is powered

from the mains using an AC to DC converter in step down configuration with 3.3 V as the nominal output

voltage. The system only requires a 3.3 V supply and is characterised by a peak power consumption of

170 mW. The full system diagram is depicted in Figure 2.10 [37].

Figure 2.10: Block diagram of the efficient smart plug [37].

24

Page 47: Design and implementation of a plug-in power metering device

3System Architecture

Contents

3.1 Microcontroller - Microchip PIC24F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

3.2 Energy meter IC - ADE7753 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3.3 Signal conditioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

3.4 Bluetooth module - Itead HC-05 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

3.5 Memory - SD Card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

3.6 Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

3.7 Mobile APP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

3.8 Software - PIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

25

Page 48: Design and implementation of a plug-in power metering device

26

Page 49: Design and implementation of a plug-in power metering device

System Architecture

The developed system is comprised by current and voltage sensors, an energy meter IC, a non-

volatile memory unit, a wireless communication interface and a PIC microcontroller.

The energy metering IC continuously acquires samples from both current and voltage sensors, and

the PIC gathers information from the IC when requested either via an interrupt or a bluetooth request. All

data received on the microcontroller regarding voltage, current and power are stored on an SD Card. SPI

is used to communicate between the PIC and the SD Card. The UART module is enabled to interface

with the bluetooth module. Communication with the energy meter is achieved through SPI. An overview

of the system architecture is represented in Figure 3.1.

Figure 3.1: Energy meter architecture.

27

Page 50: Design and implementation of a plug-in power metering device

3.1 Microcontroller - Microchip PIC24F

Microchip’s PIC24 family of Microcontroller Units (MCUs) features a 16 MIPS core and enhanced

on-chip peripherals [23]. It communicates through SPI1 module with the SD Card, SPI2 module with

the energy meter IC and UART with the Bluetooth module. There is also another UART and two I2C

modules available. This number of communications modules allow for various interface configurations

with minimum compromises. Another feature worth mentioning is the availability of a RTCC, five timers

and interrupts based on external inputs, timers or peripherals. Lastly, the program language used is C

and the program is uploaded to the unit via a PICkit3 programmer [40]. A pin diagram of the used PIC24

is depicted in Figure 3.2.

Figure 3.2: PIC24FJXXXGA010 pin diagram [23].

An Fast Internal Oscillator (FRC) feeds a clock source of 8 MHz and with the integrated Phase-

Locked Loop (PLL), it reaches 32 MHz, maximizing the peripherals clock at 16 MHz by following

FCY =FOSC

2. (3.1)

28

Page 51: Design and implementation of a plug-in power metering device

All clock sources and derivatives used in this project are described in Table 3.1.

Table 3.1: Oscillator configuration.

FOSC RTC PLL Multiplier FRCPLL FCY

8 MHz 32.768 kHz 4× 32 MHz 16 MHz

A simplified diagram of the oscillator system present in the PIC24FJXXXGA010 family is depicted in

3.3.

Figure 3.3: PIC24FJXXXGA010 clock diagram [23].

29

Page 52: Design and implementation of a plug-in power metering device

The system was designed so that by tweaking three properties, namely the UART clock, enable/dis-

able predefined CTS and RTS pins and customize the termination character, any UART capable blue-

tooth module can be used. PIC’s UART module has a register controlled baud rate generator (UBRGX ),

which values can be calculated depending on the selected mode set by BRGH. [3]

For BRGH = 1, high-speed mode is enabled (4 clocks per bit period), BRGH is given by

UBRGX = INT

(FCY

4× baudratedesired− 1

). (3.2)

Resulting in a actual baud rate of,

baudratecalculated =FCY

4× (UBRGX + 1). (3.3)

And for BRGH = 0, standard mode enabled (16 clocks per bit period), by

UBRGX = INT

(FCY

16× baudratedesired− 1

). (3.4)

Giving an actual baud rate of,

baudratecalculated =FCY

16× (UBRGX + 1). (3.5)

Lastly, the error is given by,

Error =baudratecalculated − baudratedesired

baudratedesired. (3.6)

The results are displayed in Table 3.2. The baudrate was set at 115.2 kHz delivering an error free

and more stable communication with the bluetooth module.

30

Page 53: Design and implementation of a plug-in power metering device

Table 3.2: PIC UART error rate for various baud rates for high-speed and standard mode [23].

Set Baud Rate

921600

460800

307200

230400

115200

57600

38400

19200

9600

Calculated Baud Rate(BRGH = 1) Error

1000000 0.085%

500000 0.085%

307692 0.001%

235294 0.021%

117647 0.021%

57971 0.006%

38461 0.001%

19230 0.001%

9615 0.001%

Calculated Baud Rate(BRGH = 0) Error

1000000 0.085 %

500000 0.085 %

333333 0.085%

250000 0.085%

125000 0.085%

58823 0.021%

38461 0.001%

19230 0.001%

9615 0.001%

In addition to the three serial peripherals used to access the SD Card, transmit/receive data over

Bluetooth and communicate with the energy meter IC, the integrated RTCC is set to append timestamps

to the acquired samples.

Furthermore, three interrupts are active, two of which are triggered by external inputs and the third

one by the UART module. These external inputs are configured as such to detect the insertion of

the SD Card leading to its initialization and to sense the zero-crossing output (ZX) from the energy

meter IC thus synchronizing the reading of the registers [2]. UART interrupts allows the system to

fetch the streamed data from the Bluetooth module to a software buffer as soon as it’s available without

polling; received strings can be later processed when the system is free of other more critical tasks (e.g.

retrieving samples from the IC, free buffer space by flushing samples to the SD Card).

31

Page 54: Design and implementation of a plug-in power metering device

3.2 Energy meter IC - ADE7753

The Analog Devices’s ADE7753 is an energy meter IC with a high accuracy, compliant with the fol-

lowing International Electrotechnical Commission (IEC) standards: IEC 60687/61036/61268 and IEC

62053-21/62053-22/62053-23.The IC is intended for single phase applications with all the signal pro-

cessing required to perform active, reactive and apparent power calculation. It can also measure RMS

voltage and RMS current. This energy meter resorts to two second-order Σ − ∆ ADCs to acquire the

analog inputs. The IC power consumption tops at 25 mW with a 5 V supply. [2]

The ADE7753 is compatible with SPI to read data and allows calibration for power, phase and input

offset with on-chip registers. Furthermore, it contains a Programmable Gain Amplifier (PGA) (up to

16×) to adapt for a smaller input range in case of a shunt or current transformer, along with an internal

integrator in channel 1 for use with Rogowski coil sensors [17]. The chip also provides a pulse output

frequency (CF ) proportional to the active power and a zero-crossing output signal. It is characterized

by less than 0.1% error in active power measurements over a dynamic range of 1000:1 at an ambient

temperature of 25C. The functional block diagram is presented in Figure 3.4. [2]

Figure 3.4: ADE7753 functional block diagram [2].

The ADE7753’s sensing inputs are comprised of two fully differential voltage input channels with a

maximum voltage range of ± 0.5 V. Both channels have a PGA with user defined gains of 1, 2, 4, 8 and

16. Furthermore, channel 1 also has a full-scale input range selection for its ADC. Table 3.3 summarizes

all possible setup combinations for the PGA and channel input range.

32

Page 55: Design and implementation of a plug-in power metering device

Table 3.3: ADE7753 maximum input signal levels for channel 1 [2].

Max Signal

Channel 1

0.5 V

0.25 V

0.125 V

0.0625 V

0.0313 V

0.0156 V

0.00781 V

ADC Input Range Selection

0.5 V 0.25 V 0.125 V

Gain = 1 - -

Gain = 2 Gain = 1 -

Gain = 4 Gain = 2 Gain = 1

Gain = 8 Gain = 4 Gain = 2

Gain = 16 Gain = 8 Gain = 4

- Gain = 16 Gain = 8

- - Gain = 16

At the ADC level, it is also possible to adjust offset errors in the range of 20 mV to 50 mV based on

the gain set and the Least Significant Bit (LSB) weight, as described in Table 3.4 and depicted in Figure

3.5.

Table 3.4: ADE7753 offset correction range for channel 1 and 2 [2].

Gain Correctable Span LSB size

1 ± 50 mV ± 1.61 mV/LSB

2 ± 37 mV ± 1.19 mV/LSB

4 ± 30 mV ± 0.97 mV/LSB

8 ± 26 mV ± 0.84 mV/LSB

16 ± 24 mV ± 0.77 mV/LSB

33

Page 56: Design and implementation of a plug-in power metering device

Figure 3.5: ADE7753 channel 1 offset range with gain set to 1 [2].

The zero-crossing detection circuit generates its output in regards to the channel 2 input; ZX signal

is logic high when a rising flank crosses zero and logic low on a falling edge crossing zero. This output

is used to generate interrupts and synchronize readings, as well as for calibration purposes.

The ADE7753’s channel 1 and 2 sample voltage inputs at a user selected rate depending on the

MODE register configuration, the offered options are 3.5 kSPS, 7 kSPS, 14 kSPS or the default and

used in this project, 27.9 kSPS. The RMS values are then simultaneously calculated for both channels

by

V RMS =

√√√√ 1

N∑i=1

V (i)2 (3.7)

and saved in their corresponding registers (V RMS, IRMS). All conversions from the registers

values to Volts (channel 2) and to Amps (channel 1) must be done in the microcontroller; taking into

account the selected input range and gains for the ADCs, as well as the designed voltage and current

sensor circuits.

The average power over a defined integral number of periods n is given by,

P =1

nT

∫ nT

0

p(t)dt = V I, (3.8)

where T is the line cycle period, V is the RMS voltage and I the RMS current.

Active power 3.8, is equal to the DC component of the instantaneous power signal, V I. Extracted

from the multiplication of voltage and current signals by a Low-Pass Filter (LPF), specified in Figure

3.4 and 3.7 as LPF2; this process can be visualized in Figure 3.6 and corresponding block diagram is

depicted in Figure 3.7.

34

Page 57: Design and implementation of a plug-in power metering device

Figure 3.6: ADE7753 Active Power calculation [2].

Figure 3.7: ADE7753 Active Power calculation block diagram [2].

The average reactive power over a selected integral number of lines cycles (n) is given by,

RP =1

nT

∫ nT

0

Rp(t)dt = V I sin(φ), (3.9)

where φ is the phase difference between the voltage and current channel.

Reactive power 3.9, is the product of voltage and current drifted apart by 90, meaning the channel

1 input is shifted 90 from channel 2 and then the DC component of the instantaneous reactive power

signal is extracted by the LPF, as depicted in the block diagram of Figure 3.8.

35

Page 58: Design and implementation of a plug-in power metering device

Figure 3.8: ADE7753 Reactive Power calculation block diagram [2].

Apparent power, as defined in 1.5, is the maximum power that can be feed to a load; where V RMS

and IRMS are the effective voltage and current delivered. And is independent from the phase shift φ,

the drift between the current and voltage. Figure 3.9 shows the process of calculation of the apparent

power.

Figure 3.9: ADE7753 Apparent Power calculation block diagram [2].

3.3 Signal conditioning

The energy meter IC contains two ADC with a variety of user defined input gains, as it includes a

PGA in each channel; nonetheless it has a maximum differential input range of ± 0.5 V. A conditioning

circuit is present at the input to meet the IC input range, and if necessary it’s possible to amplify the

resulting signal to an ideal range avoiding loss of information due to the signal amplitude or the ADCs

resolution.

36

Page 59: Design and implementation of a plug-in power metering device

3.3.1 Voltage sensor - Resistive divider

The choice of voltage sensor was focused on low cost and reduced footprint thus leading to a resistive

divider setup. The attenuation network is composed of a single 1 kΩ resistor and two 499 kΩ resistors,

resulting in a ratio of

ratio =R2

(R1 +R2)=

1000

499000× 2 + 1000= 1× 10−3. (3.10)

For a voltage peak of 425 V (300 VRMS), the voltage sensor output is

Voutput = Vpeak × ratio = 425× 1× 10−3 = 0.425 V. (3.11)

And the maximum current is,

Ioutput =Vpeak

(R1 +R2)= 4.254× 10−4 = 0.425 mA. (3.12)

Resulting in a power consumption per resistor of,

Pmax = I2output ×R, (3.13)

P499k =(4.254× 10−4

)2 × 499000 = 90.3 mW, (3.14)

P1k =(4.254× 10−4

)2 × 1000 = 180 µW. (3.15)

The resistors of 1 kΩ (ERJP06F1001V) and 499 kΩ (ERJP06F4993V) used for the voltage sensor,

have a power dissipation characteristic of 500 mW. This large margin in terms of power dissipation allows

for cooler operation and a steadier temperature overall for the resistors, thus mitigating the resistance

drift that otherwise could occur with the temperature increase. [41]

3.3.2 Current sensor - Shunt resistor

Once again, the selection for the current sensor relies on the same attributes, low cost and small

footprint. A 10 mΩ Shunt resistor is chosen taking into consideration its power dissipation capabilities

and temperature coefficient. As detailed in Table 1.1, the system must handle to measure current up to

16 A, which leads to

Pshuntmax= I2max ×Rshunt = 2.56 W, (3.16)

37

Page 60: Design and implementation of a plug-in power metering device

of power generated as heat, that has to be dissipated by the Shunt.

In this case, sensed voltage in the IC input is

Voutmax= Imax ×Rshunt = 0.16 V. (3.17)

The voltage output of the selected current sensor is within energy meter IC range.

Lastly, a small temperature coefficient is required so that as current increases, thus also the heat

generated (3.16), the shunt resistor preserves its characteristics. Based on availability, the smallest

temperature coefficient is ± 50 ppm/ C. A 3 W current sense chip resistor of 10 mΩ from Bourns is

used as current sensor [42]. It complies with the requirement and handles a maximum working current

of

Ishuntmax=Pshuntmax

Rshunt=

3

0.01= 17.32 A. (3.18)

3.4 Bluetooth module - Itead HC-05

Wireless communication is carried by a Bluetooth module with the task to create an abstraction layer

from the wave driven transmission to the available serial communication, most of which the available

solutions resort to UART.

The Itead HC-05 [4] supports Bluetooth 2.0 with Enhanced Data Rate (EDR), delivering a maxi-

mum bit rate of 3 Mbps. Connects to the PIC via UART, it allows data to be streamed bidirectionally.

Any American Standard Code for Information Interchange (ASCII) string sent to the module, either via

Bluetooth from a smartphone or from the microcontroller via UART is echoed to the other device. The

termination character, declaring the end of transmission, is a Carriage Return Line Feed (CRLF).

Parameters can be user defined via UART, such as customizing the device name and the pairing pin

code, when powered in AT mode also known as command mode [4]. There is a dedicated pin (PIO11)

to enter this mode; it is required to pull-high the pin before powering the module. A pin diagram is shown

in Figure 3.10. The chip operates at 3.3 V and features a low power operation for its Input/Output (I/O)

(1.8 to 3.3 V). [4]

38

Page 61: Design and implementation of a plug-in power metering device

Figure 3.10: HC-05 pin diagram [4].

As for peak current consumption, the HC-05 caps out at 40 mA while pairing to a device, after which

the current drawn is 8 mA in any case; as described in Table 3.5. [43]

Table 3.5: HC-05 current consumption [43].

Parameter Min. Max. Units

Pairing 30 40 mA

TX mode Peak Current - 8 mA

RX mode Peak Current - 8 mA

The available module has six I/O’s of the thirty-four pins of the chip (Figure 3.10); V DD (5 V in this

specific version) and GND to power the device, TX and RX for UART communication, STATE (PIO1)

that drives an LED to offer a quick visual indicator of the bluetooth connection state and EN (PIO11)

which can also be triggered via an on-board push-button to enter in AT mode, as depicted in Figure

3.11.

39

Page 62: Design and implementation of a plug-in power metering device

Figure 3.11: HC-05 module [4].

The baud rate of the unit can be configured. An experiment was setup to check the stability of

the selected baud rate. A string was sent repeatedly via UART to the Bluetooth module and echoed

to a smartphone running a serial terminal, if any character was missing or incorrect; it was considered

unstable. Clear to Send (CTS) and Request to Send (RTS) pins are physically inaccessible in this version

of the module (Figure 3.11), all tests were conducted without flow control, from which the maximum baud

rate achieved for viable operation was 115.2 kHz.

3.5 Memory - SD Card

Non-volatile memory allows the system to store and keep the previously measured data even when

powered down. The SPI interface connection between the PIC and the SD Card is depicted in Figure

3.12 [7].

Figure 3.12: SD Card SPI interface [7].

40

Page 63: Design and implementation of a plug-in power metering device

All the acquired samples will be saved on this type of memory, following a specific file tree organiza-

tion. CD pin doesn’t take part of the SPI interface, it’s a switch present on the SD Card holder that gets

closed when a card is inserted. The microcontroller should have a pin set as input to sense the closed

circuit and initialize the SD Card when inserted.

To interface with the SD Card memory blocks a file system (FAT) and library module, FatFS, was

implemented. Offering an abstraction layer on the programming side to create/read/edit folders and files

tailored to small embedded systems, while keeping the SD Card interpretable by any device. [44]

The FAT file system was originally designed for small volumes and simple folder structures. In FAT,

memory sectors are combined into clusters, there is an allocation table keeping track of the starting

cluster of each folder/file and each cluster then points to the next one that comprises the file or a end-

of-file indicator. [7]

The chosen file structure is comprised of a main folder (year), a sub-folder (month), another sub-

folder (day of the month) and lastly a text file (hour) in Comma-Separated Values (CSV) format where

data is saved (e.g. /YEAR/MONTH/DAY/hour.csv). This setup minimizes the number of files per folder

which helps prevent hangups or even disk failure, while offering the user ease of navigation through

the acquired data. As an example, the system was initialized on the 8 of September 2020 at 17h, the

SD Card folder structure and file naming scheme is depicted in Figure 3.13.

Figure 3.13: SD Card folder structure (red: folder path, yellow: file name).

Each sample is a new line written into the appropriate file based on its timestamp and offers informa-

tion in the following order: number of sample, RMS voltage, RMS current, apparent power, active power,

reactive power and timestamp.

41

Page 64: Design and implementation of a plug-in power metering device

All files and folders, for a complete thirty-one day run, are created at startup to reduce write time

when flushing the acquired data into memory. But a dynamic function was also implemented, in such

way that if left more than thirty-one days running, there is no major data loss since files and folder will

continue to be created as needed; making the SD Card volume size the real limiting factor. Although,

due to the time required for these actions to complete (file: two seconds, folder: five seconds) some

data may be lost during the process of file/folder creation, depending on the selected acquisition rate.

Lastly, if the user requests to stop the run prematurely, all empty files and folder are deleted.

3.6 Power Supply

The system requires two different voltage rails to work, 3.3 V and 5 V. For the implemented microcon-

troller family (PIC24F) and SD Card, 3.3 V is needed and 5 V for the energy meter IC (ADE7753). The

bluetooth module (HC-05) can be powered with 5 V through the module or 3.3 V if connected directly to

the chip. The power source of the system is the mains AC outlet.

The total system power consumption is 235 mA on the 3.3 V rail and 84 mA for the 5 V rail. The

microcontroller running at the maximum frequency (Table 3.1) draws 35 mA, the SD Card can peak to

200 mA, the energy meter IC 4 mA and the bluetooth module up to 80 mA. [3] [2] [43] [45]

Figure 3.14 presents a diagram of the designed power supply setup.

Figure 3.14: PSU diagram.

A universal AC input (85 to 264 VAC [46]) switching power supply rectifies and attenuates the mains

AC voltage to DC 12 V. Other characteristic such as short circuit, overload and over voltage protection,

make the IRM-15-12 a compact, reliable and affordable solution to generate 12 V. This switching power

supply can deliver up to 1.25 A. The block diagram is represented in Figure 3.15. [46]

Figure 3.15: IRM-15-12 block diagram [46].

42

Page 65: Design and implementation of a plug-in power metering device

It is required to further step-down the voltage to the required levels. From 12 V to 5 V, there is a

7 V drop, power dissipation is a concern, but can be circumvented with a step-down voltage switching

regulator. The LM2575-5, when powered with 12 V, can deliver up to 1 A with a voltage output between

4.75 V and 5.25 V with 77 % efficiency. The power dissipated is low thus no heatsink is required. This

switching regulator shuts down when internal temperature reaches 150 C and has a thermal resistance

characteristic of 65 C/W. For the device to shut down, it would require an ambient temperature over

100 C, since generated power is low and can be calculated by [47]

Pmax = (Vinmax × IQmax) +

(VoutVinmin

)× Ioutmax × Vsatmax

= ((12× 1.05)× 0.011) +

(5

12× 0.975

)× 1× 1.3 = 0.694 W.

(3.19)

Leading to an internal temperature rise over ambient of

Trise = Pmax ×Rφ = 0.694× 65 = 45.12 C. (3.20)

The switching voltage regulator IC is presented in Figure 3.16. [47]

Figure 3.16: LM2575 block diagram [47].

43

Page 66: Design and implementation of a plug-in power metering device

Lastly, a linear voltage regulator is used to achieve the final step-down to 3.3 V, from the 5 V supplied

by the LM2575-5 output. The chosen MCP1825S variant is a SOT-223-3 package with a fixed 3.3 V

output, accepts inputs in the range of 2.1 V to 6 V, has a current limit of 500 mA and has integrated over

temperature and short circuit protection. This linear regulator shuts down when internal temperature

reaches 150 C and has a thermal resistance characteristic of 62 C/W. For the device to shut down, it

would require an ambient temperature over 80 C, since generated power is low and can be calculated

by

Pmax = (Vinmax − Voutmin)× Ioutmax

= ((5× 1.05)− (3.3× 0.975))× 0.5 = 1.016 W.(3.21)

Leading to an internal temperature rise over ambient of

Trise = Pmax ×Rφ = 1.016× 62 = 63 C. (3.22)

The MCP1825S’s functional block diagram is depicted in Figure 3.17. [48]

Figure 3.17: MCP1825 block diagram [48].

44

Page 67: Design and implementation of a plug-in power metering device

3.7 Mobile APP

A smartphone mobile APP was developed to complement the designed system. It offers the possibil-

ity to review previously acquired data (voltage RMS, current RMS, apparent, active and reactive power)

in form of graphs, as well as live samples. The user can start, pause or reset the system and instantly

change the acquisition rate from a list of predefined intervals. Moreover, the APP has the task to sync

the system, on connect the APP automatically updates the time and date of the PIC RTCC based on the

smartphone clock and calendar. The application screen is depicted in Figure 3.18.

Figure 3.18: Application screen.

Pressing Start triggers a chain of processes. The PIC will start scanning the SD Card for the files and

folders; if non-existent, the missing ones are created for a thirty-one day run. Furthermore, it requests

the user to select from a list an acquisition rate for the energy meter IC.

The Stop button holds the current state of the system, halts all sampling and cleans the log structure

by deleting the empty files and folders from the SD Card. The user can then remove the SD Card, view

or copy the data to another device. To proceed with the same run, the user inserts the SD Card back

into the slot and presses Start; since Stop holds the system state, the execution will continue then from

the previous state. Holding down the Stop button will start a complete reset of the system, all variables

are set back to their initial value and and all data present in the SD Card is deleted.

45

Page 68: Design and implementation of a plug-in power metering device

With the APP connected via bluetooth, Get Data button requests the user to chose a date and time-

frame, after which the corresponding data is downloaded and processed. Due to performance reasons,

fifty samples are retrieved at a time, taking up to ten seconds to receive and process each request;

the user is prompted to download more samples or halt the process to plot the downloaded data. This

feature is presented in Figure 3.19.

Figure 3.19: Data review feature.

46

Page 69: Design and implementation of a plug-in power metering device

Turning on the LiveMonitor switch will start a looping one second timer. Every second, the app

retrieves the last sampled data by the energy meter IC and displays the values at the bottom of the

screen. When live monitoring is disabled, a graph will be automatically plotted as a summary, as depicted

in Figure 3.20.

Figure 3.20: Live data feature.

3.8 Software - PIC

Microchip offers an Integrated Development Environment (IDE) to configure, develop and debug

embedded designs based on their MCUs, MPLAB X. A plugin can be installed to further assist the user,

MPLAB Code configurator, a graphical programming environment to generate libraries for the desired

peripherals. Both tools were used to create the C program that runs on the PIC. The setup is divided in

modules, each manages a functionality of the developed system: main loop, SD Card, energy meter IC,

bluetooth module, logging buffers and processing of bluetooth commands.

In Figure 3.21 a flowchart presents the main workflow of the system. At boot, the system initial-

izes and configures the I/O, RTCC, communication peripherals (SPI and UART), energy meter IC and

interrupts.

47

Page 70: Design and implementation of a plug-in power metering device

Figure 3.21: Main loop flowchart.

A structure variable datacell was created to hold the following data items: RMS voltage, RMS current,

apparent power, active power, reactive power, sample number, date and time. There are two buffers

each holding fifty datacell’s in order to avoid data overlap, since at the maximum acquisition rate (40

ms) a buffer is full every two seconds and flushing it to memory takes one second. The current buffer

saves the received data from the energy meter IC. When full, the ADE7753’s interrupt gains access to

the second buffer which is empty and the filled buffer is pointed to be transferred to the SD Card. Figure

3.22 is a snippet of the developed code to achieve this functionality.

48

Page 71: Design and implementation of a plug-in power metering device

Figure 3.22: Data buffers management functions.

Three interrupts are used in this project, each one set with different level of priority. The insertion

or removal of the SD Card triggers an external interrupt with the highest priority, updating its mount

status and altering accordingly the edge awareness (negative edge when inserted or positive edge

when removed) of CD pin from the SD Card holder (Figure 3.12). The ZX output of the ADE7753

(Figure 3.4) is detected to count line cycles and read the IC registers at the user defined rate, as well as

synchronise the registers access with the zero-crossing of the AC outlet voltage [2]. The energy meter

IC interrupt function is presented in Figure 3.23.

Figure 3.23: ADE7753 interrupt function.

49

Page 72: Design and implementation of a plug-in power metering device

The lowest priority is set to the UART peripheral. When data is received via bluetooth, an interrupt

request is produced to save the received bytes into a queue. In the main loop, a function is called to

parse and copy the result to a string buffer (commandlist) that can hold the last five commands. The

availability of a new command is then flagged as true. Upon processing all commands, the flag is set to

false.

50

Page 73: Design and implementation of a plug-in power metering device

4Results

Contents

4.1 Energy meter IC - ADE7753 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

4.2 SD Card and RTCC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

4.3 Bluetooth module - Itead HC-05 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

4.4 Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

4.5 Final Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

51

Page 74: Design and implementation of a plug-in power metering device

52

Page 75: Design and implementation of a plug-in power metering device

Results

4.1 Energy meter IC - ADE7753

The SPI1 peripheral was set at 4 MHz for the ADE7753 since this is the maximum frequency that

could be achieved while keeping consistent results. An Hantek 4032L data analyser was used to verify

clock, chip select behaviors and correct bytes where being transmitted [49].

Writing and reading is defined by the most significant bit of the address, 1 to write and 0 to read.

Figure 4.1 shows the request for the energy meter IC to reset by writing 0x0040 to the MODE register

(0x09). Figure 4.2 is the reply from the ADE7753 of a successful reset, confirmed by reading the

STATUS register (0x0C) and acknowledging the reset flag (0x0040). [2]

Figure 4.1: Software reset request.

Figure 4.2: Successful software reset.

53

Page 76: Design and implementation of a plug-in power metering device

4.2 SD Card and RTCC

Due to the high load that may occur on the SD Card in certain situations, such as: write measured

values and read request made over bluetooth to download the last couple hours of data; the card has

SPI2 peripheral [3] exclusively dedicated to it. The clock is set at the maximum available internally on

the PIC24FJ128GA010 rated at 16 MHz.

During an experiment, the microcontroller was set to continuously write to the SD Card, multiple text

files were created and filled with time stamps; every thousand program cycles a new file was created

named after the loop number. Files were created successfully and all characters were saved. Further-

more, on Windows file explorer, the file properties specify the correct time and date in created and last

modified variables.

4.3 Bluetooth module - Itead HC-05

A bluetooth communication has been successfully established with a smartphone; the app used to

confirm the result was a simple bluetooth serial terminal. All messages sent by the user were immedi-

ately acknowledged by the PIC24 thanks to the UART interrupt [3].

Main functionalities are accomplished, but the transmission speed is lacking at a mere 115.2 kHz,

due to the UART interface and limited clock fed to the PIC24 peripherals of 16 MHz. To solve this

situation, either the UART has access to a higher clock source or changing the bluetooth module for one

with a SPI interface would be preferable. Although the latest comes with the caveat of having to share

and manage one SPI peripheral with two devices, since both are already in use for the SD Card (SPI2)

and the energy meter IC (SPI1) [3].

54

Page 77: Design and implementation of a plug-in power metering device

4.4 Calibration

The PCB design is finalized as depicted in Figures 4.3 and 4.4.

Figure 4.3: PCB’s front view.

Figure 4.4: PCB’s back view.

For calibration purposes, a resistive load is applied to the PCB mains output. Two Alcor HS100 220 Ω

aluminium housed power resistor (Figure 4.5) were connected in series, for a total of a 440 Ω load. [50]

For a voltage RMS of 230 VRMS , the expected current RMS is,

Ioutput =VRMS

R=

230

220× 2= 0.523 A. (4.1)

From Equation (3.13), the resulting power consumption per resistor is given by,

P220 = (0.523)2 × 220 = 60.18 W, (4.2)

55

Page 78: Design and implementation of a plug-in power metering device

Figure 4.5: Alcor HS100. [50]

which is in the range of the 100 W rated power dissipation capabilities of these resistors. [50]

4.4.1 Voltage RMS and Current RMS

The 440 Ω load is mainly resistive thus it is expected a zero phase shift between both channels of

the energy meter IC. Current RMS (A) and voltage RMS (V) were also measured with a multi-meter

simultaneously with the read register values.

The calibration values for the voltage channel is given by

V/LSB =VRMSmulti−meter

V RMSregister=

235.7

1118093= 2.11× 10−4, (4.3)

and the current channel by

A/LSB =IRMSmulti−meter

IRMSregister=

0.561

30251= 1.85× 10−5. (4.4)

4.4.2 Active and Apparent Power

Active and apparent power are equal when current and voltage waves are in sync. For the same test

setup it is expected a null reactive power. The expected active and apparent power in this situation from

(1.2) and (1.5) are given by

P = S = VRMS × IRMS = 235.7× 0.561 = 132.23 W(VA), (4.5)

where VRMS and IRMS were measured with the multi-meter.

56

Page 79: Design and implementation of a plug-in power metering device

The following constants between register values and energy were obtained with accumulation mode

set to five line cycles (n) [2] and are calculated from

Wh/LSB =P ×

(n×period

3600

)LAenergyregister

=132.23×

(5×0.01917

3600

)25

= 1.41× 10−4, (4.6)

and

V Ah/LSB =S ×

(n×period

3600

)LV Aenergyregister

=132.23×

(5×0.01917

3600

)22

= 1.6× 10−4. (4.7)

Where the line cycle period is calculated in seconds by the IC and is available through PERIOD

register. [2]

4.4.3 Reactive Power

A different load was connected, a fully charged laptop running a benchmark. Since active and

apparent power are already calibrated, it is possible to obtain the reactive power based on the calibrated

values of active and apparent power (LV AENERGY and LAENERGY ) from the energy meter IC,

|Q| =√S2 − P 2 =

√65.3382 − 41.4392 = 23.899 VAR, (4.8)

Resulting in a reactive energy conversion defined by

V ARh/LSB =|Q| ×

(n×period

3600

)LV ARenergyregister

=23.899×

(5×0.01917

3600

)1

= 6.363× 10−4. (4.9)

4.5 Final Results

Tests were conducted to prove the functionality of the developed system. Data was logged at a rate

of 200 ms intervals. Despite there wasn’t always the expected amount of samples, which was nailed

down to the energy meter IC itself that sporadically creeps to respond the SPI requests when using a low

level of line cycles accumulation, information was correctly saved in the SD Card. Further investigation

is required into the limitations in terms acquisition rates but the finalized PCB increased the system

stability in terms of voltage supply and signal integrity versus previous prototypes. From the acquired

information, RMS voltage, RMS current, apparent, active and reactive power values show expected

results.

57

Page 80: Design and implementation of a plug-in power metering device

Figures 4.6 and 4.7 show the results of a twenty minutes execution with a constant 440 Ω load with

a measured voltage and current of 225 V and 0.512 A, respectively.

Figure 4.6: Measured RMS voltage and RMS current from a resistive load.

Figure 4.7: Measured apparent, active and reactive power from a resistive load.

58

Page 81: Design and implementation of a plug-in power metering device

The results from Figure 4.7 show an apparent and active power (4.5) overlap, as well as a near

absence of reactive power as expected from a resistive load. These traces of reactive power may be

linked to the need for a calibration based on a larger data set and/or the presence of capacitance and

noise.

Figures 4.8 and 4.9 present the acquired values over a thirty-five minutes run of a laptop in three

different states: idling, charging while in sleep mode and running a benchmark.

Figure 4.8: Measured RMS voltage and RMS current from a rated 65 W laptop charger.

In its turn, Figure 4.8 shows the RMS voltage and RMS delivered to the laptop charger. The three

different load states can be seen on the acquired current values. While idling, the current constantly

varies depending on the background tasks and services. In sleep, the charger delivers a steadier current

that tends to decrease due to the intrinsic resistance characteristic of a battery while charging, where it

increases as its being filled. Lastly, running the benchmark the laptop requests the most effort from the

65 W charger, this rated power value can be confirmed as active power in Figure 4.9.

59

Page 82: Design and implementation of a plug-in power metering device

Figure 4.9: Measured apparent, active and reactive power from a rated 65 W laptop charger.

The energy meter IC response limitations previously mentioned, can be perceived in these tests

given that some values mainly in the voltage measurement are off-track from the expected. Never-

theless, the acquired results offer good expectation for further development of this project, although

calibration needs further attention.

60

Page 83: Design and implementation of a plug-in power metering device

5Conclusions

61

Page 84: Design and implementation of a plug-in power metering device

62

Page 85: Design and implementation of a plug-in power metering device

Conclusions

For further insight in electric power consumption, an accurate and feature complete energy metering

device is required. The implementation of a system based on an IC designed specifically for the purpose,

not only adds an abstraction layer for easier integration but also assures a level of certified accuracy and

reliability [2]. This approach only requires signal conditioning which can be accomplished at low cost

without a trade-off in size by using a resistive divider and a shunt resistor, with the only concern being

power dissipation.

The embedded system has a non-volatile memory (SD Card) access via SPI and a working wireless

communication via bluetooth, integrated by UART. Although, with a compromise in data transfer speeds,

the asynchronous serial communication and its implementation in the program makes it easily adaptable

to a wide range of UART capable bluetooth modules available on the market. As for the data logging,

the FAT file system offers compatibility with all devices that include an SD Card reader and the chosen

file structure not only improves file access performance for the PIC but also makes it straightforward

for the end-user to navigate through the measured information. All files are in CSV format making it

compatible with spreadsheet programs for advanced information processing. A smartphone APP was

successfully developed with the ability to adjust acquisition rate, download sections of the acquired data,

which is presented in the form of graphs and a constantly updated view of the last measured values.

The user can pause the execution and take the SD Card for analysis and later insert it back to resume

measurement. The APP is also in charge of adjusting the PIC RTCC automatically upon connection

via bluetooth and offers the possibility to fully reset the system and clear the measured data from the

SD Card.

The project mostly fulfills the defined goals. An embedded measurement system with data logger

functionality and wireless capabilities was fully designed. Furthermore, an APP was developed to com-

plement the system and offer further versatility to view the data.

This work could be improved by focusing on the following aspects:

• Further smartphone APP development could lead to speed improvements when processing the

downloaded data;

63

Page 86: Design and implementation of a plug-in power metering device

• Implement a relay and exploit the IC’s capability to detect line anomalies;

• Incorporate a battery and power-path management IC in case of energy fault or the relay being

triggered;

• Find a more efficient format to save information and transmit data over bluetooth.

64

Page 87: Design and implementation of a plug-in power metering device

Bibliography

[1] Mark P. Mills. The cloud begins with coal. [Online]. Available: https://www.tech-pundit.com/

wp-content/uploads/2013/07/Cloud Begins With Coal.pdf?c761ac

[2] Analog Devices. Ade7753. [Online]. Available: https://www.analog.com/en/products/ade7753.html

[3] Microchip Technology. Pic24fj128ga010. [Online]. Available: https://www.microchip.com/

wwwproducts/en/PIC24FJ128GA010

[4] Itead. Hc-05. [Online]. Available: https://www.itead.cc/wiki/Serial Port Bluetooth Module (Master/

Slave) : HC-05

[5] Weilin Li, Kun He, Yaqiang Wang. (2017) Cost comparison of ac and dc collector grid for integration

of large-scale pv power plants. [Online]. Available: https://ieeexplore.ieee.org/abstract/document/

8311173

[6] Terry S. Reynolds. (1976, September) The damnable alternating current. [Online]. Available:

https://ieeexplore.ieee.org/document/1454593

[7] Bernardo Matos, “Develop, implement and characterize an electric energy monitoring device,” Mas-

ter’s thesis, Instituto Superior Tecnico, November 2018.

[8] W. Mack Grady. (1993, November) Harmonics and how they relate to power factor. EPRI

Power Quality Issues Opportunities Conference (PQA’93), San Diego, CA. [Online]. Available:

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.130.3182&rep=rep1&type=pdf

[9] Grisha Tulcidas, “Intelligent Electric Energy Counter,” Master’s thesis, Instituto Superior Tecnico,

November 2010.

[10] Pieter-Tjerk de Boer. Accuracy and stability of the 50 hz mains frequency. [Online]. Available:

https://wwwhome.ewi.utwente.nl/∼ptdeboer/misc/mains.html

[11] Pedro M. Ramos, Pedro S. Girao. Aquisicao de sinais.

65

Page 88: Design and implementation of a plug-in power metering device

[12] Harry Nyquist. (2002, August) Certain topics in telegraph transmission theory. [Online]. Available:

https://ieeexplore.ieee.org/document/989875

[13] C. E. Shannon. (1998, Feburary) Communication in the presence of noise. [Online]. Available:

https://ieeexplore.ieee.org/document/659497

[14] Francesco Adarno, Gregorio Andria, Giuseppe Cavone, Anna M. L. Lanzolla. (2004, March) A

high voltage power supply and amplifier for hall effect voltage/current transducers characterization.

[Online]. Available: https://ieeexplore.ieee.org/document/1351138

[15] Edoardo Fiorucci, Giovanni Bucci, Fabrizio Ciancetta, Daniele Gallo, Carmine Landi, Mario Luiso.

(2013, July) Variable speed drive characterization: Review of measurement techniques and future

trends. [Online]. Available: https://www.researchgate.net/publication/258400873 Variable Speed

Drive Characterization Review of Measurement Techniques and Future Trends

[16] Chester Mitchell, Jeffrey A. Dierker, Gene Keyarts. (2009, March) Current sensing.

INTELEC - 1978 International Telephone Energy Conference. [Online]. Available: https:

//ieeexplore.ieee.org/document/4793569

[17] William Koon. Current sensing for energy metering. [Online]. Available: https://www.analog.com/

en/technical-articles/current-sensing-for-energy-metering.html

[18] Ahmed Arif Mohammed, Ergun Encelebi. (2017, June) Development of embedded system for

making plugs smart. [Online]. Available: https://ieeexplore.ieee.org/document/7935810

[19] Jin-Shyan Lee, Yu-Wei Su and Chung-Chou Shen. (2008, March) A comparative study of

wireless protocols:bluetooth, uwb, zigbee, and wi-fi. [Online]. Available: https://ieeexplore.ieee.org/

document/4460126

[20] Ritsu Tei, Hiroyuki Yamazawa and Takao Shimizu. (2015, October) Ble power consumption

estimation and its applications to smart manufacturing. [Online]. Available: https://ieeexplore.ieee.

org/document/7285303

[21] Texas Instrument. Ti cc2531emk, zigbee to usb dongle. [Online]. Available: http://www.ti.com/tool/

CC2531EMK

[22] N.N. Mahzan, A.M. Omar, S.Z.Mohammad Noor, M.Z.Mohd Rodzi. (2014, March) Design of data

logger with multiple sd cards. [Online]. Available: https://ieeexplore.ieee.org/document/6775621

[23] Microchip. Pic24 family. [Online]. Available: https://www.microchip.com/design-centers/16-bit

[24] Taehwatrans. [Online]. Available: http://www.taehwatrans.com

66

Page 89: Design and implementation of a plug-in power metering device

[25] Pedro Miguel Teixeira Agulha, “Intelligent Electric Energy Counter,” Master’s thesis, Instituto Supe-

rior Tecnico, November 2010.

[26] Craig L. King. (2009) Iec compliant active-energy meter design using the mcp3905a/06a. Microchip

Technology Inc. [Online]. Available: http://ww1.microchip.com/downloads/en/AppNotes/00994b.pdf

[27] Yaowaluk Thongkhao, Wanchalern Pora. (2016) A low-cost wi-fi smart plug with on-off and energy

metering functions. [Online]. Available: https://ieeexplore.ieee.org/document/7561264

[28] Espressif. [Online]. Available: https://www.espressif.com/en/products/hardware/esp-wroom-02/

overview

[29] ST. [Online]. Available: https://www.st.com/en/data-converters/stpm01.html

[30] Meter Test Equipment. [Online]. Available: http://www.smart-energy.com/wp-content/uploads/

CALSOURCE 200.pdf

[31] Altaf Hamed Shajahan, A.Anand. (2013, June) Data acquisition and control using arduino-android

platform : Smart plug. [Online]. Available: https://ieeexplore.ieee.org/document/6533389

[32] Arduino. [Online]. Available: https://www.arduino.cc/

[33] Microchip. Enc28j60. [Online]. Available: https://www.microchip.com/wwwproducts/en/en022889

[34] YHDC. [Online]. Available: http://en.yhdc.com/product/SCT013-401.html

[35] ZigBee. [Online]. Available: https://www.zigbee.org/

[36] Arduino. [Online]. Available: https://www.arduino.cc/en/Guide/ArduinoEthernetShield

[37] Juraj Brenkus, Viera Stopjakova, Roman Zalusky, Jozef Mihalov, Libor Majer . (2015,

June) Power-efficient smart metering plug for intelligent households. [Online]. Available:

https://ieeexplore.ieee.org/document/7129031

[38] Carlos A. Trasvifia-Moreno, Angel Asensio, Roberto Casas, Ruben Blasco, Alvaro Marco.

(2014, May) Wifi sensor networks: A study of energy consumption. [Online]. Available:

https://ieeexplore.ieee.org/abstract/document/6808887

[39] Raphael Schrader, Thomas Ax, Christof Rohrig, Claus Fuhner. (2017, January) Advertising power

consumption of bluetooth low energy systems. [Online]. Available: https://ieeexplore.ieee.org/

abstract/document/7805787

[40] Microchip. Pickit3. [Online]. Available: https://www.microchip.com/DevelopmentTools/

ProductDetails/PG164130#utm source=MicroSolutions&utm medium=Link&utm term=FY17Q1&

utm content=DevTools&utm campaign=Article

67

Page 90: Design and implementation of a plug-in power metering device

[41] Panasonic. Erj - datasheet. [Online]. Available: http://industrial.panasonic.com/cdbs/www-data/pdf/

RDO0000/AOA0000C331.pdf

[42] Bourns. Cra2512 - datasheet. [Online]. Available: https://www.bourns.com/docs/

product-datasheets/CRA.pdf

[43] Itead. Hc-05 user manual. [Online]. Available: https://buyhere22.com/components/

hc05-bluetooth-datasheet.pdf

[44] Elm Chan. Fatfs - generic fat filesystem module. [Online]. Available: http://elm-chan.org/fsw/ff/

00index e.html

[45] Transcend. Transcend microsd - datasheet. [Online]. Available: http://www.farnell.com/datasheets/

1683452.pdf? ga=2.213224148.1706323983.1599328093-1886123009.1599328093

[46] Mean Well. Irm-15 - datasheet. [Online]. Available: https://www.meanwell-web.com/content/files/

pdfs/productPdfs/MW/IRM-15-spec.pdf

[47] ON Semiconductor. Lm2575 - datasheet. [Online]. Available: https://www.onsemi.com/pub/

Collateral/LM2575-D.PDF

[48] Microchip. Mcp1825 - datasheet. [Online]. Available: http://ww1.microchip.com/downloads/en/

DeviceDoc/22056b.pdf

[49] Hantek. Hantek 4032l - datasheet. [Online]. Available: http://hantek.com.cn/products/detail/14

[50] Arcol. Hs - datasheet. [Online]. Available: https://4donline.ihs.com/

images/VipMasterIC/IC/OMIT/OMIT-S-A0004284475/OMIT-S-A0004284475-1.pdf?hkey=

52A5661711E402568146F3353EA87419

68