# Using FPGA chip EP1C3T144I-7 and analog-to-digital converter to improve the total power measurement accuracy

Published time: 2020-07-29 11:46:17

## 1 Introduction

Digital signal processing is a field of science and engineering that has developed rapidly in the past four decades. This rapid development is the result of the rapid development of digital computer technology and integrated circuit technology. Compared with the traditional electromechanical instrument measurement, the electric energy measurement realized by the digital signal processing method has the advantages of high accuracy, simultaneous measurement of multiple parameters, and convenient use.

The traditional electromechanical electric energy meter cannot realize the measurement of harmonic power, but it is supported by the international standard (IEC-1268) of the static AC electric energy meter. This standard defines the measurement of active power and reactive power at the fundamental frequency, which means that it is not mandatory to include harmonic components.

Based on the above standards, the methods commonly used to complete power measurement include time delay method, formula method, and integration method. The time delay method among these methods is very suitable for implementation using digital systems. At this time, the active power and reactive power can be expressed by the following formulas:

## 2. Use microcontroller to calculate electric energy parameters

After the AC voltage and current signals to be measured are converted into corresponding digital quantities by an analog/digital converter, the microcontroller can complete the calculation of active power, reactive power and total power. Since the calculations of equations (1) and (2) are related to the signal cycle, when the power cycle changes, the calculation of active power and reactive power will produce errors. If the signal period can be measured and the calculation can be adjusted according to its change, then the calculation error can be reduced or eliminated.

Here adopts MCS51 compatible chip and Keil development software to complete the measurement of mains cycle and the calculation of various parameters. The period measurement of the signal to be measured is realized by the timer/counter in the single chip microcomputer. The timer/counter works in timing mode, 16-bit counting mode. The start and stop of counting are controlled by the square wave signal obtained by the sine wave conversion. When the first square wave front edge arrives, the counting is started, and when the next square wave front edge arrives, the counting stops. In this way, the data in the counter is based on the MCU work cycle. The unit period value of the signal to be measured. In the design, the clock frequency of the single-chip microcomputer is selected as 12MHz, and the working period of the single-chip microcomputer, which is the time resolution of period measurement, is 1us. The maximum value of the 16-bit counting mode of the timer/counter is 65535, and the mains cycle is 20ms, so it directly meets the range of cycle measurement requirements.

Keil development software supports assembly language and C language development of MCS51 series chips, and supports mixed programming of assembly language and C language. The data types supported by Keil Cx51 include a floating point (float) data type, which includes 4 bytes (32 bits), which enables the multiplication and addition operations to maintain sufficient accuracy and provide sufficient dynamic range. Keil Cx51 supports arithmetic operations such as addition, subtraction, multiplication, and division of floating-point data types. It also provides support for arithmetic libraries including exponentiation and square extraction. These enable the completion of equations (1), (2) and ( 3) The calculation described is very convenient.

It takes a certain amount of time to complete an analog/digital conversion of voltage and current signals. From the measured signal period and this time data, the number of multiplication and addition operations that need to be completed to achieve the integral operation can be obtained. Since the number of times of multiplying and adding operations can only be integers, and if the voltage and current data cannot be collected at the same time, but the time interval between collections can only be time-sharing, these will affect the accuracy of the integration operation.

## 3. Data analysis

The mains cycle is an integer multiple of the time required for analog/digital conversion, and the time difference between the analog/digital conversion of the voltage and current signals is not considered, that is, the sampling of the voltage signal and the current signal is completed at the same time. Table 1 shows the analog measurement data of active power and reactive power when there is a phase difference with the current signal. The measurement conditions of Table 1 are: the frequency of the signal to be measured is 50 Hz, the sampling point of one signal cycle is 1000, the resolution of the analog/digital converter is 8 bits, the voltage amplitude data is 100 units, and the current amplitude data is 100 units.

Phase difference between voltage and current (degrees)

0 1 2 3 4 Theoretical value of active power

10000 9998 9994 9986 9976 Active power measurement value

10000

9998 9994 9986 9976 Absolute error of active power measurement

