# Energy Metering Engineering

1. Di/Dt current sensor simulation

To understand di/dt current sensing in the energy meter application, We simulate it by using the schematic as fingure below.

- Harmonic wave form f(x)=1.sin(x) + 0.3 sin(3x) + 0.1sin(5x) after pass di/dt function will be swing as r2_1 wave form fater that it be restored by integral circuit.

-  Output wave form quality be affected by RC components (filter factor).

-  For good in practice the OPAMP-OP07 should be select to reject dc offset component

2. di/dt in practice use OP07 OPAMP

- Blue wave: Current wave form measured by current transofrmer

- Red wave: Current wave form measured by di/dt current transofrmer after integral by OP 07

Schematic

(I will post later)

3. Three phase voltage sensing with resistor divider

3.1 Schematics:

To measure high voltage without using transformer, the resistor divider is the best choise and realiability. In the RDLAB, We had applied this schematics to major our project in the three phase system section

Figure 3.1: Three phases voltage sensing use resistor

3.2 Wave form

Look on the figure 2.2, in the case of 50% rate voltage V1 and V2 the measurement show that voltage sensing is high accuracy as it is

Fingure 3.2: Wave form of voltage in the case of imbalance system

# DIY Digital AC Watt Meter

Electro-Labs

February 6, 2015

Have you ever been curious about the power consumption of an appliance? For example did you wonder how much it will cost you to leave your television in standby mode whole night? Or did you want to learn how much change your refrigerator settings will make on your electric bill? If your answer is yes, you can use a wattmeter to measure the power consumption of a device. In this project we are building one.

This is an AC Watt Meter which can measure the real power consumption of a device connected to the 230Vrms/50Hz mains line. The PIC microcontroller collects the voltage and the current information with the help of ADCs and then calculates the RMS voltage of the mains line, RMS current drawn by the device and the resulting average power consumption. All these information is then displayed on the dot matrix LCD.

The meter itself doesn’t need an external power source. It is powered from the mains. Despite this, the microcontroller side is fully isolated from the parts interfacing to the mains.

## Circuit Design

The schematic of the project is drawn in SoloCapture, the schematic editor of SoloPCB tools. SoloCapture makes the schematic drawing process very easy and fast. You can download SoloPCB tools at Fabstream.com for FREE.

Please check out this video to see how to import the project libraries, open and synchronize the schematic and PCB files.

To calculate the power, we need to know the voltage across the load and the current drawn by the load. The voltage that should be measured is directly the mains voltage. We know that the mains voltage is 230Vrms/50Hz but it has a 10% tolerance. So the voltage can change between 207Vrms and 253Vrms. To make an accurate power measurement, it will be better to measure the mains voltage instead of putting 230Vrms into the calculations.

The mains line is connected to the AC IN connector (J1). For the voltage measurement, a resistor divider network (R1, R2, R3) is connected between the phase and the neutral lines.  With the help of the voltage divider, the mains voltage is down scaled at a factor of R1/(R1 + R2 + R3) = 1/201 which converts ±320V (peak) to ±1.59V. Then 2.5V up shifting is applied which finally maps ±320V to 0.91V – 4.09V that nicely fits between 0-5V with a good level of safety margin.

After this scaling and shifting process, the voltage across R2 is read by MCP3202 ADC. Then the voltage information is read by the microcontroller in 12 bit format over SPI interface. To isolate the microcontroller part from the section interfacing to the mains, HCPL-0630 high speed optocouplers are used. The second analog input channel of MCP is used to read the 2.5V reference voltage and use it as the correction factor in the calculations.

While the neutral and earth lines coming from the AC IN connector are directly connected to the AC OUT connector (J2), the phase line is passing through the ACS712-20A  hall effect based current sensor (U4) for the purpose of current measurement. The sensor outputs 2.5V at 0A. When current flows between the IP+ and IP- terminals, the sensor output changes at a rate of 100mV/A. So the output voltage becomes 4.50V at +20A and 0.500V at -20A. The sensor output is read by another MCP3202 and sent to the microcontroller over SPI.  The ACS712 provides internal isolation so no external precaution is required for isolation.

ACS712-20A is capable of reading ±20A. But considering the current limitations of the terminal blocks and the fuse holder, the AC current path is protected by a 16A fuse which is connected in series to the phase line.

There are two isolated 5V sources to power the mains and the microcontroller sides. The transformer generates 2x6Vrms from the 230Vrms. Each output is rectified by the bridge diodes and then regulated by the 78L05 linear regulators. D2 and D3 are the LEDs indicating the status of each 5V.