0 0 0 0 0 Relative error of active power measurement

0 0 0 0 0 Theoretical value of reactive power

0 174.5 349.0 523.4 697.6 Reactive power measurement value

-0.01311 174.5 349.0 523.3 697.6 Absolute error of reactive power measurement

-0.01311 0 0 0 0 Relative error of reactive power measurement

0 0 0 0 Table 1 Power simulation measurement value when the phase difference between grid voltage and current changes

When the mains frequency deviates from the nominal 50Hz, for example, the mains frequency rises slightly, that is, the signal period decreases slightly, because the number of multiplication and addition operations that need to be completed to achieve the integration operation must be an integer, then the signal period and the integration time will have an error . When this error reaches the maximum, that is, the time required to complete an analog/digital conversion. Regardless of the time difference between the analog/digital conversion of the voltage and current signals, other measurement conditions are the same as in Table 1. At this time, the voltage signal Table 2 shows the analog measurement data of various powers when there is a phase difference with the current signal.

Phase difference between voltage and current (degrees)

0 1 2 3 4 Theoretical value of active power

10000 9998 9994 9986 9976 Active power measurement value

9990 9988 9984 9976 9966 Absolute error of active power measurement

-10 -10 -10 -10 -10 Relative error of active power measurement

-0.0010 -0.0010

-0.0010 -0.0010 -0.0010 Theoretical value of reactive power

0 174.5 349.0 523.4 697.6 Reactive power measurement value

-0.01309 174.3 348.6 522.8 696.9 Absolute error of reactive power measurement

-0.01309 -0.2 -0.4 -0.6 -0.7 Relative error of reactive power measurement

-0.0011 -0.0011 -0.0011 -0.0010 Table 2 Power simulation measurement error value when the phase difference between grid voltage and current changes

Many microcontrollers have multiple analog signal input channels and on-chip analog/digital converters, such as ADI’s ADuC8xx and TI’s TMS320C28x series, but their internals are completed by a multi-channel strobe circuit and a module Analog/digital conversion. If such a chip is used to complete the data acquisition of voltage and current signals, a time difference will inevitably occur between the two. Table 3 shows that there is a 10us time difference between the analog/digital conversion of the voltage and current signals, but the signal period is an integer multiple of the time required for the analog/digital conversion. At this time, there is a phase difference between the voltage signal and the current signal. Analog measurement data of power. Other measurement conditions in Table 3 are the same as Table 1.

Phase difference between voltage and current (degrees)

0 1 2 3 4 Theoretical value of active power

10000 9998 9994 9986 9976 Active power measurement value

10000 9998 9993 9985 9973 Absolute error of active power measurement

0 0 -1 -1 -3 Relative error of active power measurement

0 0 -0.000010 -0.000010 -0.000030 Theoretical value of reactive power

0 174.5 349.0 523.4 697.6 Reactive power measurement value

31.40 205.9 380.4 554.7 728.9 Absolute error of reactive power measurement

31.40 31.4 31.4 31.3 31.3 Relative error of reactive power measurement

0.1799 0.08997 0 0 Table 3 Power simulation measurement value when the phase difference between grid voltage and current changes

It can be seen from Table 1 that the active power and reactive power measurement methods proposed in this paper have good theoretical measurement accuracy. Table 2 shows that changes in the grid frequency will have an impact on the measurement, but the impact is very small [3]. The biggest measurement error, especially the measurement of reactive power, comes from the time difference between the analog/digital conversion of the voltage and current signals, as shown in Table 3.

## 4. Use FPGA to overcome the measurement time difference between voltage and current signals

Using a microcontroller to control two independent analog/digital converters can overcome the time difference between the voltage signal and current signal measurement. The extended data memory can store the measurement data, but the problem at this time is that it needs to be in a market. The two-way analog/digital conversion is completed simultaneously within the time of the electrical cycle, and the obtained data needs to be stored in the data memory.