The microcontroller of the wattmeter is PIC18F252. Basically it reads the voltage and the current and calculates the RMS voltage, the RMS current and the average power. Then it interfaces with the LCD and shows all these values. It has a hardware SPI module which lets communicating with the MCP3202 ADCs. On the other hand it interfaces to the LCD over 4-bit or 8-bit interface.  The microcontroller’s master clock becomes 5Mhz when 20Mhz crystal oscillator is used. There is an onboard ICSP connector (J3) which is used to program the PIC.

## PCB Design

The PCB of the project is designed in SoloPCB. SoloPCB is a pack of powerful tools consisting of schematic capture, PCB layout, and integrated autorouting. You can download SoloPCB tools at Fabstream.com for FREE and start using immediately.

Please check out this video to see how to import the project libraries, open and synchronize the schematic and PCB files.

Designing the wattmeter as a handheld device was a good idea. The outline of the PCB was drawn accordingly. Autocad was used to draw the outline and the .dxf file was imported in SoloPCB.

All the footprints which are not included in the SoloPCB libraries were created manually. They can be found in the SoloPCB design files.

The lines (phase, neutral and earth) connecting AC IN connector to AC OUT connector were drawn as thick as possible.  The bypass capacitors are placed as close to the ICs as possible. Two separate ground planes are drawn for AGND and DGND to keep the ground resistance low.

All the components were placed at the top layer. An acrylic cover was planned to use as a cover for both the top and bottom layers. So the height of the bottom layer would be as low as possible.

## Software

Basically the MCU reads the voltage and the current samples every 1 ms and collects 40 sample pairs which means two periods for the 50Hz. Then calculates the RMS values and the average power. 1ms period is generated by using the Timer A module. The module runs in 16 bit mode and generates an interrupt at each overflow. So we assign a start value in each cycle and wait for the 1ms trigger.

After collecting all of the samples, the calculation processes begin. The RMS voltage is calculated by using the equation below,

The RMS current is also calculated by using the same equation.

The voltage and the current samples include the phase relation between the voltage and the current. So active (real) AC power which is V * I* cosθ can be achieved by calculating the average power by using the equation below.

Calculated RMS and power values are displayed on the LCD by using the lcd.h library of CCS C compiler.

The whole CCS C code is provided at the end of the article.

## Assembly and Test

The part list of the project is given below

You can see the power consumption of a solder station while heating up below.

You can see another measurement below. 2KW water boiler is connected to the meter.

## PIC Code

The PIC code is written in CCS C compiler.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

#include <18F252.h>

#FUSES NOWDT                    //No Watch Dog Timer

#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale

#FUSES NOBROWNOUT               //No brownout reset

#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(crystal=20000000)

#INCLUDE

#define LCD_ENABLE_PIN PIN_A0

#define LCD_RS_PIN PIN_A2

#define LCD_RW_PIN PIN_A1

#define LCD_DATA4 PIN_B4

#define LCD_DATA5 PIN_B5

#define LCD_DATA6 PIN_B6

#define LCD_DATA7 PIN_B7

#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)

#include

char tick=0;

float rms_v=0;

float rms_i=0;

float rms_v_cor=1.04245;

float rms_v_accum=0;

float rms_i_accum=0;

unsigned int32 sampling_period=60536; // 65536-60536=5000 >> 5000x200ns=1ms

float apparent_power=0;

float average_power_accum=0;

float vi_accum=0;

char i,k;

#INT_RTCC

void  RTCC_isr(void)

{

set_rtcc(sampling_period);

tick=1;

return;

}

void initialize() {

setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);

lcd_init();

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);      //13.1 ms overflow

}

unsigned char MSbyte=0x00;

unsigned char LSbyte=0x00;

// Chip Select

// Send Start Bit

Spi_Write(0x01);

// Channel Select and Read High Byte

// Join the Bytes

}

void main()

{

delay_ms(100);

initialize();

k=0;

while (1) {

set_rtcc(sampling_period);

enable_interrupts(INT_RTCC);

enable_interrupts(GLOBAL);

while(tick==0) {}

tick=0;

}

disable_interrupts(INT_RTCC);

disable_interrupts(GLOBAL);

for (i=0;i<40;i++) {

}

average_power_accum += vi_accum /40;

vi_accum=0;

rms_i = sqrt(adc_accum_i /40) * ((5/4096)/0.100);

rms_v_accum += rms_v;

rms_i_accum += rms_i;

k++;

if (k == 20) {

k=0;

printf(lcd_putc,"\f%3.1f V",(rms_v_accum/20));

lcd_gotoxy(9,1);

printf(lcd_putc,"%2.2f A",abs(((rms_i_accum/20) - 0.1)));

lcd_gotoxy(5,2);

printf(lcd_putc,"%4.1fW",average_power_accum/20);

rms_v_accum=0;

rms_i_accum=0;

average_power_accum=0;

}