The parallel processing capability of programmable logic devices makes it better than microcontrollers in terms of operating speed. Since the computer can only execute one instruction at a time, its main limitation is the operating speed. Digital systems designed with hardware solutions are always better than software The digital system of the scheme works fast.

In this design, the work done by FPGA includes controlling the control of two TLC0820 analog/digital converters, providing the storage unit needed for data storage, and realizing the data transmission interface between it and the AT89S51 microcontroller. FPGA chip adopts

EP1C3T144I-7of ALTERA Company.TLC0820 is an analog/digital converter with a parallel data interface and 8-bit resolution produced by TI with a conversion time of 2.5us. It meets the requirements of this design [6]. Use VHDL language to realize the control code of single-chip TLC0820 analog/digital converter.

IF (reset_adc = ‘0’) THEN

current_state_adc 《= 0;

wr_tlc0820 <<= ‘1’; rd_tlc0820 <<= ‘1’; clk_ram_in <<= ‘0’;

ELSIF (clk_sys‘EVENT AND clk_sys = ’1’) THEN

CASE current_state_adc IS

WHEN 0 =" wr_tlc0820 "= ’0’; rd_tlc0820 "= ’1’; clk_ram_in "= ’0’;

current_state_adc 《= 1;

WHEN 1 =" wr_tlc0820 "= ’1’; rd_tlc0820 "= ’1’; clk_ram_in "= ’0’;

current_state_adc 《= 2;

WHEN 2 =" wr_tlc0820 "= ’1’; rd_tlc0820 "= ’1’; clk_ram_in "= ’0’;

IF (int_tlc0820 = ’0’) THEN

current_state_adc 《= 3;

ELSE

current_state_adc 《= 2;

END IF;

WHEN 3 =" wr_tlc0820 "= ’1’; rd_tlc0820 "= ’0’; clk_ram_in "= ’1’;

current_state_adc 《= 4;

WHEN 4 =" wr_tlc0820 "= ’1’; rd_tlc0820 "= ’0’; clk_ram_in "= ’1’;

current_state_adc 《= 5;

WHEN 5 =" wr_tlc0820 "= ’1’; rd_tlc0820 "= ’1’; clk_ram_in "= ’0’;

current_state_adc 《= 6;

WHEN 6 =" wr_tlc0820 "= ’1’; rd_tlc0820 "= ’1’; clk_ram_in "= ’0’;

current_state_adc 《= 6;

END CASE;

END IF;

The FPGA chip controls the work of two TLC0820 analog/digital converters, and realizes the sampling of voltage signals and current signals respectively. The analog/digital converter reset signal reset_adc is sent to two TLC0820 control codes at the same time to realize the synchronous sampling of the voltage signal and the current signal. After the analog/digital conversion process is completed, TLC0820 generates an interrupt signal int_tlc0820. Under the control of this signal, the above code generates the data memory write clock clk_ram_in, and writes the analog/digital conversion result into the corresponding data memory.

The data memory storing the result of analog/digital conversion is realized by the variable parameter module LPM_RAM_DP provided by QUARTUS II programmable logic device development software. The voltage signal and the current signal have their own data storage. The data memory has independent read and write address lines, data lines, enable signals and clock signals.

The data transmission from the FPGA chip to the microcontroller is realized through the latter's data bus. This part can also be written using the finite state machine model.

After completing the design of the above-mentioned parts, generate their symbol files, and then use the schematic input mode provided by the QUARTUS II programmable logic device development software to connect all the symbols to realize a complete system. This system occupies 42 of 2910 logic units of EP1C3T144I-7 chip; 47 of 104 input/output pins; 32768 bits of 59904 bits of storage space. The actual working clock of the system is 1MHz, and the highest clock that the FPGA chip can achieve after completing this design is 212MHz.

## 5. Conclusion

The increasing technical complexity of electrical equipment makes it impossible to measure the total amount of electricity delivered to the terminal only with active power. According to the experience of some power suppliers, measuring reactive power is a countermeasure to solve the problem. For example, the most important power company in Italy has decided to install 20 million electric energy meters with both active and reactive power measurement to measure the electricity consumption of users.