dsPIC33FJ128GP206,MCP3909 Ref Design Guide Datasheet by Microchip Technology
View All Related Products  Download PDF DatasheetQ
MICROCHIP
© 2009 Microchip Technology Inc. DS51823A
MCP3909 / dsPIC33FJ128GP206
3Phase Energy Meter
Reference Design
QUALITY MANAGEMENT SYSTEM
CERTIFIED BY DNV
= ISO/TS 1694922002 =
DS51823Apage 2 © 2009 Microchip Technology Inc.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, dsPIC,
KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART,
rfPIC and UNI/O are registered trademarks of Microchip
Technology Incorporated in the U.S.A. and other countries.
FilterLab, Hampshire, HITECH C, Linear Active Thermistor,
MXDEV, MXLAB, SEEVAL and The Embedded Control
Solutions Company are registered trademarks of Microchip
Technology Incorporated in the U.S.A.
AnalogfortheDigital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, HITIDE, InCircuit Serial
Programming, ICSP, Mindi, MiWi, MPASM, MPLAB Certified
logo, MPLIB, MPLINK, mTouch, Octopus, Omniscient Code
Generation, PICC, PICC18, PICDEM, PICDEM.net, PICkit,
PICtail, PIC32 logo, REAL ICE, rfLAB, Select Mode, Total
Endurance, TSHARC, UniWinDriver, WiperLock and ZENA
are trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
© 2009, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
Note the following details of the code protection feature on Microchip devices:
• Microchip products meet the specification contained in their particular Microchip Data Sheet.
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Microchip received ISO/TS16949:2002 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
6‘
MICROCHIP
MCP3909 / dsPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 3
Table of Contents
Preface ........................................................................................................................... 7
Introduction............................................................................................................ 7
Document Layout .................................................................................................. 8
Conventions Used in this Guide............................................................................ 9
Recommended Reading...................................................................................... 10
The Microchip Web Site ...................................................................................... 10
Customer Support ............................................................................................... 10
Document Revision History................................................................................. 10
Chapter 1. Meter Overview
1.1 Introduction ................................................................................................... 11
1.2 Meter Design Parameters ............................................................................ 11
1.3 Power Calculations ....................................................................................... 12
1.4 Getting Started ............................................................................................. 13
Chapter 2. Hardware Description
2.1 Overview ...................................................................................................... 17
2.2 Analog Front End Circuitry ........................................................................... 18
2.3 AnalogToDigital Conversion ...................................................................... 20
2.4 dspic33f Hardware Connection And Peripheral Usage ................................ 22
2.5 Power Supply ............................................................................................... 25
Chapter 3. Firmware
3.1 Overview ...................................................................................................... 27
3.2 Main Loop ..................................................................................................... 27
3.3 Calculation()  Calculating Electrical Parameters ......................................... 29
3.4 ADC Sampling Scheme For Calculations .................................................... 33
3.5 ReadING A/D Data Of The MCP3909 Device .............................................. 35
3.6 Communication Of UART Interface .............................................................. 37
3.7 Resource Configuration ................................................................................ 37
3.8 Description Of Project Files .......................................................................... 38
Chapter 4. Meter Calibration
4.1 Introduction ................................................................................................... 39
4.2 Current/voltage Calibration .......................................................................... 39
4.3 Apparent Power Calibration ......................................................................... 40
4.4 Phase Lag Calibration ................................................................................. 41
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 4 © 2009 Microchip Technology Inc.
Chapter 5. PC Software
5.1 Overview And Installation ............................................................................. 43
5.2 Establish Communication ............................................................................. 44
5.3 Basic Parameters Output Screen ................................................................. 45
5.4 Phase A/B/C Harmonic Output Screen ........................................................ 45
5.5 Distortion Rate .............................................................................................. 46
5.6 Harmonic Power ........................................................................................... 46
5.7 Energy Accumulation ................................................................................... 47
5.8 Calibration Step 1  Reset All Calibration ..................................................... 47
5.9 Linearity Calibration ...................................................................................... 48
5.10 Apparent Power Calibration ....................................................................... 49
5.11 Phase Lag Calibration ................................................................................ 50
Chapter 6. Meter Communications Protocol
6.1 Introduction ................................................................................................... 51
6.2 Test Connection Command .......................................................................... 52
6.3 Total Data Request ...................................................................................... 52
6.4 Status Register ............................................................................................. 54
6.5 Harmonic Content Command ....................................................................... 54
6.6 Total Harmonic Distortion (THD) Command ................................................ 55
6.7 Start Energy Measurement Command ......................................................... 56
6.8 Stop Energy Measurement Command ......................................................... 56
6.9 Harmonic Power Command ......................................................................... 57
6.10 Calibrate Meter Voltage/current Command ................................................ 58
6.11 Calibrate Phase Lag Command ................................................................. 59
6.12 Calibrate Apparent Power Command ......................................................... 59
6.13 Calibrate Energy Pulse Command ............................................................. 60
6.14 Reset All Meter Calibration Values Command ........................................... 60
6.15 Calibrate Meter Constant (Energy Pulse Output Constant) ....................... 61
Appendix A. Schematics and Layouts
A.1 Introduction .................................................................................................. 63
A.2 Schematics And Pcb Layout ........................................................................ 63
Appendix B. Bill Of Materials (BOM)
Appendix C. Power Calculation Theory
C.1 Overview ...................................................................................................... 75
C.2 Synchronous Sampling And Quasisynchronous Sampling ........................ 75
C.3 The Harmonic Analysis Algorithm Of Quasisynchronous Sampling ........... 82
C.4 Measuring The Voltage/current Rms Value And Power Using Quasisynchro
nous Sampling Algorithm ........................................................................ 84
C.5 Measuring Frequency .................................................................................. 87
C.6 Improving Measurement Precision Of Quasisynchronous Sampling Algorithm
................................................................................................................. 89
C.7 Measuring Secondary Parameters .............................................................. 91
C.8 Apparent Power Of Each Phase And Total Apparent Power ....................... 91
C.9 Power Factor Of Each Phase And Total Power Factor ............................... 91
© 2009 Microchip Technology Inc. DS51723Apage 5
C.10 Active Energy And Reactive Energy .......................................................... 92
C.11 Positive/negative Active Energy, Positive/negative Reactive Energy And
Fourquadrant Reactive Energy ............................................................. 92
C.12 Harmonic Components Of Current, Voltage And Total Harmonic Distortion
................................................................................................................. 94
C.13 Compensation For Ratio Error And Phase Lag ......................................... 95
C.14 Relationship Between Error And Current ................................................... 96
C.15 Ratio Error Compensation ......................................................................... 97
C.16 Phase Lag Compensation ......................................................................... 98
Appendix D. 50/60 Hz Meter Operation
D.1 Firmware Versions ..................................................................................... 103
Worldwide Sales and Service .................................................................................. 104
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 6 © 2009 Microchip Technology Inc.
NOTES:
6‘
MICROCHIP
MCP3909 / dsPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51823Apage 7
Preface
INTRODUCTION
This chapter contains general information that will be useful to know before using the
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design. Items discussed in
this chapter include:
• Document Layout
• Conventions Used in this Guide
• Recommended Reading
• The Microchip Web Site
• Customer Support
• Document Revision History
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs
and/or tool descriptions may differ from those in this document. Please refer to our web site
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
“DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the
document.
For the most uptodate information on development tools, see the MPLAB® IDE online help.
Select the Help menu, and then Topics to open a list of available online help files.
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51823Apage 8 © 2009 Microchip Technology Inc.
DOCUMENT LAYOUT
This document describes how to use the MCP3909 / dsPIC33F 3Phase Energy Meter
Reference Design as a development tool to emulate and debug firmware on a target
board. The manual layout is as follows:
This document describes how to use the MCP3909 / dsPIC33F 3Phase Energy Meter
Reference Design as a development tool. The manual layout is as follows:
•Chapter 1. “Meter Overview”  Summarizes the meter specifications and a quick
getting started section
•Chapter 2. “Hardware Description”  A detailed explanation of the different
circuit blocks, their function, and implementation
•Chapter 3. “Firmware”  All the calculations performed by the dsPIC33F are
described here
•Chapter 4. “Meter Calibration”  Explains how the meter is calibrated to
accuracy
•Chapter 5. “PC Software”  Includes screen shots of the viewer/calibration
software included with the system
•Chapter 6. “Meter Communications Protocol”  The UART commands used to
communicate to the meter
•Appendix A. “Schematics and Layouts”  Both PCB, SCH files are located here
for the 2 board system
•Appendix B. “Bill Of Materials (BOM)”  Part number and ordering information
for all components of the energy meter
•Appendix C. “Power Calculation Theory”  A detailed explanation of the theory
behind the calculations described in Chapter 3. “Firmware”
•Appendix D. “50/60 Hz Meter Operation”  Instructions on converting the meter
for use in a 60 Hz line frequency environment
MPLABW
Hle>Sa vs
Preface
© 2009 Microchip Technology Inc. DS51823Apage 9
CONVENTIONS USED IN THIS GUIDE
This manual uses the following documentation conventions:
DOCUMENTATION CONVENTIONS
Description Represents Examples
Arial font:
Italic characters Referenced books MPLAB® IDE User’s Guide
Emphasized text ...is the only compiler...
Initial caps A window the Output window
A dialog the Settings dialog
A menu selection select Enable Programmer
Quotes A field name in a window or
dialog “Save project before build”
Underlined, italic text with
right angle bracket A menu path File>Save
Bold characters A dialog button Click OK
A tab Click the Power tab
N‘Rnnnn A number in verilog format,
where N is the total number of
digits, R is the radix and n is a
digit.
4‘b0010, 2‘hF1
Text in angle brackets < > A key on the keyboard Press <Enter>, <F1>
Courier New font:
Plain Courier New Sample source code #define START
Filenames autoexec.bat
File paths c:\mcc18\h
Keywords _asm, _endasm, static
Commandline options Opa+, Opa
Bit values 0, 1
Constants 0xFF, ‘A’
Italic Courier New A variable argument file.o, where file can be
any valid filename
Square brackets [ ] Optional arguments mcc18 [options] file
[options]
Curly brackets and pipe
character: {  } Choice of mutually exclusive
arguments; an OR selection errorlevel {01}
Ellipses... Replaces repeated text var_name [,
var_name...]
Represents code supplied by
user void main (void)
{ ...
}
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51823Apage 10 © 2009 Microchip Technology Inc.
RECOMMENDED READING
This user's guide describes how to use MCP3909 / dsPIC33F 3Phase Energy Meter
Reference Design. Other useful documents are listed below. The following Microchip
documents are available and recommended as supplemental reference resources.
MCP3909 Data Sheet, “Energy Metering IC with SPI Interface and Active Power
Pulse Output“ (DS22025)
This data sheet provides detailed information regarding the MCP3909 device.
AN994 Application Note “IEC61036 Meter Design using the MCP3905/6 Energy
Metering Devices” (DS00994)
This application note documents the design decisions associated with using the
MCP390X devices for energy meter design and IEC compliance.
THE MICROCHIP WEB SITE
Microchip provides online support via our web site at www.microchip.com. This web
site is used as a means to make files and information easily available to customers.
Accessible by using your favorite Internet browser, the web site contains the following
information:
•Product Support – Data sheets and errata, application notes and sample
programs, design resources, user’s guides and hardware support documents,
latest software releases and archived software
•General Technical Support – Frequently Asked Questions (FAQs), technical
support requests, online discussion groups, Microchip consultant program
member listing
•Business of Microchip – Product selector and ordering guides, latest Microchip
press releases, listing of seminars and events, listings of Microchip sales offices,
distributors and factory representatives
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
• Distributor or Representative
• Local Sales Office
• Field Application Engineer (FAE)
• Technical Support
Customers should contact their distributor, representative or field application engineer
(FAE) for support. Local sales offices are also available to help customers. A listing of
sales offices and locations is included in the back of this document.
Technical support is available through the web site at: http://support.microchip.com
DOCUMENT REVISION HISTORY
Revision A (November 2009)
• Initial Release of this Document.
6‘
MICROCHIP
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 11
Chapter 1. Meter Overview
1.1 INTRODUCTION
The MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design is a fully
functional energy meter with many advanced features such as harmonic analysis, per
phase distortion information, voltage sag detection, four quadrant energy measure
ment, and active and reactive power calculation. It uses Microchip’s powerful 16bit
dsPIC33F Microcontroller Unit (MCU).
The MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design is unique in the
fact that all calculations take advantage of the dsPIC33F DSP engine, and all output
quantities are calculated in the frequency domain through the use of direct fourier
transforms (DFT). This approach yields a large volume of outputs for a variety of meter
designs, from simple active power only energy meters, to advanced energy meters
requiring harmonic analysis.
Another significant advantage of this design, is that the dsPIC firmware implements a
quasisynchronous sampling algorithm, eliminating the need for external zerocrossing
detection and PLL (Phase Locked Loop) circuit for the synchronization of ADC samples
to line frequency. The line frequency is measured in software and corrected for mea
surement errors caused by frequency fluctuations in the power grid. This additional
processing on the dsPIC reduces the overall meter cost by eliminating the requirement
for a PLL circuit.
1.2 METER DESIGN PARAMETERS
• Accuracy Class: 0.2S
• Rated Current Ib: 3 X 5(20)A
• 3phase 4wire System
• Line Frequency Range: 4753 Hz or 5763 Hz
(firmware option, see Appendix D. “50/60 Hz Meter Operation”)
• ADC Sampling Rate: 12.8 ksps to 3.2 ksps
• Voltage Input:
 3 x 220/380V
 3 x 57.7/100V (3Phase, 4Wire)
• Starting Current: 0.001 IB
• Active Power Measurement Range: 013200W, Precision Class: 0.2.
• Reactive Power Measurement Range: 013200VAR, Precision Class: 0.2.
• Power Factor (PF) Precision Class: 0.2.
• Frequency Measurement: Precision Class: 0.2, Max. Error 0.1 Hz
• Harmonic Component Measurement of Voltage Input: 2ND31ST Harmonic
• Harmonic Component Measurement of Current Input: 2ND31ST Harmonic
• Creeping: Anticreeping Design (<0.0008 IB)
• Two Pulse Outputs: Total Phase Active Power, Total Phase Reactive Power
• Pulse Constant: 3200 Imp/kWh
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 12 © 2009 Microchip Technology Inc.
1.3 POWER CALCULATIONS
A summary of all the calculations performed by this energy meter are summarized
below.
Chapter 3. “Firmware” provides an explanation on the firmware implementation,
Appendix C. “Power Calculation Theory” is included to show the theory behind this
firmware.
• Power Grid Frequency
• RMS Voltage Of Each Phase
• RMS Current Of Each Phase
• RMS Neutral Current
• Active Power Of Each Phase
• Reactive Power Of Each Phase
• Apparent Power Of Each Phase
• Power Factor Of Each Phase
• Fundamental Active Power Of Each Phase
• Fundamental Reactive Power Of Each Phase
• Harmonic Active Power Of Each Phase
• Harmonic Reactive Power Of Each Phase
• Total Active Power:
 The Algebraic Sum Of Active Power Of Three Phases
• Total Reactive Power:
 The Algebraic Sum Of Reactive Power Of Three Phases
• Total Apparent Power:
 The Algebraic Sum Of Apparent Power Of Three Phases
• Total Power Factor
• Phase Missing / Line voltage sag detection and alarm
• Total Active Energy:
 The Algebraic Sum Of Positive/negative Active Energy
• Positive/negative Active Energy
• Positive/negative Reactive Energy
• Fourquadrant Reactive Energy
• Voltage/current Harmonic Content Of Each Phase
Meter Overview
© 2009 Microchip Technology Inc. DS51723Apage 13
.
FIGURE 11: MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design.
1.4 GETTING STARTED
To describe how to use the MCP3909 / dsPIC33F 3Phase Energy Meter Reference
Design, the following example is given using a 4wire, 3phase, 220VAC line voltage
and connection. The rated current of the energy meter is 5(20)A.
The energy meters are not shipped fully calibrated, and a full calibration should be
performed to show the true meter accuracy. See Chapter 4. “Meter Calibration” for
more information.
All connections described in this section are dependent on the choice of current
sensing element and a secondary external transformer may be required in higher
current meter designs.
dsPIC33 MCP3909
ICD Interface
UART Interface Current Transformer
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 14 © 2009 Microchip Technology Inc.
Step 1: Connect the meter to 220V line and load
The diagram below shows where the voltage and current connections should be made.
It is not required to connect all 3 phases for the meter to be operational.
220VAC should be placed between either VA, VB, VC and NIN, NOUT.
The AC load for a given phase should then be connected to the IIN and IOUT of a given
phase.
FIGURE 12: Meter Case Bottom.
Step 2: Turn On Line/Load Power to the Meter
Turn on the power to the energy meter. D1 should be lit showing the meter has power.
At this point, if a load is connected and the meter is measuring power, the power LED,
D1, should be blinking.
IAIN IAOUT
VA IBIN IBOUT
VB ICIN ICOUT
VC
~ Lmk mknm Reire:hSyud Em
Parameters Work Sfalus
mm
oaApparnntNA) 1W FrequencytHI) W W
Total ActiveNV) W Voltage Fhas: cream
TotalReactlveNar) W CurrentFnaseOrderW [W
TotalFowerFactor W NeutraICurremtAt W
Phase A Phas: B Phase 0 , .
VolkageM 0.00 0.00 107.21 15.21? 15:55:
CurrenﬁA) 0.0000 0.0000 0.0000 ‘ '
Active PowerNV) W 0.0000 0.0000
Reactlve PowerNAR! 0.0000 0.0000 0.0000
Apparent PoweerA) 0.0000 0.0000 0.0000 M Q
ICHDCHIF
Power Factor 1.0000 1.0000 1.0000 CAD;
POWPYSUPPIY Stews Losx Phasz Lost Fhasz Normal
cow 20074722 0 50 Cummumcauunowcummamﬂﬁ cammumcale
Meter Overview
© 2009 Microchip Technology Inc. DS51723Apage 15
Step 3: Connect the RS232 Cable
1. Connect the RS232 cable from the energy meter to a Personal Computer (PC),
using either COM1, COM2, or COM6.
Step 4: Run the PC Calibration Software
After installing and running the PC energy meter software on a PC running a
Windows™ Operating System, and selecting the proper comm port for RS232
communication, the following screen should show realtime meter results. The
following chapters include more detail on the firmware, calculation, and PC software.
.
FIGURE 13: “PM_Viewer” or Power Meter Viewer PC Software.
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 16 © 2009 Microchip Technology Inc.
NOTES:
6‘
MICROCHIP
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 17
Chapter 2. Hardware Description
2.1 OVERVIEW
Figure 21 is the basic hardware block diagram of the MCP3909 / dsPIC33F 3Phase
Energy Meter Reference Design. The hardware includes the dsPIC33F and ICD 2
interface, analog signal conditioning for 3phase voltage/current inputs and current
using the MCP3909 Energy Meter IC, neutral current measurement using external
opamp onboard dsPIC33F ADC, UART interface to PC, ICD2 interface for MCU
programming, and power supply circuits. Note there are two PCBs comprising this
energy meter, the power supply PCB, and the MCU/AFE PCB. Refer to Appendix
A. “Schematics and Layouts” for more information.
Threephase voltage and current signals are connected to the meter through
transformers, and connected to the MCP3909 A/D converter through a simple signal
conditioning circuit. The MCP3909 device samples the signal and performs the
analogtodigital conversion (ADC). The MCP3909 device sends the digital conversion
results to the dsPIC device via the SPI interface.
The MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design uses a quasisyn
chronous sampling algorithm via the dsPIC33F, therefore eliminating the need for
voltage zerocrossing detect and clock generating circuit, which are otherwise needed
in a synchronous sampling algorithm. The clock of the MCP3909 device is an active
external 3.2768 MHz crystal.
.
FIGURE 21: Hardware Block Diagram.
SPI
RS232
Phase A
PT
Phase A
CT
Phase B
PT
Phase B
CT
Phase C
PT
Phase C
CT
MCP3909 MCP3909 MCP3909
dsPIC33FJ64GP206
CLK 3.2768
MHz
UART
Interface
+5V
Power Supply
ICD2
Interface
ADC
I/O
SPI
UART
Neutral
line CT
Gain
Control
Op Amp
+3.3V
Power Supply
\\\\\\
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 18 © 2009 Microchip Technology Inc.
2.2 ANALOG FRONT END CIRCUITRY
For safety, current transformers are used between the voltage and current input signals
and the measurement module to isolate it from the 3phase power supply.
The transformer used for the voltage path is a 1:1 transformer, SPT204B from Beijing
Singure Measurement & Control Technology Co., with nonlinearity less than 0.1%, and
rated input/output current of 2mA/2mA.
The transformer used on the current side is a SPT254FK, from Yhehua Shanghai, with
rated input /output current of 20A/2 mA, nonlinearity less than 0.1%, and linear range
of 020 A. See Appendix B. “Bill Of Materials (BOM)” for more information on the
input circuitry.
Using phase A as an example for the voltage signal path, a 150 kΩ (R1) resistor is used
before the CT to transform the signal to an appropriate current. After the CT, burden
resistors R125 and R126 are needed to transform the current signal to a differential volt
age signal for the MCP3909 device to sample. Signals are coupled into the MCP3909
device's signal input port via R110 and R111. C111 and C112 are used to filter highfre
quency signals.
Using phase A as an example for the current signal path, transformation of the current
signal is similar to that of the voltage signal. The burden resistors R125/R126 and
R116/R117 are chosen to be 20Ω for the current channel and 100Ω for the voltage
channel after considering the following 3 factors:
• The MCP3909 device's differential voltage input range: 1V for voltage channel
and 0.705V for current channel
• Maximum current/voltage for the meter: rated current of 5A, maximum current of
20A, and maximum voltage of 300V)
• Transformer ratio for the current and voltage transformer.
A nonisolated voltage input circuit is included. In practice, a voltage divider network of
resistors is often used for sampling AC voltage input. This measuring method is
therefore included in the hardware design. In Figure 22, voltage divider resistors R3,
R4, and sampling resistor R1 construct a network for sampling AC voltage.
FIGURE 22: Input Signal Conditioning Circuit (Phase A).
1nF
1.0 kΩ
1nF
1.0 kΩ
20 Ω
20 Ω
MCP3909
CH0+
CH0
CH1+
CH1+
CTA1 SCT220B
T103
R125
R126
R110
R111
C111
C112
1nF
1.0 kΩ
1nF
1.0 kΩ
100 Ω
100 Ω
PA
N
SPT204B
T1
R116
R117
R108
R109
C109
C110
150 kΩ
R1
CURRENT
499 kΩ
R4
499 kΩ
R3
1kΩ
R1
VOLTAGE
PA
N
33 nF
C3
Jumper
VOLTAGE (NonIsolated Option)
CTA2
Hardware Description
© 2009 Microchip Technology Inc. DS51723Apage 19
2.2.1 Burden Resistor Temperature Coefficient
The high precision class 0.2S requirement for the energy meter makes it crucial to
select proper burden resistors for the output of the current transformers.
Metal film resistors with low inherent noise and temperature coefficient are ideal. Given
that the secondary current of the CT is I, then the input voltage of the MCP3909 device
is U = IR, where R is the resistance of R125 and R126 (Using Phase A as an example).
If the temperature varies by ΔT, and the temperature coefficient of sampling resistor R
is β ppm/°C, then the output voltage is:
EQUATION 21:
The voltage variation is:
EQUATION 22:
This relationship shows that the output voltage variation caused by temperature
variation is in proportion to the temperature coefficient of the burden resistor.
In addition, a smaller temperature coefficient benefits meter start stabilization after
startup. It takes a longer time for resistors with larger temperature coefficient to
stabilize. Therefore, accurate measurements would require a longer wait after
powerup. This affects the efficiency, or speed of meter calibration.
U'IR
Δ
T
β×
R
×
+()=
ΔUU'U–IΔTβ× R×× UΔT×β×== =
H mm
r
‘F'AQ‘: J\
/
#7 7—H \
/ / \
/ / \
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 20 © 2009 Microchip Technology Inc.
2.3 ANALOGTODIGITAL CONVERSION
This meter design uses Microchip's MCP3909 energy meter ICs. Smallsignal current
inputs can be amplified by the programmable gain amplifier inside the MCP3909
device. The programmable range for the MCP3909's PGA is 16:1 V/V. The MCP3909
PGA gain can be configured by G0 and G1 (Pin 15 and 16 of the dsPIC33F).
The MCP3909 device's clock is provided by a 3.3768 MHz active crystal (for 50 Hz
system, see Appendix D. “50/60 Hz Meter Operation” for 60 Hz line frequency
information). The MCP3909 device's output data rate is 12.8 ksps. The clock lines and
MCLR lines of all 3 MCP3909 devices are connected together, which ensures that the
3 phases are strictly synchronous.
FIGURE 23: Clock Generation, Sampling Times and Calculation Frequencies.
MCP3909 MCP3909 MCP3909
X100
3.3768 MHz (50 Hz Version)
fSAMPLE1 = 12.8 ksps (Active Power)
tLINE_CYC
SDO DR
Phase A,B,C I & V Data
16 bits DR
tSAMPLE
MCLK input
DR Pulse
To dsPIC33F
SDO
SDO
SDO
IRQ IC1
x 6 ADCs
(Input Capture)
fSAMPLE2 = 6.4 ksps (Reactive Power, RMS Current / Voltage)
fSAMPLE3 = 3.2 ksps (Harmonic Analysis, Distortion)
Hardware Description
© 2009 Microchip Technology Inc. DS51723Apage 21
2.3.1 Samples And Processing
Input capture IC1 on the dsPIC33F is used to detect if A/D conversion is complete.
However, not all MCP3909 device samples are stored in the MCU, depending on the
parameter being calculated. The ADC conversion rate of the MCP3909 device is
determined by the frequency of the master clock (3.378 MHz for the case of a 50 Hz
line), and the output data rate is MCLK/256 or 12.8 ksps. After each conversion is
complete, a Data Ready signal is generated by the SDO of the MCP3909 device. The
signal is fed into IC1, allowing the Interrupt Service Routine (ISR) of IC1 to read the
data. When the MCP3909 device outputs data, it first sends an ADC result of the
voltage channel, then an ADC result of the current channel, with MSB first.
As noted, not all MCP3909 device samples are used for calculating all the parameters.
In practice, 6.4 ksps sampling rate is required, which means only 1 output data is used
for every 2 data sampled. For 50 Hz input signal, 6.4 ksps sampling rate will take 128
samples for each cycle. For example, the active power metering is computed based on
this condition.
But for other parameters for which precision is not critical, such as reactive energy,
voltage, current and frequency, the sampling rate may be reduced to save data storage
space and processing time. In this design, the 3.2 ksps sampling rate is used, which
means only 1 result is stored for every 4 ADC conversions.
After each conversion, a positive pulse with the width of 4 clock cycles is output by the
SDO pin of the MCP3909 device. IC1 is used to detect the falling edge of the pulse and
generate an interrupt for every 2 falling edges, i.e., 1 data is read for every 2 conver
sions, thus realizing 6.4 ksps sampling rate.
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 22 © 2009 Microchip Technology Inc.
2.4 DSPIC33F HARDWARE CONNECTION AND PERIPHERAL USAGE
Table 21 is the pin allocation for the dsPIC33FJ64GP206 MCU.
TABLE 21: FUNCTIONAL ALLOCATION FOR dsPIC33F PINS
dsPIC
Pin Pin Function
Name
Corresponding Name
in Schematic
Diagram Functional Description
62, 1 RG14, RG15 G0A, G1A MCP3909's gain control for Phase A
2, 3 RC1, RC2 G0B, G1B MCP3909's gain control for Phase B
13, 12 RB3, RB4 G0C, G1C MCP3909's gain control for Phase C
14 RB2 CSA MCP3909's chipselect signal corresponding to Phase A
15 RB1 CSB MCP3909's chipselect signal corresponding to Phase B
16 RB0 CSC MCP3909's chipselect signal corresponding to Phase C
4, 5, 6 SCK, SDI, SDO SPI I/F Interface signal of SPI2. SPI interface operates under master
mode, used for the MCP3909 device communications
42 INT1 SDO SDO line of SPI interface, for detecting MCP3909's A/D
conversion complete flag
4951 RD1RD3 PULSE1, PULSE2,
PULSE3 PULSE1 is total phase active power pulse output, PULSE2 is
total phase reactive power pulse output. PULSE3's function is
to be determined.
61 RG0 AD_MCLR Master clear signal of 3 MCP3909 devices (tied together)
53 RC13, RC14 LED1, LED2 LED drive pins, can be used as energy pulse output indicator,
for meter calibration. Its function is similar to those of
PULSE1 and PULSE2
36, 37 SDA1 / SCL1 SDA/SCL I2C™ interface, used to read/write EEPROM externally
33, 34 U1TX / U1RX RF3/RF2 UART interface
33, 34,
35 SDO1/SDI1/SCK1 RF3/RF2/RF6 SPI1 interface, can be designed by customers, used for
communication with host MCU to obtain measurement results
and calibrate a meter. Its function is the same as UART
interface, but have a faster communication rate and higher
efficiency. SPI operates in slave mode. If UART interface is
used to communicate with host MCU, then this interface
cannot be used.
27 AN12 Current_N Detect neutral current
28 AN13 Ref_V Detect boost voltage of neutral current
17, 18 ICSPCLK, ICSP
DAT ICSP I/F Online debugging/programming interface
7 MCLR MCLR Master clear input
Hardware Description
© 2009 Microchip Technology Inc. DS51723Apage 23
2.4.1 UART and SPI1 Interface
The UART and SPI1 interfaces are multiplexed. Through the UART or SPI1 interface,
the host MCU can communicate with the metering frontend to perform calibration or
obtain metering results. The SPI interface may also be used if highspeed data transfer
is desired. In this case, the SPI interface of the dsPIC device works in the slave mode.
The UART and SPI1 share a common pin, so only one of the two interfaces can be
used at a time. Since the reference design uses a PC to simulate the host MCU, the
UART interface is chosen as the communication interface. SPI and RS232 interfaces
are not isolated from the PC. A generalpurpose transceiver device, MAX232, is used
for the UART interface.
2.4.2 Energy Pulse Output Interface
Three sets of outputs for energy measurement pulses are available in this design,
corresponding to the I/O pins of RD1RD3. Two of them, output total active energy and
total reactive energy, respectively, and the other is not yet specified. Outputs are
isolated by a photoelectronic coupling device, U3. The photoelectronic coupler is
active when corresponding I/O pin is high.
In addition, the design also provides two sets of LED outputs for energy meter calibra
tion. The output pins for these LEDs are RC13 and RC14. The LED is on when the
output is low. Figure 24 is the circuit of energy pulse output interface.
FIGURE 24: Energy Output Pulse Configuration.
RD3
RD2
RD1
RC13
RC14
1kΩ
R301
1kΩ
R301
1kΩ
R301
470Ω
R314
3.3V
470Ω
R310
3.3V
D303
D302
Total Active
Total Reactive
(not used)
Total Active
Total Reactive
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 24 © 2009 Microchip Technology Inc.
2.4.3 Neutral Current Detection
Detection of neutral wire tampering is performed by the onchip A/D of the dsPIC
device. The purpose of the detection is to prevent electricity theft, balance 3phase
signals and detect electricity leakage. Since the precision is not critical, a dsPIC
onchip A/D is sufficient.
Figure 25 shows the circuit for neutral current detection. The neutral input uses R128
for sampling. To bias the AC signals to the A/D measurement range, a 3.3V power
supply is divided by R130 and R129 and connected to the emitterfollower of the
MCP6002 device to output a boost voltage REV_V of 1.65V. The biased voltage is then
connected to the CT in series. The CT's sampling voltage is connected to Opamp B of
the MCP6002 device via R127 as emitterfollower output, generating the sampling
voltage, Current_N, for the current. Both Current_N and 1.65V VREF signals are
sampled and measured by the dsPIC onchip A/D.
.
FIGURE 25: Circuit of Neutral Line Detection.
R130
R129

+
Current_N

+
1.65V VREF
4.7 kΩ
4.7 kΩ
4.7 kΩ
R127
3.3V
U101_B
U101_A
470Ω
R128
T100 Secondary
Neutral Wire Input
Hardware Description
© 2009 Microchip Technology Inc. DS51723Apage 25
2.5 POWER SUPPLY
The power supply used in this design provides 3.3V and 5V. Since the energy meter for
a 3phase 4wire system is required to operate properly when any one phase is active,
a switching power supply module is used for convenience. T4 is the switching power
supply module.
Prior to the input of this module, additional protection circuitry is included with the meter
design. Figure 26 shows the input to the switching power supply module and the
additional filtering and protection circuitry. In Figure 26, R5 is the integrated ferrite
bead, C1, C4, C6, RV1, RV2 and RV3 are CBB capacitors and varistors. They are used
to improve antisurge performance of the system.
.
FIGURE 26: Switching Power Supply Module (T4) and Additional Input Protection Circuitry.
1
JP5
1
JP4
1
1
JP6
N
1
C
2
B
3
A
4G1 5
Vo1 6
G2 7
Vo2 8
T4
RV3RV1 RV2
A
1
B
2
C
3
N
4N5
C6
B7
A8
R5
COILS
12V
C4
0.1u
C1
0.1U C6
0.1u
PA
PB
PC
N
PA
PB
PC
N
N
1
2
3
JP6
Header 3
+C2
100uf
MCPHUI (SVSUIEW) 5V
—:L’§ B
CAP
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 26 © 2009 Microchip Technology Inc.
An LDO is connected in series at the output of the switching power supply to obtain a
more stable power supply. Figure 27 shows this circuit. Microchip's MCP1701 device
and MCP1700 device, low dropout high efficiency LDOs, are selected for use.
D301 is the power LED for the meter and is active when the meter is connected to the
proper line input voltage.
FIGURE 27: 5V and 3.3V LDO Modules.
C322
CAP C336
0.1uF
+C337
100uf
5V
C323
CAP C324
CAP
+C338
100uf
+C339
47uF
D301
LED
R316
470
Vin
3Vout 2
Gnd1
U306
MCP1700(3.3VSOT23)
1
2
J1 5V_IN
3.3V
L302
INDUCTOR
L301
INDUCTOR
Vin
2Vout 3
VSS
1
MCP1701(5VSOT89)
6‘
MICROCHIP
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 27
Chapter 3. Firmware
3.1 OVERVIEW
This section discusses the dsPIC firmware structure, peripheral resources, important
program flows, and explanations of project files included in the firmware zip files
included with the system. See Appendix D. “50/60 Hz Meter Operation” for
converting to 60 Hz code.
• Calculate all electrical parameters in frequency domain
• MCP3909 device communication
• Detect voltage/current phase order, and determine missing phases
• Generation imp/kWh power pulse
• UART communication
3.2 MAIN LOOP
The main loop of the entire dsPIC33F program is shown in Figure 31.
FIGURE 31: Main Loop Chart.
Main Program
Initialize onchip
peripherals and variables
Process UART
comm. commands
Sampled 3 cycles? Compute elec.
parameters
Neutral data
acquisition complete?
Clear WDT
Compute
neutral line
current
Yes
No
Yes
No
and MCP3909 device
Calculation()
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 28 © 2009 Microchip Technology Inc.
After system powerup, the MCU enters the initialization process, which includes
proper configuration of the I/O ports and onchip peripherals (such as timer, UART, SPI
and IC). At the same time, the system control parameters can be loaded from the
external EEPROM and variables are all initialized.
Since most tasks of this system are accomplished through interrupts, only three tasks
are carried out in the system main loop, which are interpreting/processing UART
communication protocol, calculating parameters, and detecting neutral current. The
UART communication is performed in function UART_process(), the executing
frequency of which depends on the polling frequency of the upper computer.
Parameters are calculated by the function Calculation(), which is executed once every
3 cycles of the power grid. Neutral current is detected by function ComputeNeutral
Current(), and computing is performed once every 16 cycles of the power grid.
+ >ﬁ¢
h 1"3
¢
i d:
L
$
i
¢
$
$
i
\, :
Firmware
© 2009 Microchip Technology Inc. DS51723Apage 29
3.3 CALCULATION()  CALCULATING ELECTRICAL PARAMETERS
All power parameters are calculated with the function Calculation(), which is executed
once every 3 cycles of the power grid. As shown in Figure 32, all calculations are
performed post DFT (direct fourier transform), in the frequency domain.
• RMS Voltage/current Of Each phase
• Phase Angle
• Measuring Line Frequency
• Active, Reactive, Apparent Power Of Each Phase
• Positive and Negative Active Power
• Positive/negative Reactive Power
• 4quadrant Reactive Energy
• Total Active Power, Total Reactive Power, and Total Apparent Power
• Total Power Factor
• Voltage and Current Distortion Of Each Phase
• Voltage and Current Harmonic Contents Of Each Phase
FIGURE 32: Calculation() Flow
Chart.
Note: Algorithms for all calculations are shown in Appendix C. “Power
Calculation Theory”.
Calculate function
Select sync. window
function and
sine/cosine table
phase sequence 1~3
loop
Voltage signal and
sync. window process
DTF transformation
Calculate voltage
Calculate voltage
harmonic
Current signal and
sync. window process
DTF transformation
RMS value
Calculate current
Calculate current
harmonic
RMS value
Active/reactive
power calculation
and compensation
phase sequence 1~3
end
Calculate combined
power
Combined energy
accumulation
Calculate frequency,
determine phase
sequence
Update loop array
pointer and data
length
End of function
calculation
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 30 © 2009 Microchip Technology Inc.
Each block can be categorized into one of three types of calculations:
1. Calculation for an individual phase
2. Calculation for all 3 phases
3. Calculation of power accumulation (Energy)
3.3.1 Process QuasiSynchronization Window
The first blocks of the calculation flow are to determine how many samples to use for
the quasisynchronization sampling algorithm. See Appendix C. “Power Calculation
Theory” for more information on this approach.
The firmware selects the proper quasisynchronization window function (array of data)
and corresponding sine/cosine table according to the number of sampling points in
present current cycle.
The number of sampling points is obtained from the last calculation of frequency
function. As the line frequency fluctuates in slow motion and typically varies by a small
amount over three (3) line cycles, the period of line frequency measurements of the
previous cycle can be used to determine data length of sampling.
The quasisynchronization window function is an array established in advance, and its
length is the same as that of the sampling data, which is obtained by the weight
coefficient multiplied by 32768. In this design, the method of quadrature by
complexification echelon is used, corresponding weight coefficient is calculated with
three (3) iterations. Three iterations implies that the length of the input original data is
equal to the number of sampling points in three cycles. The number of sampling points
in each cycle is usually different from the input signal cycle, but it will be close to an
integral multiple of the input signal cycle. For example, at a sampling rate of 3.2 ksps,
50 Hz input signal corresponds to 64 sampling points for each cycle, and 50.1 Hz input
signal would also be close to 64 sampling points for each cycle. Again, 51 Hz input
signal would be close to 63 sampling points for each cycle. Therefore, at different input
frequencies, the corresponding numbers of sampling points in each cycle are different.
Consequently, the corresponding quasisync window function and sine/cosine table
need to be established according to different numbers of sampling points. The
sine/cosine table is established by evenly dividing a cycle into a number of segments
equal to the number of sampling points, calculating corresponding sine/cosine values
and then multiplying the values by 32768. The purpose of the multiplication is to
change the original operation of floating point numbers into that of fixedpoint numbers.
Adjustments will be performed in the final stage of calculation.
The processing of the original signal being processed by the quasisynchronization
window function is actually a process of array multiplication, i.e. the original input signal
is multiplied with a corresponding array of window functions. It's accomplished by the
function qusi_syn_wnd(), which is written in assembly to take full advantages of DSP
features.
3.3.2 DFT Transformation
A Direct Fourier Transform (DFT) is performed on the collected sets of data. Process
ing of the original signal by quasisynchronization window can effectively reduce
spectrum leakage caused by nonentirecycle sampling during DFT transformation.
The data length is not a power of 2, therefore, the FFT algorithm cannot be used in DFT
transformation. DFT transform is accomplished by function DFT(), which is written in
assembly to take full advantages of the DSP feature of accumulated multiplication.
Since an FFT algorithm cannot be used, and it takes longer to perform a DFT
calculation, this is the most timeconsuming process in the entire system.
Firmware
© 2009 Microchip Technology Inc. DS51723Apage 31
3.3.3 Calculating RMS Voltage/Current
After the data set of either a voltage or current signal (of each phase), has been DFT
transformed, the voltage or current magnitudes of the different harmonics can then be
calculated. The total effective voltage or current (RMS) can be obtained by further
calculaton, by simply combining the results of the individual harmonics (including the
fundamental or the 1ST harmonic).
Computing the magnitude of the voltage or current is accomplished by function
ComputeMagnitude(). The result, called amplitude, is a long integer, and is the
squared magnitude of voltage or current. To speed up the computation, fixedpoint
operation is used. The ComputeMagnitude() routine is written in assembly language.
After the magnitude is computed, there is an adjustment process which is based on a
floatingpoint operation. The limited number of computations will not affect the
operation speed, and will instead greatly improve precision.
Parameter ratio1 in the firmware is a coefficient related to the number of sampling
points (see Equation 22). Division is accomplished by a simple shift operation in
firmware. If the sampling cycle is not a power of 2, it cannot be accomplished by
shifting. However, division by shifting can be accomplished by multiplying a compen
sating coefficient Coeff.data.linear.V_channel[]. This is the calibration coefficient for
ratio errors.
Since the current signal has a wide dynamic range, for small signals, the ADC output
data range is small and is limited by DSP's bit resolution (16bit MCU). If division by
shift is used in the same way that is used for large signals in computation, precision
may be affected. Therefore, for computing magnitudes of small signals, ComputeS
mallMagnitude() function is used instead. This function is similar to ComputeMagni
tude(), the only difference being that the shift length is shortened in division operation,
and will be compensated during data adjustment. The computation precision will not be
affected as the data adjustment process uses floatpoint operation.
3.3.4 Calculating Harmonics
Computing harmonics is accomplished in assembly language, by the function Com
puteHarmonic(). The computation is based on Equation C62, in Appendix
C. “Power Calculation Theory”. The result is the ratio of the magnitude of Kth
harmonic to fundamental magnitude, and is given in a percentage.
3.3.5 Calculating Power
Computing power is accomplished in assembly language by the function Compute
Power() based on Equation C39 and Equation C40 in Appendix C. “Power Calcu
lation Theory”.
After the ComputePower() function is complete, an adjusting process for computed
power is required. First, the computed result is adjusted according to the gain of current
amplifier. Then the calibrating coefficient ratio2 is determined according to present
number of sampling points.
Additional compensation to the power calculation is required, for phase compensation.
This compensation is based on the present load current. The difference between signal
frequency and the central frequency is also taken into consideration. Consequently
computed power is compensated.
Note: Since the output of ComputeHarmonic() is the squared harmonic
magnitude, extraction of square root is needed in computation. The
calculated harmonic content is stored as a fixedpoint number, and the
actual value stored is the harmonic content multiplied by 10.
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 32 © 2009 Microchip Technology Inc.
3.3.6 Active Energy Accumulation
Energy accumulation is done by calculating the total energy, which is the algebraic sum
of energy of each phase. Active energy is obtained by accumulating the multiplication
of voltage and current of each sample, which ensures the high accuracy of measure
ment.
3.3.7 Reactive Energy Accumulation
The required measurement accuracy of reactive energy low, so in this design, it is
obtained by accumulating the product of the present measured reactive power and the
time interval between two measurements.
3.3.8 Output Pulse Generation
Refer to Section 2.4.2 “Energy Pulse Output Interface” for pulse output. To ensure
the uniformity of output pulses, the calculation is divided in the measurement cycle into
in a number of equal sections, and accumulate them. For simplification and lowering
computation complexity, a counter is used to substitute the process of accumulation.
The counter is only enabled when accumulated energy approaches to the threshold of
the pulse output.
3.3.9 Line Frequency Calculation
Frequency calculation is based on Equation C52 and Equation C53, in Appendix
C. “Power Calculation Theory”. The dsPIC33F collects 3line cycles worth of data.
The first two cycles of data of all sampled data is analyzed, and then the frequency of
two successive cycles is used.
The data of two successive cycles are transformed via DFT for the fundamental, which
is accomplished by assemble function DFT_Fundamental(). This is followed by the
computation of the initial phase angle of the first two line cycles. Then the phase lag
and frequency offset of the two line cycles of signal can be calculated.
When measuring frequency, only the first two cycles of data are used. It must be
assumed the input frequency is 50 Hz and the chosen appropriate sine/cosine table to
carry out DFT transform for fundamentals of the 1st and 2nd cycles of data. See
Appendix D. “50/60 Hz Meter Operation” for 60 Hz firmware.
Frequency offset is calculated by determining the initial phase angle for each line cycle.
The greater the frequency offset, the greater the measurement error.
Since one of the 3 phases may be missing, if the voltage magnitude for phase A is less
than the threshold, it is necessary to switch to phase B. Consequently, if sufficient volt
age magnitude of phase B is not detected, it is necessary to switch to phase C.
The basic algorithm for measuring line frequency is based on the method described in
Appendix A, Section C.4 “Measuring The Voltage/current Rms Value And Power
Using Quasisynchronous Sampling Algorithm”.
Frequency will be measured once for every 3 times the data is sampled.
Firmware
© 2009 Microchip Technology Inc. DS51723Apage 33
3.4 ADC SAMPLING SCHEME FOR CALCULATIONS
The ADC conversion rate of the MCP3909 device is determined by the frequency of
master clock, MCLK, and the rate will be MCLK/256. After each conversion is complete,
a DataReady signal (4CLK length) is generated by the SDO of the MCP3909 device.
The signal is fed into IC1 (Input Capture 1 on the dsPIC33F), allowing the Interrupt
Service Routine (ISR) of IC1 to invoke dataread function of the MCP3909 device.
When the MCP3909 device outputs data, it first sends the ADC result of the voltage
channel, then that of the current channel, with the MSB first.
The frequency of the master clock, MCLK, of the MCP3909 device is 3.2768 MHz, and
ADC outputs @12.8 ksps. In practice 6.4 ksps sampling rate is used in the program,
which means only 1 output data is used for every 2 data sampled. For a 50 Hz input
signal, a 6.4 ksps sampling rate will take 128 samples for each cycle. The active power
calculation is computed based on this condition.
The other parameters for which precision is not critical, such as reactive energy,
voltage, current and frequency, the sampling rate may be reduced to save data storage
space and processing time. In this design, the 3.2 ksps sampling rate is used, which
means only 1 result is stored for every 4 ADC conversions.
In the program, sampling and calculation are carried out concurrently, and data is
stored in the cyclic array in the dsPIC33F RAM. A calculation may be performed after
either 1 cycle, 2 cycles or 3 cycles of data are sampled, which can be configured in the
program. The user should note that frequent calculations will increase the measure
ment precision at the price of system overhead and response speed, therefore making
proper tradeoffs based on practical requirement. In this design, 3 cycles of signals are
sampled before an AC electrical parameter calculation is performed. Refer to
Figure 33.
FIGURE 33: AC Signal Sampling alnd Computing.
3.4.1 Processing IC1 Interrupt
Input capture IC1 is used to detect if the A/D conversion is complete. After each
conversion, a positive pulse the width of 4 clock cycles is outputted by the SDO pin of
the MCP3909 device. IC1 is used to detect the falling edge of the pulse and generate
an interrupt for every 2 falling edges, i.e., 1 data is read for every 2 conversions, thus
realizing 6.4 ksps sampling rate.
In addition to reading the data of the MCP3909 device, the IC1 interrupt service routine
(ISR) also controls the energy pulse output generation. Energy pulse processing
consists of active/reactive energy pulse processing. For the pulses to be outputted
more uniformly, the clock resolution used to generate the pulses must be as high as
possible. The interval of the IC1 interrupt is 156.25 µs, therefore, the resolution
generated by the pulse can be up to 156.25 µs.
Sampling
Cycle n Sampling
Cycle n+1 Sampling
Cycle n+2 Sampling
Cycle n+3
Idle Idle Idle Calculate
n,n+1,n+2
Sampling
Cycle n+4
Idle
'rocessmg
ﬁang edge m
acme energy?
Processmg
nsmg edge 0
achve energy?
Pmcessmg y
lang edge 0 ,
eachve energy?
.< processmg="" nsmg="" edge="" 0="" achve="" energy?="">
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 34 © 2009 Microchip Technology Inc.
The energy pulse processing program only begins when the level is close to outputting
pulse level. To simplify the process and shorten the ISR execution time, a counter is
used in place of the energy accumulation function for each pulse and to determine if a
pulse will be outputted. When the count is greater than the threshold of pulse output,
an energy pulse will be outputted, and the appropriate amount of energy will be sub
tracted from the energy accumulating register. Output toggling will then be processed.
Once the width of the output pulse exceeds 80 ms, the pulse output will be turned off.
The program flow chart is shown in Figure 34.
FIGURE 34: IC1 Interrupt Service Routine.
ICI Interrupt Service
routine
Call MCP3909 data
read program
Processing
falling edge of
active energy?
Processing
rising edge of
active energy?
Processing
falling edge of
reactive energy?
Return
Yes
Yes
Yes
Yes
No
No
No
No
Processing
rising edge of
active energy?
Update pulse width
counter, if counter >
flip threshold, output
pulse and update
energy accumulation
register.
Update pulse width
counter, if counter >
flip threshold, output
pulse and update
energy accumulation
register.
Update pulse width
counter, if pulse
width > 80 ms, toggle
pulse output level.
End pulse output
process.
Update pulse width
counter, if pulse
width > 80 ms, toggle
pulse output level.
End pulse output
process.
Firmware
© 2009 Microchip Technology Inc. DS51723Apage 35
3.5 READING A/D DATA OF THE MCP3909 DEVICE
All three MCP3909 devices use the same clock source and reset signal, so all 6 A/D
channels of the 3 MCP3909 devices are synchronous. Only a single Data Ready (SDO)
signal of any of the MCP3909 device is required to read A/D data of the 3 phases in
turn. This module is invoked by IC1 interrupt triggered by the "data ready" signal on the
SDO of the MCP3909 device. IC1 is set to generate an interrupt for every two falling
edges. Therefore, only one of the two sampling data of the MCP3909 device is
read.The flow of reading the MCP3909 device's data is as follows:
• Retrieve all values of 3phases, both current channel and voltage channel data.
Bits 015 of each phase data are voltage channel data, bits 1631 are current
channel data
• Accumulate the active power of each phase. On every other interrupt, the current
and voltage values are stored into RAM in the cyclic sampling array
• Update the pointer of sampling array and length of sampling data. If the length of
sampling data is 3line cycles long, set the sampling complete flag, and then the
calculation function Calculate() will be called by the main flow to start computing
all corresponding parameters.
FIGURE 35: Flow Chart of Read A/D Data.
Read MCP3909 data
Select phase A of
clear SPI flag
Even count
data read?
Read phase A data
and accumulate active
energy of phase A
Read phase B data
and accumulate active
energy of phase B
Read phase C data
and accumulate active
energy of phase C
End
Read phase A data,
accumulate active
energy of phase A
and save data to array
Read phase A data,
accumulate active
energy of phase A
and save data to array
Read phase A data,
accumulate active
energy of phase A
and save data to array
Update array pointer,
sample pass count
flag and data length
End of sampling of
this cycle?
Set data sampling
complete flag
No
Yes
y
No
The MCP3909 device,
\nitiahze MCPSQO?
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 36 © 2009 Microchip Technology Inc.
3.5.1 Initialize and Configure MCP3909 Operation Mode
The task of this module is to enable the MCP3909 device to enter the "Channel Output"
mode. This design uses the "Channel Output" mode of the MCP3909 device. In this mode,
the current and voltage data channels measured by the ADC is sent through the
MCP3909 device's SPI port. To enable the MCP3909 device to enter the Channel
Output mode, certain instructions must be sent to the device via the SPI interface within
a specified time (32CLK) after resetting the MCP3909 device.
• Enable all MCP3909 devices: enable ADCS1, ADCS2 and ADCS3, and configure
MCU's SPI to 8bit mode
• Reset the MCP3909 device through the RESET pin. The pin must be pulled low
for no less than 1 clock cycle of the MCP3909 device
• After the RESET pin is pulled high, wait for 4 clock cycles for the MCP3909 device
pin functions to reset
• Send Instruction 0x94 to the MCP3909 device through the SPI Interface
• Configure the SPI interface to 16bit mode and strobe the MCP3909 device for
Phase A
FIGURE 36: Initializing the MCP3909 Device Flow Chart.
Initialize MCP3909
Strobe all
Reset the
Wait for 4 CLK cycles
Send instruction 0xac
Set SPI to 16bit mode
Strobe phase A of
the MCP3909 device
End
MCP3909 devices
MCP3909 devices
Firmware
© 2009 Microchip Technology Inc. DS51723Apage 37
3.6 COMMUNICATION OF UART INTERFACE
The UART interface is used to communicate with the upper computer (MCU or PC). Via
the UART interface, the upper computer reads the measured parameters of the power
grid, and may also send system parameters and calibration parameters to the target
board as well.
The communication interface is a bidirectional interface based on UART, using
master/slave halfduplex mode. The baud rate is 19,200 bps, with 1 start bit, 8 data bits
and 1 stop bit. Communication is done by frames with nonfixedlength frame structure,
definition of which is shown in Table 31. The Communication protocol is specified in a
masterslave structure. The system in this design is the slave, and the upper computer
is the master. The master sends commands to the slave, and slave responds to the
master.
Each command is defined in Chapter 6. “Meter Communications Protocol”.
TABLE 31: FRAME STRUCTURE OF COMMUNICATION PROTOCOL
3.7 RESOURCE CONFIGURATION
Details of the MCU resources used in this design and their configurations are listed in
Table 32.
Sync Field Command Type Data Length Data Field Checkout Byte End Byte
2 bytes 1 byte 1 byte N bytes 1 byte 1 byte
TABLE 32: CONFIGURATION OF MCU RESOURCES
Resource Name Interrupt
Priority Functional Description
System Clock Fcy = 29.4912M, provided by an external 7.3728 Mz timer through an inter
nal PLL frequency doubler.
Timer Timer2 1 System clock, used for timing. Its cycle is 10 ms. The interrupt flag may be
set in the IRS. Used to extend the indication of timer. Also used to deal with
UART reception overtime.
Timer3 none Used to detect ADC's sampling synchronization of neutral current. After the
frequency of the power grid is measured, the period of TMR3 is adjusted
accordingly. 16 points are sampled by ADC for each cycle of power grid.
Interrupt TMR2 1 ditto
IC1 5 Driven by a 3.2768 MHz clock. The MCP3909 device can generate
12.8 ksps of data output.
Sampling input capture. An interrupt is generated for every two MCP3909
device samplings. 6.4 ksps sampling rate is realized.
In fact, active power is cumulated at 6.4 ksps sampling rate (128 sampling
points each cycle at 50 Hz), but other parameters are cumulated at 3.2 ksps
sampling rate
UART RX 2 Receive data of UART communication
UART TX 2 Transmit data of UART communication
ADC 2 Detect current of neutral line
SPI2 none Used in communicating with the MCP390X device  set the MCP390X
device's modes and read A/D results
SPI1 none Unused, but the interface is reserved and may be used to communicate
with upper computer in substitution of the UART interface
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 38 © 2009 Microchip Technology Inc.
3.8 DESCRIPTION OF PROJECT FILES
TABLE 33: FILE DESCRIPTION
File Name Description
main.h
main.c Main program
global.h
global.c Mainly define important system macros, key data structures, and declare global variables.
MCP390x.h Declare macros, constants, local global variables, some of the global variables and functions
used in the MCP390X device.
MCP390x.c Functions involved with the MCP390X device, including set SPI, initialize the MCP390X device
and read data.
calcu.h Declare macros, constants, local global variables, some of the global variables and functions
used in calcu.c.
calcu.c Main module to calculate parameters, including calculate frequencies, current/voltage RMS,
power, power factors and energy, and analyze harmonics.
uart_comm.c Declare macros, constants, local global variables, some of the global variables and functions
used in uart.c.
uart.c Receive, transmit, process protocol and so forth for UART communication.
Calibrate.c Program for Ratio error calibration, power calibration and phase lag calibration, it stores and
initializes calibration data.
Calibrate.h Declare constants, local variables and global variables used in calibration.
Adc.c
Adc.h Onchip ADC operation, detecting the current of neutral wire.
I2Csubs.h
I2Csubs.c Control EEPROM of offchip I2C interface.
interrupt.h Declare macros, constants, local global variables, some of the global variables and functions
used in interrupt.c.
interrupt.c Set interrupts and ISRs.
Asmcode.c Some assemble functions used in calculation.
6‘
MICROCHIP
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 39
Chapter 4. Meter Calibration
4.1 INTRODUCTION
Meter calibration consists of using standard electrical power equipment that supplies
the power to the meter and calculates the error and correction factor at each calibration
point. This equipment must be accurate in order to calibrate the energy meter. The
supplied PC software is then used to send calibration commands and correction factors
down to the dsPIC33F, completing meter calibration.
Why Is Calibration Necessary?
An energy meter usually consists of errors due to transformers, VREF tolerance, ADC
gain errors, and other passive component errors. Energy meters are factory calibrated
before shipping to eliminate the impact from such elements and reduce the error. The
nonlinearity and inconsistency of signals in the path of sampling circuit and A/D
conversion circuit cannot be ignored in highaccuracy measurement. The impact needs
to be corrected to improve measurement accuracy.
The calibration described in this chapter are calibrated with the help of the PC software
PM_Viewer, described in detail in the next chapter. To summarize the process, the
measurement error is fed into the software, and the data is then sent to the meter to via
the UART. The details of this procedure are detailed in the next chapter, "PC Software".
4.2 CURRENT/VOLTAGE CALIBRATION
Current and voltage calibration is a ratio error calibration from the upper computer by
sending commands and data for correction to the MCU. The dsPIC33F will call a
firmware module after receiving the command from the host PC. The flow is as follows:
1. Determine the phase to be calibrated and the magnitude of current and voltage
being applied to the meter, and read measurement (RMS) values of that channel.
2. Calculate the calibration coefficient of the ratio error by the ratio of standard value
received to the measured value.
3. Multiply the original coefficient by calibration coefficient and obtain the calibration
coefficient after correction.
4. Store the final calibration coefficient after correction into EEPROM.
Since the dynamic range of the voltage channel is usually very small, singlepoint
calibration is enough to meet the accuracy requirements for full range. However, the
dynamic range of the current channel is larger, and the transformer has different ratio
errors at different current loads.
The MCP3909 device’s current channel, CH0, contains a PGA with gain options of 1,
2, 8, 16. For highaccuracy energy meters, current ratio error needs to be segmented
and calibrated for different current loads. The ratio error calibration of current channel
uses a twopoint calibration method. One point is calibrated when the load is at the
rated current (IB) and the PGA gain is 1. The second point is calibrated under smallsig
nal input condition (0.1 IB) and the PGA gain is 16.
Note: Voltage and current calibration is a two step process using 100% and
10% IB.
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 40 © 2009 Microchip Technology Inc.
4.2.1 Current/Voltage Calibration Process
The process of calibration is as follows:
1. Supply the meter with balanced load, PF = 1.0, VCAL = 220V, IB = 5A.
2. Load the dsPIC33F with the proper correction factors. Automatically done using
the PC software. See Chapter 5. “PC Software”.
Repeat these following steps for the second point at 10% IB:
1. Set the threephase balance input conditions PF = 1.0, VCAL = 220V, ICAL = 0.1 IB or
500 mA.
2. Load the dsPIC33F with the proper correction factors. Automatically done using
the PC software. See Chapter 5. “PC Software”.
If accuracy is not critical, the singlepoint calibration method can be used. The number
of calibration points can be defined in the header file of the program.
4.3 APPARENT POWER CALIBRATION
Apparent Power calibration function is implemented by the upper computer by sending
the commands. Before the power calibration process can be entered, power calibration
mode command needs to be sent first. The error data of the calibration workbench and
channel information to be calibrated are sent to the metering frontend. When the
frontend receives the command, it calls this module. The flow is as follows:
1. Determine the phase to be calibrated according to the parameters received.
2. Calculate new power calibration coefficient according to the error value received
and the measured value, together with the original power calibration coefficient.
3. Store the coefficient after correction into the EEPROM.
4.3.1 Apparent Power Calibration Process
The process of calibration is as follows:
1. Set the input condition as: Phase A PF = 1.0, VCAL = 220V, input current is the
current when region N is being calibrated, the voltage and current inputs of phase
B and C are zero.
2. Choose the energy pulse output to be the apparent power output mode Refer to
Chapter 6. “Meter Communications Protocol”. At this time, the energy pulse
is the accumulated multiplication of power and time.
3. Load the dsPIC33F with the proper correction factors. This is automatically done
using PC software. See Chapter 5. “PC Software”.
4. Repeat steps 1  3 for phase lag calibrations for all current regions of phase A.
5. Repeat the above steps for Phases B and C.
Note: At this time, the phase lag has not been calibrated, so when the input
PF = 1.0, the measured value of the reactive power isn't equal to zero.
Meter Calibration
© 2009 Microchip Technology Inc. DS51723Apage 41
4.4 PHASE LAG CALIBRATION
The phase lag calibration function is implemented by the upper computer by sending
the proper commands via the UART. When calibrating phase lag, error from the
calibration equipment and channel information to be adjusted are sent to the dsPIC33F
energy meter. When the frontend receives the command, it calls this module. The flow
is as follows:
1. Determine the phase to be calibrated according to parameters received.
2. Calculate new phase lag calibration coef. according to the error value received
and the measured value.
3. Store the coefficient after correction into the EEPROM.
This meter design supports single, two, and five point calibration for phase lag error
correction.
The purpose of phase lag calibration is to eliminate the impact of phase lag introduced
by the current transformer (CT), and voltage transformer (PT) over the power measure
ment range.
The voltage transformer usually has a constant load, thereby introducing a phase lag
that varies insignificantly. The dynamic range of current is larger, and under different
current loads, phase lags caused by CT vary greatly. In order to meet the requirements
of measurement accuracy in the entire range, it is usually necessary to segment the
phase lag and calibrate.
In this design, current is partitioned into 5 regions.
TABLE 41: CURRENT REGIONS FOR PHASE CALIBRATION
The partition limit for the current region can be modified in the header file of the
program. If accuracy is not critical, singlepoint calibration and twopoint calibration can
be used to improve the efficiency of meter calibration.
Single, Two, or Five Point Calibration
Single, two or fivepoint calibration method can be configured by modifying the
header file. When using the singlepoint calibration, the phase lag compensation
values of all regions are the same; When using twopoint calibration, the compensation
values of region 1 and 2 (00.075 IB, 0.075 IB  0.2 IB) are the same, and the phase lag
compensation values for region 3, 4 and 5 (0.2 IB  0.75 IB, 0.75 IB  1.5 IB, 1.5 IB 
4.0 IB) are the same.
Region Current Range
1 0  0.075 IB
2 0.075 IB  0.2 IB
3 0.2 IB  0.75 IB
40.75 I
B 1.5 IB
5 1.5 IB  4.0 IB
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 42 © 2009 Microchip Technology Inc.
4.4.1 Phase Lag Calibration Process
The process of phase calibration is as follow:
1. Setup input condition: Phase A, voltage input 220V, current input is the current
for region 1, voltage and current inputs of phase B and phase C are zero.
2. Load the dsPIC33F with the proper correction factors. This is automatically done
using the PC software. See Chapter 5. “PC Software”.
3. Repeat steps 1 and 2 for phase lag calibrations for all current regions of
phase A.
4. Repeat for Phases B & C.
Note: If the power metering error still can not meet the requirement, the meter can
be calibrated a few more times. When doing so, simply input a new error
value into the frontend of the meter.
6‘
MICROCHIP
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 43
Chapter 5. PC Software
5.1 OVERVIEW AND INSTALLATION
The PC software “PM_Viewer” or “Power Meter Viewer” has two main functions: view
the calculated parameters and calibrate the meter. The PC software has seven output
display screens, or “work modes”, selected from the toolbar pulldown menu.
• Basic Parameters
• Phase A Harmonic
• Phase B Harmonic
• Phase C Harmonic
• Distortion Rate
•Harmonic Power
• Energy Accumulation
In addition, the PC software has four calibration screens, selected from the toolbar
pulldown menu.
• Reset All Calibration
• Linearity Calibration
• Apparent Power Calibration
• Phase Lag Calibration
5.1.1 System Required
• HDD space > 25 MB
• Microsoft Windows OS98 or later
• Hardware COM interface
5.1.2 Installation
1. Unzip PM_Viewer setup.zip.
2. Double click on setup.exe.
3. Finish the installation according the prompt.
4. To PM_Viewer.exe  Start > Program > Energy Meter >PM_Viewer.exe.
r my wumeae Refruhsyud
3: Parameters War“ 5‘3““
o a ApparentwA] 0.000 Frequency/1H1) 49.97 W
Total Activsm 0.000 Voltage Phaso UniWm
Total Reactivewar) 0900 Current Phase Order Normal 1 seemm
TotaIPowerFactur 1auu NeutralCurrenttAl 00034
Phase A Phase B Phase c
Voltagem l0 00 poo ‘137 21
CurrentlA) . ﬂoooo
Active PowerfW)
Reacllve PowerrVAR) .
Apparent Powsrtvm . . Q
P MIEHDCHIP
owor Factor 1.0000 . CADC
Power Supply status L Lost Phase
mm mm 22 a 54 EnmmumcauanOKlCammand 96 mmmumcatn
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 44 © 2009 Microchip Technology Inc.
5.2 ESTABLISH COMMUNICATION
1. Open PM_Viewer.
2. Click on Comm Port selection, and select the com port (com1, com2, or com3)
that you will use on the menu, noting the baud rate is 19200 bps in 181 format,
and can not be changed.
3. Click on the Link to establish communication with the demo. “Communication
OK!” will be displayed on the bottom, if communication is established.
FIGURE 51: Establising Communications.
Emmi rm mm . lefremiyeed mama“ rm
Baaic Part 3“ 1? :mm Wnrk Sham:
TotzlApp "me u “mm quuency1H1) 60.00 W
nmmm rm
TotaIAcri hm. hm Voltage Phase Order phas, Reva
My gamma 7
Total ReamW current Phase Order Normal 1 sacond
TotalPowerFactor 1.000 Neutral Current(A) 03043
Phase A Phase B Phase 0 ,
Vcl‘ageM 10.00 10.00 1137.47 15:: 1535':
curremw 1W 1W 1W
Active Power(W1 10.0000 10.0000 10.0000
Reactive PowerWAﬁ) 1W 1W 1W .
ApparemPowarh/AJ W 1W 1W 6
Power Factor 1W 1W 1W “€13?”
Paw" Supply Status 1m 1W 1W
cow 2.107122 was warm
cmrm rm mum Idxuhsvgzﬂ Cnhhxnnan um
Phase A Harmonic Work Status
antagz1“/.1Curr2m("/.1 Valtage1“/.) Currem("/.) Vohage(°/.1 Currem(“/.) PhaseAHI'mnic
2 a 10 12 a 10 22 n 10
a n 1n 13 n 10 23 n 1a 1' second
4 a 10 14 a 10 24 n 10
5 n7 hi rs n7 ’07 25 n ’07
6 a 10 16 a 10 26 n 10
7n71n717n710727n7107 Start Stop
animilaaihizanihi 1"“ Te“
9 n7 W 19 n7 W 29 n W
m 70 ’7“ 20 7“ 170 30 n 170
n in W 21 in W a) a W G
Mrcaama
cum
mm m w 31
PC Software
© 2009 Microchip Technology Inc. DS51723Apage 45
5.3 BASIC PARAMETERS OUTPUT SCREEN
FIGURE 52: Basic Parameters Work Mode Screen.
5.4 PHASE A/B/C HARMONIC OUTPUT SCREEN
FIGURE 53: Phase N Harmonic Work Mode Screen.
Cami You um imam Refresh siege Eanuan [m
Dislnnion
Phase A Phase 5
Voltage Dislorlion(%) o ‘0
Current Disloniant‘M n 0
mums m 1U 32
Work Status
Dismmon Rale
o h second
sun smp
Tesi T251
6‘
MICHUENID
mm:
Conn 170:! mi. mum Rdruh 99nd Cumnuan
Harmonic Power
Phns: A
Fundemenlal Active Power 0
Fundemennai Reactive Power in
Harmonic Active Power(W) o
Harmonic Reaclive PowerWA) 0
min am in 3:
Km
Phase a
777
Work Slalus
Phase 1:
Harmon Power
0
i0 ‘1 second
MIERDCHIF
two
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 46 © 2009 Microchip Technology Inc.
5.5 DISTORTION RATE
FIGURE 54: Distortion Mode Screen.
5.6 HARMONIC POWER
FIGURE 55: Harmonic Power Work Mode Screen.
CnnnFoxr Lnik Workrlade remenSoeea camrnion Em
Energy Cumulaﬁon
1st Quad Reactive Energy 0
E?
2nd auad Reactive Energy 0 ’7
3rd Quad REadivE Enerqy 0
4m Quad Reaciive Energy ‘0
deard Reactive Energy ’70
Backward Reactive Energy ’70
Forward Active Energy ‘0
3
33
‘Kwn
BackwardAcliveEnergy o 7 W
TotalActive Energy ’70 W curnniar n
2nu75 H was
Clear
Wnrk Slalus
‘Energy Cumulalinn
ii secdnd
Siari stop
Test resi
MIEEDCHIB
[‘ADC
comm ma van node lerzsnspnd i‘nmnu
Basic Pararneiers
Tmal Apparenﬂvlj n
Tmal AciivetW) n
Tmal ReaclivEWar) 0
Tmal Fewer Faclor 0
Phase A
Voiiageiv) 107
curremiA) 107
Aclive Poweriwl {of
Reaciive PoweriVARi {of
Apparem PoweriVA) {of
Power Fanor ’07
Power supply siaius Normal
Znulsii mm
Linennv Cammuon
Arman)“ Panr canmauan
m” m Cahhnumi
anlzge Pnase Order Manual
Curreni Pirase OrderW
Nemrai Currenim
Pirase a
7777777
7777777
ormal
0
Phase c
ornral
Work Slams
‘Baslc Parameters
1 second
sian Slop
Tesr Tesi
MERGEHIP
cADc
PC Software
© 2009 Microchip Technology Inc. DS51723Apage 47
5.7 ENERGY ACCUMULATION
FIGURE 56: Energy Accumulation Work Mode Screen.
5.8 CALIBRATION STEP 1  RESET ALL CALIBRATION
1. Select Reset All Calibration from the toolbar menu.
2. Meter Calibration Values are Reset.
FIGURE 57: Reset All Calibration Command.
n hem
Eamhn me New. “has,“ gamma. 2“.
LinsarityCalibration
Region Select Phase selce¢
ﬁ 100% r: Phase A
F 10% r Phase B
r Phase I:
Condimen
3 phs balanceNoltage100%,Cuvrent100%,
PF=I.0
channel Select
: Vullage
“ Current
Resetlnnial
Va‘ue
standard Meter
Value 22 set
Close
Wlndow
znumm
Work Status
‘Linearily Calibration
1 second
9
Mlcnncmn
CADC
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 48 © 2009 Microchip Technology Inc.
5.9 LINEARITY CALIBRATION
1. Select Channel, either Voltage or Current.
2. Select Phase A, B or C.
3. Select Region, either 100% or 10%.
4. Using a standard meter, supply the input conditions given here.
5. Enter the error recorded from the standard meter here.
6. Click the Set button.
cam.“ Lmk wnmae many!“ mam”, 1m
Power Callbratmn
Work Slams
Raglan Select Phase Selecr Error Input Appartm Pow" Calihr
a Regmm r phase A Ermr Rata'
{007 % W
P Remonz 7 Phase 5 '
” R°9‘°"3 r Phase c Set
v Remona
v Remonﬁ
Set Reset Initial Close
Apparent Vzrue Wlndow
conmnan Q
o .a%lh MICRUCHI!
er Appzlem“ hurrah berm caubratmn “DC
com mmm n35 unenwszzmnmsnw
PC Software
© 2009 Microchip Technology Inc. DS51723Apage 49
5.10 APPARENT POWER CALIBRATION
1. Select Phase A, B or C.
2. Select Region n.
3. Using a standard meter, supply the input conditions given here.
4. Click the Set Apparent button.
5. Enter the error recorded from the standard meter here.
6. Click the Set button.
7. Repeat steps 25 for the different regions.
8. Repeat for other 2 phases.
Eammhxi Linda imam ReiyeShSyeed carom)“. 2m
Phase Lag Calibration
Currentﬁeﬂlcn Select
a Region1
r Rogion 2
r Region 3
r Reulond
r Rtgion 5
Condition:
PhsA ,PF=o.6L,3%Ib
Error on %
cow mum“ n m
Phase Select
6 PIraseA
r Phase B
r Phase I:
Rosa inin‘al
Value
close
59‘ window
Cammumcatian Evian mommanaim
Work stains
Phase Laa Calibration
1 second
6‘
MICRDCHIP
CADC
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 50 © 2009 Microchip Technology Inc.
5.11 PHASE LAG CALIBRATION
1. Select Phase A, B or C.
2. Select Region n.
3. Using a standard meter, supply the input conditions given here.
4. Enter the error recorded from the standard meter here.
5. Click the Set button.
6. Repeat steps 25 for the different regions.
7. Repeat for other 2 phases.
6‘
MICROCHIP
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 51
Chapter 6. Meter Communications Protocol
6.1 INTRODUCTION
The UART interface is used to communicate with the upper computer (MCU or PC). Via
the UART interface, the upper computer reads the measured parameters of the power
grid, and may also send system parameters and calibration parameters to target board
as well.
The communication interface is a bidirectional interface based on UART, using
master/slave halfduplex mode. The baud rate is 19,200 bps, with 1 start bit, 8 data bits
and 1 stop bit. Communication is done by frames with nonfixedlength frame structure,
definition of which is shonw in Table 61. Communication protocol is specified in
masterslave structure. The system in this design is the slave, and the upper computer
is the master. The master sends commands to the slave, and the slave responds to the
master.
UART communication uses halfduplex mode. The data format is 811 and the rate is
19,200 bps. The PC is the host computer, and the target board is the slave.
There are 14 command strings that the meter uses. These command strings are
defined in Table 61
TABLE 61: COMMAND STRINGS
Command Description Command
Test Connection 0x41
Total Data Request 0x42
Harmonic Content, Phase A 0x43
Harmonic Content, Phase B 0x44
Harmonic Content, Phase C 0x45
Total Harmonic Distortion 0x46
Energy 0x47
Stop Energy Measurement and Clear Energy Values 0x48
Harmonic Power 0x49
Write Calibration Values to Meter 0x62
Write Phase Lag Calibration Values to Meter 0x63
Write Power Calibration Values to Meter 0x64
Write Energy Pulse Configuration  Active/Apparent 0x65
Reset All Calibration Values 0x66
Write Energy Pulse Constant 0x67
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 52 © 2009 Microchip Technology Inc.
Variantlength frame structure is used and data communiate in bytes. The command
protocol structure is defined as following.
TABLE 62: TYPICAL PROTOTOL
• The START word has 2 bytes, which are 0x00, 0xFF ( PC to target board) or 0xFF,
0x00 (target board to PC)
• Command word is 1 byte which indicates the type of the command
• Data length word is 1 byte that indicates the length of data field
• The data field word has multiple byte(s) that varies with command types
• Checksum word is a single byte, whose content equals to the XOR value of all
bytes sent before it
• Stop word is 1 byte with the content of 0xE0
6.2 TEST CONNECTION COMMAND
This command is sent from the PC to the meter to setup and test the connection.
TABLE 63: PC TO METER (7 BYTES)
TABLE 64: METER RESPONSE (8 BYTES)
6.3 TOTAL DATA REQUEST
This is the main command retrieves all the calcuated data from the dsPIC33F. This
command gathers data from all 3 phases including total energy, power, and power
factor data.
TABLE 65: PC TO METER (7 BYTES)
TABLE 66: METER RESPONSE (104 BYTES)
START Command Data
Length Data Field Check Sum STOP
2 Bytes 1 Bytes 1 Byte N Bytes 1 Byte 1 Byte
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x41 0x00 0x00 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x42 0x02 0xA5, 0X5A XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x42 0x00 0x00 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x43 0x62 98 bytes XX 0xE0
Meter Communications Protocol
© 2009 Microchip Technology Inc. DS51723Apage 53
TABLE 67: METER RESPONSE, TOTAL REQUEST FRAME, DETAILED
DESCRIPTION
Data Field
Byte Name Value
1,2 Status See Definition Below
36 Frequency Float, 4 Bytes Total
710 Phase A Voltage Float, 4 Bytes Total
Phase B Voltage Float, 4 Bytes Total
Phase C Voltage Float, 4 Bytes Total
Phase A Current Float, 4 Bytes Total
Phase B Current Float, 4 Bytes Total
Phase C Current Float, 4 Bytes Total
Neutral Current Float, 4 Bytes Total
Active Power, Phase A Float, 4 Bytes Total
Reactive Power, Phase A Float, 4 Bytes Total
Apparent Power, Phase A Float, 4 Bytes Total
Power Factor, Phase A Float, 4 Bytes Total
Active Power, Phase B Float, 4 Bytes Total
Reactive Power, Phase B Float, 4 Bytes Total
Apparent Power, Phase B Float, 4 Bytes Total
Power Factor, Phase B Float, 4 Bytes Total
Active Power, Phase C Float, 4 Bytes Total
Reactive Power, Phase C Float, 4 Bytes Total
Apparent Power, Phase C Float, 4 Bytes Total
Power Factor, Phase C Float, 4 Bytes Total
Total Active Power Float, 4 Bytes Total
Total Reactive Power Float, 4 Bytes Total
Total Apparent Power Float, 4 Bytes Total
9498 Total Power Factor Float, 4 Bytes Total
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 54 © 2009 Microchip Technology Inc.
6.4 STATUS REGISTER
This register contains the gain register.
REGISTER 61: STATUS REGISTER
6.5 HARMONIC CONTENT COMMAND
TABLE 68: PC TO METER (7 BYTES)
TABLE 69: METER RESPONSE (134 BYTES)
R0 R0 R0 R0 R0 R0 R0 R0
CPO VPO PHC_S1 PHC_S0 PHB_S1 PHB_S0 PHA_S1 PHA_S0
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 7 CPO: Current Phase Order
1 = Problem Detected
0 =Normal
bit 6 VPO: Voltage Phase Order
1 = Problem Detected
0 =Normal
bit 5:4 PHC_S: Phase C Status
11 = High Votage
10 = No Input
01 = Low Voltage
00 = Normal
bit 3:2 PHB_S: Phase C Status
11 = High Votage
10 = No Input
01 = Low Voltage
00 = Normal
bit 1:0 PHA_S: Phase C Status
11 = High Votage
10 = No Input
01 = Low Voltage
00 = Normal
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x43 0x00 0x00 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x44 0x80 128 bytes XX 0xE0
Meter Communications Protocol
© 2009 Microchip Technology Inc. DS51723Apage 55
TABLE 610: HARMONIC ANALYSIS DETAILED DESCRIPTION
6.6 TOTAL HARMONIC DISTORTION (THD) COMMAND
TABLE 611: PC TO METER (7 BYTES)
TABLE 612: METER RESPONSE (29 BYTES)
TABLE 613: TOTAL HARMONIC DISTORTION DESCRIPTION
Data Field
Byte Description Value
1,2 Fundamential or 1st Harmonic, Voltage Content Unsigned Int, 2 bytes
3,4 2nd Harmonic, Voltage Content Unsigned Int, 2 bytes
556 331st Harmonic, Voltage Content Unsigned Int, 2 bytes
57,58 Total Voltage Harmonic Content (not including
Fundamental) Unsigned Int, 2 bytes, /
1000 * (100%)
59,60 Fundamential or 1st Harmonic, Current Content Unsigned Int, 2 bytes
61,62 2nd Harmonic, Current Content Unsigned Int, 2 bytes
63126 331st Harmonic, Current Content Unsigned Int, 2 bytes
127,128 Total Current Harmonic Content (not including
Fundamental) Unsigned Int, 2 bytes, /
1000 * (100%)
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x46 0x00 0x00 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x47 0x18 24 bytes XX 0xE0
Data Field
Byte Description Value
14 Total Harmonic Distortion of Phase A Voltage Float, 4 Bytes Total
58 Total Harmonic Distortion of Phase B Voltage Float, 4 Bytes Total
912 Total Harmonic Distortion of Phase C Voltage Float, 4 Bytes Total
1316 Total Harmonic Distortion of Phase A Current Float, 4 Bytes Total
1720 Total Harmonic Distortion of Phase B Current Float, 4 Bytes Total
2124 Total Harmonic Distortion of Phase C Current Float, 4 Bytes Total
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 56 © 2009 Microchip Technology Inc.
6.7 START ENERGY MEASUREMENT COMMAND
TABLE 614: PC TO METER (7 BYTES)
TABLE 615: METER RESPONSE (42 BYTES)
TABLE 616: TOTAL HARMONIC DISTORTION DESCRIPTION
6.8 STOP ENERGY MEASUREMENT COMMAND
TABLE 617: PC TO METER (7 BYTES)
TABLE 618: METER RESPONSE (7 BYTES)
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x47 0x00 0x00 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x48 0x24 36 bytes XX 0xE0
Data Field
Byte Description Value
14 First quadrant reactive energy Float, 4 Bytes Total
58 Second quadrant reactive energy Float, 4 Bytes Total
912 Third quadrant reactive energy Float, 4 Bytes Total
1316 Fouth quadrant reactive energy Float, 4 Bytes Total
1720 Forward Reactive energy Float, 4 Bytes Total
2124 Reverse Reactive Energy Float, 4 Bytes Total
2528 Forward Active Energy Float, 4 Bytes Total
2932 Reverse Active Energy Float, 4 Bytes Total
3336 Reverse Active Energy Float, 4 Bytes Total
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x48 0x00 0x00 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x49 0x00 0 bytes XX 0xE0
Meter Communications Protocol
© 2009 Microchip Technology Inc. DS51723Apage 57
6.9 HARMONIC POWER COMMAND
TABLE 619: PC TO METER (7 BYTES)
TABLE 620: METER RESPONSE (54 BYTES)
TABLE 621: HARMONIC POWER MEASUREMENTS
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x49 0x00 0x00 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x4A 0x30 48 bytes XX 0xE0
Data Field
Byte Description Value
14 Fundamental Active Power Of Phase A Float, 4 Bytes Total
58 Fundamental Reactive Power Of Phase A Float, 4 Bytes Total
912 Fundamental Active Power Of Phase B Float, 4 Bytes Total
1316 Fundamental Reactive Power Of Phase B Float, 4 Bytes Total
1720 Fundamental Active Power Of Phase C Float, 4 Bytes Total
2124 Fundamental Reactive Power Of Phase C Float, 4 Bytes Total
2528 Harmonic Active Power Of Phase A Float, 4 Bytes Total
2932 Harmonic Reactive Power Of Phase A Float, 4 Bytes Total
3336 Harmonic Active Power Of Phase B Float, 4 Bytes Total
3740 Harmonic Reactive Power Of Phase B Float, 4 Bytes Total
4144 Harmonic Active Power Of Phase C Float, 4 Bytes Total
4548 Harmonic Reactive Power Of Phase C Float, 4 Bytes Total
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 58 © 2009 Microchip Technology Inc.
6.10 CALIBRATE METER VOLTAGE/CURRENT COMMAND
TABLE 622: PC TO METER (7 BYTES)
TABLE 623: METER RESPONSE (7 BYTES)
TABLE 624: CALIBRATION OF GAIN AND OFFSET VALUES
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x63 7 0x07 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x64 0 0x00 XX 0xE0
Data Field
Byte Description Value
1 Phase Select 0x01 = Phase A
0x02 = Phase B
0x03 = Phase C
2 Range Select 0x01 = 10%
0x02 = 100%
3 Channel Select 0x00 = Current
0x01 = Voltage
47 Correction Factor (Error Being Calibrated Out) Float, 4 Bytes Total
Meter Communications Protocol
© 2009 Microchip Technology Inc. DS51723Apage 59
6.11 CALIBRATE PHASE LAG COMMAND
TABLE 625: PC TO METER (12 BYTES)
TABLE 626: METER RESPONSE (7 BYTES)
TABLE 627: CALIBRATION OF PHASE LAG
6.12 CALIBRATE APPARENT POWER COMMAND
TABLE 628: PC TO METER (12 BYTES)
TABLE 629: METER RESPONSE (7 BYTES)
TABLE 630: CALIBRATION OF POWER
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x63 6 0x06 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x64 0 0x00 XX 0xE0
Data Field
Byte Description Value
1 Phase Select 0x01 = Phase A
0x02 = Phase B
0x03 = Phase C
2 Range Select 17
36 Correction Factor (Error Being Calibrated Out) Float, 4 Bytes Total
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x64 6 0x06 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x65 0 0x00 XX 0xE0
Data Field
Byte Description Value
1 Phase Select 0x01 = Phase A
0x02 = Phase B
0x03 = Phase C
2 Current Range Select 17
36 Correction Factor (Error Being Calibrated Out) Float, 4 Bytes Total
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 60 © 2009 Microchip Technology Inc.
6.13 CALIBRATE ENERGY PULSE COMMAND
TABLE 631: PC TO METER (12 BYTES)
TABLE 632: METER RESPONSE (7 BYTES)
TABLE 633: CALIBRATION OF POWER
6.14 RESET ALL METER CALIBRATION VALUES COMMAND
TABLE 634: PC TO METER (12 BYTES)
TABLE 635: METER RESPONSE (7 BYTES)
TABLE 636: RESET METER OPTIONS
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x65 2 0x02 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x66 0 0x00 XX 0xE0
Data Field
Byte Description Value
1 Phase Select 0x01 = Phase A
0x02 = Phase B
0x03 = Phase C
2 Energy Output Mode 0x00 = Active Power
0x01 = Apparent Power
START Command Data
Length Data Field Check Sum STOP
0x00, 0xFF 0x66 4 0x04 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x67 0 0x00 XX 0xE0
Data Field
Byte Description Value
1 Command Type 0x55  Reset All
0xA1 = Reset
0xA2  Reset Power Calibration Only
0xA3  Reset Phase Calibration
2 Phase Select 0x01 = Phase A
0x02 = Phase B
0x03 = Phase C
3 Current Range Select
4 Reserved
Meter Communications Protocol
© 2009 Microchip Technology Inc. DS51723Apage 61
6.15 CALIBRATE METER CONSTANT (ENERGY PULSE OUTPUT CONSTANT)
TABLE 637: PC TO METER (9 BYTES)
TABLE 638: METER RESPONSE (7 BYTES)
TABLE 639: ENERGY CONSTANT OPTIONS OPTIONS
START Command Data
Length Data Field Check Sum STOP
0x00, 0xFF 0x67 2 0x02 XX 0xE0
START Command Data
Length Data Field Check Sum STOP
0xFF, 0x00 0x68 0 0x00 XX 0xE0
Data Field
Byte Description Value
12 Energy Constant Range of 10064000 (Decimal)
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 62 © 2009 Microchip Technology Inc.
NOTES:
6‘
MICROCHIP
M
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 63
Appendix A. Schematics and Layouts
A.1 INTRODUCTION
This appendix contains the following schematics and layouts for the MCP3909 /
dsPIC33F 3Phase Energy Meter Reference Design.
• Power Supply Board Schematic
• Main Board Schematic  Page 1
• Main Board Schematic  Page 2
• Power Supply Board  Assembly Drawing
• Power Supply Board  Composite Drawing
• Main Board  Assembly Drawing
• Main Board  Composite Drawing
A.2 SCHEMATICS AND PCB LAYOUT
FIGURE A1: LAYER ORDER
Top Layer
Bottom Layer
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 64 © 2009 Microchip Technology Inc.
FIGURE A2: POWER SUPPLY BOARD SCHEMATIC
1 2 34
A
B
C
D
4
321
D
C
B
ATitle
Number RevisionSize
A4
Date: 30Nov2007 Sheet of
File: X:\AIPD Eval Boards\10200011 thru 00020\10200018\PCB Files (Protel )\PCBR5\PM33_Drawn By:
R2
150k
R7
150k
R11
150k
1
JP5
1
JP4
1
JP1
three phase voltage input
N
T3 SPT204B
T1 SPT204B
T2 SPT204B
2R = Vour*Rin/(Kpt*Vin)
1
JP6
Power supply for 3phs power meter
2.01  1
N
N
PA
PB
PC
N
1
C
2
B
3
A
4G1 5
Vo1 6
G2 7
Vo2 8
T4
DB12CY
RV3RV1 RV2
A
1
B
2
C
3
N
4N5
C6
B7
A8
R5
COILS
12V
PC
C7
33N
R10
1K 1%
N
PC
PC
PC+
PB
PB+
PA
PA+
R12
0
PA+
PA
PB+
PB
PC+
PC
1
2
3
4
5
6
7
8
9
10
JP3
Header 10
R9
499K 1%
PB
C5
33N
PB
PA
C3
33N
PA
W1
Jumper
C4
0.1u
C1
0.1U
C6
0.1u
PA
PB
PC
N
N
N
N
PA
PB
PC
N
R8
499K 1%
R4
499K 1%
R3
499K 1%
R13
499K 1%
R14
499K 1%
R6
1K 1%
R1
1K 1%
N
W2
Jumper
W3
Jumper
1
2
3
JP6
Header 3
+C2
100uf
Schematics and Layouts
© 2009 Microchip Technology Inc. DS51723Apage 65
FIGURE A3: MAIN BOARD SCHEMATIC  PAGE 1
123456
A
B
C
D
6
54321
D
C
B
A
Title
Number RevisionSize
B
Date: 30Nov2007 Sheet of
File: X:\AIPD Eval Boards\10200011 thru 00020\10200018\PCB Files (Protel )\PCBR5\PM33_Drawn By:
Frontend of three Phase Power Meter Design
1.0
R113
100
R102
1K
R100
1K C101
1nf
C104
1nf
R112
100
R121
20
R101 1K
C102
1nf
R122
20
C103
1nf
R103 1K
R115 100
R106
1K
R104
1K C105
1nf
C108
1nf
R114
100
R123
20
R105 1K
C106
1nf
R124
20
C107
1nf
R107
R117
100
R110 1K
R108
1K C109
1nf
C112
1nf
R116
100
R125
20
R109 1K
C110
1nf
R126
20
C111
1nf
R111
1K
2R = Vour*Rin/(Kpt*Vin)
2R = Vout/(Kct*Iin)
4
2
6
8
T101
SCT220B
4
2
6
8
T102
SCT220B
4
2
6
8
T103
SCT220B
4
2
6
8
T100
SCT220B
Current_N
R128
470
R127
4.7K
C100
1nf
Neutral line current detection
3.3V C128
0.1uF
R130
4.7K 1%
R129
4.7K 1%
3.3V
PCV
PCV+
PCC+
PCC
PBV
PBV+
PBC+
PBC
PAV
PAV+
PAC+
PAC
Current_N
1.65V
C121
1uf
C123
1u
5V_IN
C122
AD_MCLR
5V
5V
5V
5V
5V
5V
C1260.1
C127
0.1
C117
C118
C119
C120
VCC
14
GND
7CLKOUT 8
X100
3.2768M Gain selection
G1 G0 Gain
0 0 1
0 1 2
1 0 8
1 1 16
+
C114
+
C113
+
C116
+
C115
+
C125
+
C124
DVDD
1
HPF
2
AVDD
3
NC
4
CH0+
5
CH0
6
CH1_
7
CH1+
8
MCLR
9
REFi/o
10
AGND
11
F2
12 F1 13
F0 14
G1 15
G0 16
OSC1 17
OSC2 18
NC 19
NEG 20
DGND 21
HFo 22
Fo1 23
Fo0 24
U102 MCP3909
DVDD
1
HPF
2
AVDD
3
NC
4
CH0+
5
CH0
6
CH1_
7
CH1+
8
MCLR
9
REFi/o
10
AGND
11
F2
12 F1 13
F0 14
G1 15
G0 16
OSC1 17
OSC2 18
NC 19
NEG 20
DGND 21
HFo 22
Fo1 23
Fo0 24
U103 MCP3909
DVDD
1
HPF
2
AVDD
3
NC
4
CH0+
5
CH0
6
CH1_
7
CH1+
8
MCLR
9
REFi/o
10
AGND
11
F2
12 F1 13
F0 14
G1 15
G0 16
OSC1 17
OSC2 18
NC 19
NEG 20
DGND 21
HFo 22
Fo1 23
Fo0 24
U104 MCP3909
R131
4.7K
R132
4.7K
R133
4.7K
R134
4.7K
R135
4.7K
R136
4.7K
G0A
G1A
G0B
G1B
G0C
G1C
PCC+
PCC
PCV
PCV+
AD MCLR
PBC+
PBC
PBV
PBV+
PAC+
PAC
PAV
PAV+
AD MCLR
GAIN
G0A
G1A
SDI
SCK
G0B
G1B
G0C
G1C
GAIN
CSC
CSB
CSA
3905 CS
SDO
SPI I/F
AD_CLK
REF_V REV_V
AD_CLK
21
Jemmey Huang
1
2
3
J6
1
2
3
J7
1
2
3
J8
FB3
500
FB2
500
AD_MCLR
FB1
500
R118
10
R119
10
R120
10
OutA
1
InA
2
InA+
3
Vss
4InB+ 5
InB 6
OutB 7
VDD 8
U101
MCP6002
CSC
SDI
SCK
SDO
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 66 © 2009 Microchip Technology Inc.
FIGURE A4: MAIN BOARD SCHEMATIC  PAGE 2
123456
A
B
C
D
6
54321
D
C
B
A
Title
Number RevisionSize
B
Date: 30Nov2007 Sheet of
File: X:\AIPD Eval Boards\10200011 thru 00020\10200018\PCB Files (Protel )\PCBR5\PM33Drawn By:
R313
510
C340
0.1uf
11
2
2
S301
SWPB
3.3V
3.3V
Jemmey Huang
Frontend of three Phase Power Meter Design
1.0
AD CLK = Fac * SampleRate * Kad
F = 50Hz * 64 * 256 = 819.2 KHz
F = 50Hz * 128 * 256 = 1638.4 KHz
* 3905 clk range 1M to 4M C328
1
2
3
4
5
6
J2
CON6
3.3V
C330
3.3V
C331
3.3V
C332
3.3V
C333
C334
R321
10k
ICSPDAT
ICSPCLK
MCLR
3.3V
C322
CAP
C336
0.1uF
+C337
100uf
5V
C323
CAP
C324
CAP
+C338
100uf
+C339
47uF
D301
LED
R316
470
A0
1
A1
2
A2
3
Vss
4SDA 5
SCL 6
WP 7
VCC 8
U309
24LC04B
3.3V
R311
1k
R312
1k
3.3V
C335
Vin
3Vout 2
Gnd
1
U306
MCP1700(3.3VSOT23)
1
2
J1
1
2
3
4
5
6
J3
C342
0.1
C341
0.1 C344
0.1
C343 0.1
C1+
1V+ 2
C1
3
C2
5
T2OUT 7
C2+
4V 6
R2IN 8
T1IN
11
T2IN
10
R1OUT
12
R2OUT
9R1IN 13
T1OUT 14
GND 15
VCC 16
U308
MAX232
3.3V
1
6
2
7
3
8
4
9
5
J5
DB9
U1RX/SDI1
U1TX/SDO1
5V_IN
SCL
SDA
C329
RG15
1
AN16/RC1
2
AN17/RC2
3
RG6
4
RG7
5
RG8
6
MCLR
7
SS2/RG9
8
Vss
9
Vdd
10
AN15/RB5
11
AN4/RB4
12
AN3/RB3
13
AN2/RB2
14
PGC3/RB1
15
PGD3/RB0
16
PGC1/RB6
17
PGD1/RB7
18
AVdd
19
AVss
20
AN8/RB8
21
AN9/RB9
22
AN10/RB10
23
AN11/RB11
24
Vss
25
Vdd
26
AN12/RB12
27
AN13/RB13
28
AN14/RB14
29
AN15/RB15
30
RF4
31
RF5
32
RF3 33
RF2 34
INT0/RF6 35
SDA1/RG3 36
SCL1/RG2 37
Vdd 38
OSC1/RC12 39
OSC2/RC15 40
Vss 41
RD8 42
RD9 43
RD10 44
IC4/RD11 45
RD0 46
RC13 47
RC14 48
RD1 49
RD2 50
RD3 51
RD4 52
RD5 53
RD6 54
RD7 55
Vddcore 56
Vdd 57
RF0 58
RF1 59
RG1 60
RG0 61
RG14 62
RG12 63
RG13 64
U307
DSPIC33FJ128GP706
OSC1
OSC2
MCLR
ICSPDAT
ICSPCLK
C345
C346
X303
3.3V
3.3V
GND
GND
GND
3.3V
3.3V
GND
3.3V
R318 100
R317 100
R319 100
D303 LED
R314
470 3.3V
CSA
G0A
G1A
SCK
SDI
SDO
CSB
G0B
G1B
CSC
G0C
G1C
SPI I/F
CSA
G0A
G1A
CSB
G0B
G1B
CSC
G0C
G1C
GAIN
3909 CS
SCL
SDA
U1RX(SDI1)
U1TX(SDO1)
Current_N Current_N
SDO
3.3V
REF_V
SCK1
SCK2
SDO2
SDI2
U1RX/SDI1
U1TX/SDO1
SPI1_SCK
1
2
3
4
J4
L302
INDUCTOR
L301
INDUCTOR
R303
1K
C303
0.1uf
U303
TLP5211
R302
1K
C302
0.1uf
U302
TLP5211
R301
1K
C301
0.1uf
U301
TLP5211
D302 LED
R310
470
AD_CLK AD_CLK
Output Pulse
1: active power 
2: active power +
3: Reactive power 
4: Reactive power +
5: TBD 
6: TBD +
22
AD_MCLR
MCLR
R309
100
R308
100
R307
100
R306
100
Vin
2Vout 3
VSS
1
U305
MCP1701(5VSOT89)
Schematics and Layouts
© 2009 Microchip Technology Inc. DS51723Apage 67
FIGURE A5: POWER SUPPLY BOARD LAYOUT  ASSEMBLY DRAWING
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 68 © 2009 Microchip Technology Inc.
FIGURE A6: POWER SUPPLY BOARD LAYOUT  COMPOSITE DRAWING
O
on
 O .'.'.'.'. O
o o —III\IIIIIHIIII\— .. .
.. " ' ' ':. ...:.. '' :' ‘
" I o ::
= o c
: : :IIIIIIIIIIII : : : I .
: :: Inmmm ' ::: mmmm '
E :: llll .
: _ _ _ II Illl .
O I ..' I O
.0 . '0 . .0 . .0
0. g I. o O. . I.
O O O
Schematics and Layouts
© 2009 Microchip Technology Inc. DS51723Apage 69
FIGURE A7: MAIN BOARD LAYOUT  ASSEMBLY DRAWING
2111“
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 70 © 2009 Microchip Technology Inc.
FIGURE A8: MAIN BOARD LAYOUT  COMPOSITE DRAWING
6‘
MICROCHIP
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 71
Appendix B. Bill Of Materials (BOM)
TABLE B1: BILL OF MATERIALS  POWER SUPPLY (BOTTOM BOARD)
Qty Reference Description Manufacturer Part Number
3 C1, C2, C3 CAP 0.1UF 305VAC EMI SUPPRESS EPCOS Inc B32922A2104M
1 C4 CAP 470UF 25V ALUM LYTIC RADIAL Panasonic®  ECG ECA1EM471
3 C5, C6, C7 DO NOT POPULATE — —
3 J4, J5, J6 CONN HEADER 3POS .100 VERT TIN Molex®/Waldom
Electronics Corp 22232031
4 JP1, JP2, JP3,
JP4 HOOKUP WIRE 18AWG STRAND RED Alpha Wire
Company 3055 RD005
4 JP1, JP2, JP3,
JP4 CONN RING TERM #6 1822AWG Molex/Waldom Elec
tronics Corp 190700040
1 JP6 CONN HEADER 3POS .156 VERT TIN Molex/Waldom
Electronics Corp 26481035
1 JP6 CONN HOUSING 3POS .156 W/O RAMP Molex/Waldom
Electronics Corp 09507031
3 JP6 CONN TERM FEMALE 1824AWG TIN Molex/Waldom
Electronics Corp 08500105
1 PCB RoHS Compliant Bare PCB, dsPIC33F
and MCP3909 3Phase Energy Meter
(Power) Bottom Bd.
Microchip
Technology Inc. 10400158
3 P4, P5, P6 CONN HOUS 3POS .100 W/RAMP/RIB
(Connects to Above) Molex/Waldom
Electronics Corp 22013037
9 P4, P5, P6 CRIMP TERM FEMALE 2230AWG TIN Molex/Waldom
Electronics Corp 08650805
1 R1 Part of T1 Sanki —
1 R2 DO NOT POPULATE — —
6 R3, R4, R5, R6,
R7, R8 DO NOT POPULATE — —
3 R9, R10, R11 RES 150K OHM METAL FILM .50W 1% Vishay®/Phoenix
Passive
Components
5033ED150K0F12AF5
3 R12, R13, R14 DO NOT POPULATE — —
3 RV1, RV2, RV3 VARISTOR 300V RMS 14MM RADIAL EPCOS Inc S14K300E2
1 T1 3P ACDC converter, 220V  12V/5V Sanki DB12CY220
3 T2, T3, T4 2mA/2mA Current transformer Xinge SPT204
3 W1, W2, W3 DO NOT POPULATE — —
Note 1: The components listed in this Bill of Materials are representative of the PCB assembly. The released BOM
used in manufacturing uses all RoHScompliant components.
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 72 © 2009 Microchip Technology Inc.
TABLE B2: BILL OF MATERIALS  TOP BOARD
Qty Reference Description Manufacturer Part Number
13 C100, C101, C102,
C103, C104, C105,
C106, C107, C108,
C109, C110, C111,
C112
CAP 1000PF 50V CERAMIC X7R
0805 Kemet® Electronics
Corp C0805C102K5RACTU
6 C113, C114, C115,
C116, C124, C125 CAP CER 10UF 16V X7R 1206 Murata Electronics®
North America GRM31CR71C106KAC7L
26 C117, C118, C119,
C120, C126, C127,
C128, C301, C302,
C303, C322, C323,
C324, C328, C330,
C331, C332, C333,
C334, C335, C336,
C340, C341, C342,
C343, C344
CAP .1UF 25V CERAMIC X7R 0805 Panasonic®  ECG ECJ2VB1E104K
4 C121, C122, C123,
C329 CAP 1.0UF 10V CERAMIC X7R 0805 Kemet Electronics
Corp C0805C105K8RACTU
3 C337, C338, C339 CAP 470UF 25V ALUM LYTIC
RADIAL Panasonic  ECG ECA1EM471
2 C345, C346 CAP 22PF 50V CERM CHIP 0805
SMD Panasonic  ECG ECJ2VC1H220J
3 6" Wire Thru CT HOOKUP WIRE 16AWG STRAND
RED Alpha Wire
Company 3057 RD005
6 CT Wire terminals CONN RING TERM #6 1822AWG Molex/Waldom
Electronics Corp 190700040
1 D301 LED 3MM ALGAAS RED CLEAR LITEON INC LTL4266N
1 D302 LED 3MM GREEN CLEAR LITEON INC LTL4236N
1 D303 LED 3MM YELLOW CLEAR LITEON INC LTL4256N
3 FB1, FB2, FB3 FERRITE SMT luying STBL2012121
1 J1 CONN HOUSING 3POS .156 W/O
RAMP Molex/Waldom
Electronics Corp 09507031
1 J1 CONN TERM FEMALE 1824AWG
TIN Molex/Waldom
Electronics Corp 08500105
1 J1 HOOKUP WIRE 22AWG STRAND
RED Alpha Wire
Company 3051 RD005
1 J1 HOOKUP WIRE 22AWG STRAND
BLACK Alpha Wire
Company 3051 BK005
1 J2 CONN MOD JACK 66 VERT PCB
50AU Tyco
Electronics/Amp 55202583
1 J3 CONN HEADER 6POS .100 VERT
TIN Molex/Waldom
Electronics Corp 22272061
1 J4 CONN HEADER 4POS .100 VERT
TIN Molex/Waldom
Electronics Corp 22272041
1 J5 DB9 Female vertical Tyco
Electronics/Amp 7470912
3 J6,J7 & J8 CONN HOUS 3POS .100
W/RAMP/RIB (Connects to J4,J5 & J6
of Lower Board)
——
9 J6,J7 & J8 CRIMP TERM FEMALE 2230AWG
TIN Molex/Waldom
Electronics Corp 08650805
Note 1: The components listed in this Bill of Materials are representative of the PCB assembly. The released BOM
used in manufacturing uses all RoHScompliant components.
Bill Of Materials (BOM)
© 2009 Microchip Technology Inc. DS51723Apage 73
3 J6,J7 & J8 HOOKUP WIRE 22AWG STRAND
GREEN Alpha Wire
Company 3051 GR005
3 J6,J7 & J8 HOOKUP WIRE 22AWG STRAND
RED Alpha Wire
Company 3051 RD005
3 J6,J7 & J8 HOOKUP WIRE 22AWG STRAND
BLACK Alpha Wire
Company 3051 BK005
2 L301, L302 60ohm bead Jones B60
1 PCB RoHS Compliant Bare PCB,
dsPIC33F and MCP3909 3Phase
Energy Meter (Power) Bottom Bd.
— 10400159
17 R100, R101, R102,
R103, R104, R105,
R106, R107, R108,
R109, R110, R111,
R301, R302, R303,
R311, R312
RES 1.00K OHM 1/8W 1% 0805 SMD Panasonic  ECG ERJ6ENF1001V
12 R112, R113, R114,
R115, R116, R117,
R307, R308, R309,
R317, R318, R319
RES 100 OHM 1/8W 1% 0805 SMD Panasonic  ECG ERJ6ENF1000V
3 R118, R119, R120 RES 10.0 OHM 1/8W 1% 0805 SMD Panasonic  ECG ERJ6ENF10R0V
6 R121, R122, R123,
R124, R125, R126 RES 20.0 OHM 1/8W 1% 0805 SMD Panasonic  ECG ERJ6ENF20R0V
7 R127, R131, R132,
R133, R134, R135,
R136
RES 4.7K OHM 1/8W 5% 0805 SMD Panasonic  ECG ERJ6GEYJ472V
4 R128, R310, R314,
R316 RES 470 OHM 1/8W 5% 0805 SMD Panasonic  ECG ERJ6GEYJ471V
2 R129, R130 RES 4.70K OHM 1/8W 1% 0805 SMD Yageo Corporation 9C08052A4701FKHFT
1 R313 RES 510 OHM 1/8W 5% 0805 SMD Panasonic  ECG ERJ6GEYJ511V
1 R321 RES 10.0K OHM 1/8W 1% 0805 SMD Panasonic  ECG ERJ6ENF1002V
1 S301 SWITCH TACT 6MM MOMENTARY
250GF ESwitch TL1105BF250Q
1 X100 3.2768Mhz Crystal Koan DIP83.2768M
1 X303 7.3728Mhz Crystal Koan HC49SSMD7.3728M
1 U305 2uA Low Dropout Positive Voltage
Regulator Microchip
Technology Inc MCP1701T5002I/MB
1 U306 Low Quiescent Current LDO Microchip
Technology Inc MCP1700T3302E/TT
1 U307 HighPerformance, 16bit Digital Sig
nal Controllers Microchip
Technology Inc dsPIC33FJ128GP206
1 U308 IC DRVR/RCVR MULTCH RS232
16SOIC Texas Instruments MAX3232CDR
1 U309 4K I2C™ Serial EEPROM Microchip
Technology Inc 24LC04BE/SN
3 U102, U103 U104 Energy Metering IC with SPI Interface
and Active Power Pulse Output Microchip
Technology Inc MCP3909I/SS
1 U101 1MHz, Low Power OpAmp Microchip
Technology Inc MCP6002I/SN
3 T101 T102, T103 5A/5mA Current transformer Xinge SCT954F
1 T100 " DO NOT POPULATE — —
TABLE B2: BILL OF MATERIALS  TOP BOARD
Qty Reference Description Manufacturer Part Number
Note 1: The components listed in this Bill of Materials are representative of the PCB assembly. The released BOM
used in manufacturing uses all RoHScompliant components.
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 74 © 2009 Microchip Technology Inc.
NOTES:
6‘
MICROCHIP
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 75
Appendix C. Power Calculation Theory
C.1 OVERVIEW
This MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design is unique in that
all calculations are done in the frequency domain. This is easily realized using the DSP
engine core of the advanced 16bit MCU, the dsPIC33F. In addition to performing direct
fourier transforms (DFTs) on all the input channel measurements, an additional
firmware function is included, quasisynchronous sampling.
C.2 SYNCHRONOUS SAMPLING AND QUASISYNCHRONOUS SAMPLING
The fundamentals of quasisynchronous sampling and corresponding methods for
measuring AC electrical parameters are discussed in this section. Typically, a
synchronous sampling method is used for measuring electrical parameters. The
method requires synchronization between sampling intervals and power grid
frequency. For these types of meter designs, an external hardware PLL circuit is used
to track power grid frequency, and the clock of the MCP3909 device is automatically
updated to change the sampling frequency. Since the PLL output frequency drops
behind the power grid frequency, a synchronous error exists in the system, and fully
synchronous sampling is hard to achieve. In addition, as nonsine waves exist in the
power grid, which may affect zerocrossing detection, when such conditions worsen, it
may cause PLL failure, preventing the system from working normally.
For the MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design presented
here, the dsPIC33F performs additionall calculations that eliminates the need for a
costly external PLL circuit. This quasisynchronous sampling method has an
advantage in the engineering practice, which actually is periodic sampling, without
synchronizing with the power grid frequency. Therefore, the zerocrossing detection
and PLL circuit can be reduced to lower the hardware complexity. The tradeoff is the
increased software requirements of the system, easily realized using the powerful
dsPIC33F.
For DFT or FFT harmonic analysis of periodic signals, a Fourier transform may only
bring accurate spectrum analysis when the sampling points satisfy N > 2M for each line
cycle and strict synchronous sampling is realized. (Where M is the maximal harmonic
order of periodic signals, and N is the number of samples per line cycle).
Otherwise, if N ≤ 2M, it will cause spectrum aliasing. In addition, if strict synchronous
sampling cannot be realized, spectralleakage will occur (the Hurdle Effect). However,
in the quasisynchronous sampling method emplyed here, strict synchronization
between sampling intervals and the period of sampled signal is not guaranteed but is
overcome through postprocessing and iteration of the collected data. To reduce the
error caused by this problem and to obtain better accuracy when measuring the
fundamental and harmonics of higher orders, an increase in the number of iterations
when processing data to improve accuracy is performed.
The iterations can effectively reduce the impact of synchronization error over the mea
surement accuracy, and is one of the methods to realize accurate measurement of the
frequency and harmonics under steadystate conditions.
faaﬂ
ayﬁa
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 76 © 2009 Microchip Technology Inc.
FIGURE C1: Quasi Synchronous Sampline.
C.2.1 Basic Idea of QuasiSynchronous Sampling
Assuming that the average of a periodic signal in one cycle is g(t),
EQUATION C1:
Make t = x/
ω
, then,
EQUATION C2:
where f(x) = g(x/
ω
), and the period is 2π.
If the entire period sampling cannot be realized while a sampling frequency deviation
Δ exists, then:
EQUATION C3:
We have:
EQUATION C4:
The value of F1(α) is a function of
α
and also a function with 2π as its perod. The
nonsynchronous sampling error E = f(x) F1(α).
As F1(α) is function with 2
π
as its period, its value may be averaged through integration
within the range of 02
π
, and it can be deduced that f(x) = F1(α).
V
t
Ts
T≠N*Ts
gt() 1
T
g
0
T
∫t()dt
⋅
1
T
g
TO
TO T+()
∫t()dt
⋅
==
gt() 1
2
π
 fx()xd
0
2
π
∫
⋅
fx()==
fx() 1
2
πΔ
+
fx()x
d
0
2
πΔ
+()
∫
⋅
1
2
πΔ
+
fx()x
d
α
α
2
πΔ
++()
∫
⋅≠≠
F1
α
() 1
2
πΔ
+
fx()xd
α
α
2
πΔ
++()
∫
⋅
=
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 77
Assuming that the integral starts at β, then:
EQUATION C5:
Likewise, as strict integration cannot be realized in the entire cycle, so:
EQUATION C6:
Similarly, the integral value of above equation is related to β with 2π as its period, let’s
denote it as F2(β). If it won't confuse people, we'll write F1(α) and F2(β) as F1(x) and
F2(x), and a recurrence formula can be obtained as the following:
EQUATION C7:
It can be proved that,
EQUATION C8:
In practical applications, it is necessary to sample the continuous analog signals and
process the data obtained with discrete algorithms. The quasisynchronous recursive
process mentioned above can be expressed as follows:
For Equation C4, the integral interval [x0,x
0+nx(2π + Δ)] whose width is nx(2π+Δ)
can be divided equally into nxN sections, which results in nxN+1 sampled data,
f(xi), (i=0,1,...,nxN), and we can iterate as follows:
fx() F1
α
() 1
2
π
 F1
α
()
α
d
β
β
2
π
+()
∫
⋅
==
fx() F1
α
() 1
2
πΔ
+
F1
α
()
α
d
β
β
2
πΔ
++()
∫
⋅≠
=
Fn
α
() 1
2
πΔ
+
Fn1–x()xd
x
x2
πΔ
++()
∫
⋅
=
Fn
α
()
n
∞
–
lim f x()=
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 78 © 2009 Microchip Technology Inc.
First iteration:
…
Second iteration:
…
F011
ρ
i
i0=
N
∑

ρ
i
i0=
N
∑fx
i
()
⋅⋅
=
F111
ρi
i1=
N1+
∑
ρi
i1=
N1+
∑fx
i
()⋅⋅=
F1n1–()N
×
1
ρ
i
in1–()N
×
=
Nn
×
∑

ρ
ifx
i
()
⋅
in1–()N
×
=
Nn
×
∑
⋅
=
F021
ρ
i
i0=
N
∑

ρ
iFi1
⋅
i0=
N
∑
⋅
=
F121
ρ
i
i1=
N1+
∑

ρ
i
i1=
N1+
∑Fi1
⋅⋅
=
F2n2–()N
×
1
ρ
i
in2–()N
×
=
Nn1–()
×
∑

ρ
i
in2–()N
×
=
Nn1–()
×
∑Fi1
⋅⋅
=
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 79
Third iteration:
…
…
F031
ρ
i
i0=
N
∑

ρ
i
i0=
N
∑Fi2
⋅⋅
=
F131
ρ
i
i1=
N1+
∑

ρ
i
i1=
N1+
∑Fi2
⋅⋅
=
F3n3–()N
×
1
ρ
i
in3–()N
×
=
Nn2–()
×
∑

ρ
i
in3–()N
×
=
Nn2–()
×
∑Fi2
⋅⋅
=
\ 
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 80 © 2009 Microchip Technology Inc.
Nth iteration:
Where ρi is the weight coefficient which is decided by the digital quadrature formula.
Complex rectangular quadrature algorithm or complex trapezoidal quadrature
algorithm is usually used in quasisynchronous sampling.
Figure C2 shows a 3cycle interative process.
FIGURE C2: 3Cycle Iterative Process.
In practical applicatons, a frequency offset Δ is usually small, and good results may
usually be obtained through 35 iterations.
As mentioned above, the iterative process will result in a group of weight coefficients
ηi, called weight coefficients of quasisynchronous algorithm, they may be deduced
from the numeric quadrature formula. The relationship between the iterative result and
original data is shown in Equation C9.
EQUATION C9:
F0n1
ρ
i
i0=
N
∑

ρ
i
i0=
N
∑Fin1–
⋅⋅
=
f0
F01
F02
F03
Original data
First Iteration
Second Iteration
Third Iteration
F12F22...... FN2
F11F21...... FN1F1N+1 F1N+2 ...... F12N
f1f2...... fNfN+1 fN+2 ...... f2N f2N+1 f2N+2 ...... f3N
F0n1
η
i
i0=
nN
×
∑

η
ifx
i
()
⋅
i0=
nN
×
∑
⋅
=
1
Nn

η
ifx
i
()
⋅
i0=
nN
×
∑
⋅
=
Rifx
i
()
⋅
i0=
nN
×
∑
=
72
I]
DEM
I
DEIZ
\
DDS
\
[IDA
I
DDS
DUE
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 81
Where:
EQUATION C10:
Equation C10 is called the quasisynchronous window function. After determining the
sampling points, the number of iterations and numerical quadrature method, the
coefficients of quasisynchronous window function will become definite, and a
quasisynchronous window function arrays may be established in advance.
Using the quasisynchronous window function to carry out the weighted process of the
original data is equivalent to carrying out data synchronization one time, and the
algorithm realization is also very simple that only a multiplication of the original data and
quasisynchronous window function arrays is required. After processing, the new
periodic signal will have the same period and frequency components as the original
signal, and the synchronization error of the new signal becomes smaller.
Figure C3 is a schematic of the quasisynchronous window function characteristics in
the time domain and data processing. In Figure C3, the red curve is the characteristic
of the window function, and the blue curve is input signal, and the green curve is the
output signal.
FIGURE C3: QuasiSynchronous Window Function Characteristics Curve and Data
Processing.
Ri1
Nn

η
i
⋅
=
（
i = 0 ~ n x N
）
Amplitude
Sampling point (1193) Time 3.2 ksps
Window function
Raw data
Data processed
r
A“, n
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 82 © 2009 Microchip Technology Inc.
C.3 THE HARMONIC ANALYSIS ALGORITHM OF QUASISYNCHRONOUS
SAMPLING
Periodic signal can be expressed as trigonometric Fourier series or exponential Fourier
series. A periodic signal with a period of T can be expressed as :
EQUATION C11:
where:
EQUATION C12:
EQUATION C13:
or as:
EQUATION C14:
where the relationship between ak, bk，ck and ϕk is:
EQUATION C15:
EQUATION C16:
EQUATION C17:
ft()
α
0
2

α
kk
ω
t
⋅⋅
()cos
β
k
ω
t
⋅⋅
()cos+()
k1=
∞
∑
+=
ak2
T
ft()
0
T
∫k
ω
t
⋅⋅
()dtcos
⋅⋅
=
bk2
T
ft()
0
T
∫k
ω
t
⋅⋅
()sin dt
⋅⋅
=
ft() a0ckk
ω
t
ϕ
k
+
⋅⋅
()sin
k1=
∞
∑
+=
ckak
2bk
2
+=
ϕ
k
ak
bk
atan=
akck
ϕ
k
sin=
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 83
EQUATION C18:
Make g(t) = f(t) • cos(K•ω•t), it can be proved that g(t) is also a periondic function with T
as its period. Averaging g(t) in the range of [0 ~ T] results in:
EQUATION C19:
So ak = 2 × g(t). Therefore, ak can be obtained if only g(t) can be calculated.
EQUATION C20:
EQUATION C21:
Where N, n and ηi are constants. The equation may therefore be written as:
EQUATION C22:
EQUATION C23:
Where:
EQUATION C24:
bkck
ϕ
k
cos=
gt() 1
T
ft()
0
T
∫k
ω
t
⋅⋅
()dtcos
⋅⋅
=
ak2g t() 2
Nn

η
igi
⋅
i0=
nN
×
∑
⋅
==
2
Nn
 ηifik2π
N
 i⋅⋅
⎝⎠
⎛⎞
cos⋅⋅
i0=
nN×
∑
⋅=
bk2
Nn

η
ifik2
π
N
 i
⋅⋅
⎝⎠
⎛⎞
sin
⋅⋅
i0=
nN
×
∑
⋅
=
akIifik2
π
N
 i
⋅⋅
⎝⎠
⎛⎞
cos
⋅⋅
i0=
nN
×
∑
=
bkIifik2
π
N
 i
⋅⋅
⎝⎠
⎛⎞
sin
⋅⋅
i0=
nN
×
∑
=
Ii2
Nn

η
1R12
×
=
⋅
= i 0nN
×∼
=()
1+
24
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 84 © 2009 Microchip Technology Inc.
C.4 MEASURING THE VOLTAGE/CURRENT RMS VALUE AND POWER USING
QUASISYNCHRONOUS SAMPLING ALGORITHM
From Equation C11, a periodic voltage can be expressed as:
EQUATION C25:
So the voltage fundamental and the voltage of each harmonic can be expressed as:
EQUATION C26:
From Equation C25, the fundamental voltage and voltage of each harmonic can also
be expressed as:
EQUATION C27:
Where:
EQUATION C28:
EQUATION C29:
The voltage RMS value of each harmonic, then can be expressed as shown in
Equation C31 with its initial phase angle shown in Equation C29.
EQUATION C30:
Ut() Ua0
2
u
ak k
ω
t
⋅⋅
()cos ubk k
ω
t
⋅⋅
()sin+()
k1=
∞
∑
+=
Ukt() uak k
ω
t
⋅⋅
()ukk
ω
t
⋅⋅
()sin+cos=
Ukt() uck k
ω
t
⋅⋅ ϕ
uk
+()sin=
uck uak2ubk2
+=
ϕ
uk
uak
ubk
atan=
Uk1
2
uck
uak2ubk2
+
2

=
⋅
=
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 85
The relationship between uak, ubk and Uk can be expressed as:
EQUATION C31:
EQUATION C32:
Total effective voltage can be expressed as:
EQUATION C33:
Similarly, the effective values and initial phase angles of fundamental current and
current of each other harmonic can be expressed as:
EQUATION C34:
EQUATION C35:
The relationship between iak, ibk and Ik can be expressed as:
EQUATION C36:
EQUATION C37:
Total current RMS can be expressed as:
EQUATION C38:
uak 2U
k
ϕ
uk
sin
⋅⋅
=
ubk 2U
k
ϕ
uk
cos
⋅⋅
=
Utotal Uk2
k0=
∞
∑
=
Ik1
2
ick
⋅
iak2ibk2
+
2

==
ϕ
ik
iak
ibk
atan=
iak 2I
k
ϕ
ik
sin
⋅⋅
=
ibk 2I
k
ϕ
ik
cos
⋅⋅
=
Itotal Ik2
k0=
∞
∑
=
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 86 © 2009 Microchip Technology Inc.
According to the definition of power measurement, the active power and reactive power
of the fundamental and each other harmonic can be expressed as:
EQUATION C39:
EQUATION C40:
Substituting Equation C31, C32, C33 and C37 into Equation C39 and C40, the
power of each harmonic component can be obtained with the following:
EQUATION C41:
EQUATION C42:
Total active power and reactive power can be expressed as:
EQUATION C43:
EQUATION C44:
PkUkIk
ϕ
uk
ϕ
ik
–()cos=
1
2
UkIk
⋅ϕ
uk
sin
ϕ
ik
sin
ϕ
uk
cos
ϕ
ik
cos+()=
QkUkIk
ϕ
uk
ϕ
ik
–()sin=
1
2
UkIk
⋅ϕ
uk
sin
ϕ
ik
cos
ϕ
uk
cos
ϕ
ik
sin–()=
Pk1
2
uakiak ubkiik
+()
⋅
=
Qk1
2
uakiak ubkiik
–()
⋅
=
Ptotal Pk
k0=
∞
∑
=
Qtotal Qk
k0=
∞
∑
=
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 87
C.5 MEASURING FREQUENCY
There are many ways to measure frequency, with the most common being counting the
signal cycle. In this method, a counter increments each time a zerocrossing is
detected. Based on the counts, the width of a cycle can be measured. If the zerocross
ing is accurate and the counter precision is high enough, cycle counting can be a
simple and practical method. But if the input signal has large harmonic components,
causing distortion around zerocrossing, then this approach may produce large errors.
Another method is to analyze and process the sampled data and calculate the frequen
cies. Analysis may be carried out in time domain, such as digital differential ND and
interpolation method; or may be carried out in frequency domain after DFT transforma
tion, such as gravity center method, spectrum zoom method and phase difference
method, among which the phase difference method is the most common one. It is not
sensitive to signal distortion around zerocrossing points.
The basic idea of the phase difference method is: if the rough range of tobemeasured
signal frequency is known, then we may assume a frequency that is close to the actual
frequency and then acquire an array of samples based on the assumed frequency. In
the sampled data, the phase of the 1st cycle and the subsequent Nth cycle are meau
red and their difference may be calculated. Then the phase difference may be used to
calculate the difference between the actual freqency and the assumed frequence, thus
figuring out the actual frequency.
If the frequency f0 to be measured is known to be a definite value f, i.e., f0=f+Δf,
Δf<< f, then from Equation C27, the fundamental signal can be expressed as:
EQUATION C45:
If:
EQUATION C46:
EQUATION C47:
EQUATION C48:
U1t() uc1
ω
t
ϕ
u1
+
⋅
()sin uc1 2
π
f0t
ϕ
u1
+()sin==
T1
f
=
ua2
T
U1t()
ω
t()cos td
0
T
∫
⋅
=
2
T
uc1 2
π
f0t
ϕ
u1
+()2
π
ft()cossin td
0
T
∫
⋅
=
ub2
T
U1t()
ω
t()sin td
0
T
∫
⋅
=
2
T
uc1 2
π
f0t
ϕ
u1
+()2
π
ft()sinsin td
0
T
∫
⋅
=
4PM
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 88 © 2009 Microchip Technology Inc.
We get:
EQUATION C49:
EQUATION C50:
As Δf << f, from Equation C49 and C50, we have:
EQUATION C51:
Therefore,
EQUATION C52:
Assuming that the signal's initial phase angle measured in the 1st cycle is
ϕ
1 and in
the Nth is
ϕ
N, then the difference between actual frequency and the assumed
frequency is:
EQUATION C53:
ua
2uc1
T

f
Δ
f+()
ϕ
u1
()sin
πΔ
f
f

⎝⎠
⎛⎞
sin
⋅⋅
π
2f
Δ
f+()
Δ
f
⋅⋅

⋅
=
ub
2uc1
T

f
ϕ
u1
()cos
πΔ
f
f

⎝⎠
⎛⎞
sin
⋅⋅
π
2f
Δ
f+()
Δ
f
⋅⋅

⋅
=
ua
ub

ϕ
u1
()sin
ϕ
u1
()cos

≈
⎪
⎪
⎪
⎪
⎪
⎪
⎩
⎪
⎪
⎪
⎪
⎪
⎪
⎨
⎧
><+
<>+
>>
<=
>=
≈
−
−
−
)0,0(,2)(
)0,0(,)(
)0,0(),(
)0,0(,
2
3
)0,0(,
2
1
1
1
1
ab
b
a
ab
b
a
ab
b
a
ab
ab
u
uu
u
u
tg
uu
u
u
tg
uu
u
u
tg
uu
uu
π
π
π
π
ϕ
⎪
⎪
⎪
⎩
⎪
⎪
⎪
⎨
⎧
>−
⋅
⋅−−
−<−
⋅
⋅+−
<−
⋅
⋅−
≈Δ
)(,
2
)2(
)(,
2
)2(
)(,
2
)(
1
1
1
1
1
1
πϕϕ
π
πϕϕ
πϕϕ
π
πϕϕ
πϕϕ
π
ϕϕ
N
N
N
N
N
N
N
f
N
f
N
f
f
Error (%)
m
m
r
7 Vollagi
7 Acme Puwer
Peaclrve Power
Currem
705
475
AB
485 49 495 5a 505 51 515 52 525
Frequency (HZ) @ 3 2Ksps
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 89
C.6 IMPROVING MEASUREMENT PRECISION OF QUASISYNCHRONOUS
SAMPLING ALGORITHM
When using the quasisynchronous sampling method for harmonic analysis and
calculation of power as well as voltage and current, strict restrictions apply for the
algorithm and compensation, (i.e., the frequency offset must not exceed 1% of the
central frequency). Precision of the result increases as the frequency offset gets less.
Measurement accuracy is not guaranteed, if this condition can not be met. Figure C4
shows the quasisynchronization algorithm using 3 iterations with input signal ranging
from 47.5 Hz to 52.5 Hz. The algorithm is for calculating the active power, the reactive
power and the relative error of current and voltage. Figure C4 shows that the algorithm
works well when the frequency falls in the range of 47.5 Hz to 52.5 Hz. As the
frequency deviates from the range, the error increases significantly. Therefore, the
algorithm needs to be improved to fit into more applications with a more relaxed
restriction.
FIGURE C4: Quasisync Algorithm Error Analysis of 3 Iterations.
The quasisync sampling algorithm has relative high accuracy in frequency measure
ment and the error can be less than 0.005 Hz. If the frequency range to be measured
can be segmented to make the frequency input closest to the multiple of cycle point,
and processed using appropriate quasisync window function and sine/cosine tale,
then the algorithm can be used for a much wider range of frequency .
Figure C5 is the error analysis of the improved 3iteration quasisynchronous
algorithm at 3.2 ksps. It shows that the relative error for each result can be well
controlled when the frequency of the input signal falls in the range of 47.5 Hz to
52.5 Hz.
Figure C5 clearly shows that the relative errors of the current, voltage, active power
and reactive power in the entire frequency range are less than 0.08%. Also, when the
input frequency is around the multiple of cycle frequencies (52.459 Hz, 51.613 Hz,
50.794 Hz, 50.0 Hz, 49.231 Hz, 48.485 Hz and 47.761 Hz), the calculateion error is
DUB
nun \Ilun 2nd‘3vd harmonlc 20%
W‘s“ 151 has: mama] 3p.
D 07 Current _
Am: inev
n 05 Reactwe Pow _
Frequency
a
o
m
DUB ,
Ermr m) 3 ZKSps
1:
a
b
002 
001
D
475 43 435 49 495 5D 5u5 51 515 52 525
Fvequency (HZ)
x m
15 ‘ ‘ ‘ ‘ ‘ ‘ ‘
Vnhage
5mm sandman 2nd31dhavmnmc=1ﬂ%
“WWW" 15H] ase advancem 25 ‘
R’Eactwe inev
F12 uen:
m n y 7
D ,
,5 ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘
47 5 45 45 5 43 43 5 5m 5m 5 51 51 5 52 52 5
FvKuEnEy (HZ)
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 90 © 2009 Microchip Technology Inc.
minimal (<0.01%). When the input frequency deviates from the multiple of cycle
frequencies, the calculation error increases rapidly. As the calculation error is related
to the frequency offset to the multiple of freqency point, the calculation error caused by
frequency offset can be corrected. Figure C6 is the error analysis after frequency off
set correction using simple parabolic interpolation. Calcultion errors for all parameters
are shown to be less than 0.015% after the correction.
FIGURE C5: Error Analysis Of Improved Quasisync Calculation Using 3
Iterations.
FIGURE C6: Calculation Error Analysis After The Frequency Offset
Compensation.
Mr
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 91
C.7 MEASURING SECONDARY PARAMETERS
The methods of measuring parameters such as RMS values of voltage and current,
active power, reactive power and frequency have been discussed in previous sections.
These are primary parameters that need to be calculated from the original data. There
are some other parameters called secondary parameter, such as power factor of each
phase, total reactive power, total active power, total power factor, harmonic
components and cumulative energy. They are obtained indirectly from primary param
eters.
The measurement of secondary parameters is discussed in this section.
C.7.0.1 TOTAL ACTIVE POWER AND TOTAL REACTIVE POWER
For 3phase 4wire systems, 3phase total active power and recative power are the
sum of power of each phase, respectively, which can be expressed as:
EQUATION C54:
EQUATION C55:
C.8 APPARENT POWER OF EACH PHASE AND TOTAL APPARENT POWER
Apparent power is defined as:
EQUATION C56:
C.9 POWER FACTOR OF EACH PHASE AND TOTAL POWER FACTOR
Power factor is defined as the ratio of active power to apparent power. The definition
can be represented as shown in Equation C57:
EQUATION C57:
PP
APBPC
++=
QQ
AQBQC
++=
SQ
2p2
+=
PF P
P2Q2
+
=
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 92 © 2009 Microchip Technology Inc.
C.10 Active Energy AND REACTIVE ENERGY
Active energy is defined as the integral of active power over time, which is:
EQUATION C58:
In this design, active energy is obtained from multiplying the voltage by the current
sampled each time. The phase angle difference is compensated after each power
measurement is completed.
For reactive power, the cumulative reactive energy over a time period can be calculated
by measuring the average power and calculating the time interval between 2 measure
ments.
EQUATION C59:
C.11 POSITIVE/NEGATIVE ACTIVE ENERGY, POSITIVE/NEGATIVE REACTIVE
ENERGY AND FOURQUADRANT REACTIVE ENERGY
In the measurement plane, the horizontal axis denotes voltage vector U (fixed on the
horizontal axis). The instantaneous current vector is used to represent the power
transfer, and has a phase angle φ against vector U. φ is positive in counterclockwise
direction. Power exchange can be defined in 4 scenarios:
• Quadrant I (P>0, Q>0): active energy and reactive energy are sent out at the
same time;
• Quadrant II (P<0, Q>0): active energy is sent in while reactive energy is sent out;
• Quadrant III (P<0, Q<0): active energy is sent in while reactive energy is
absorbed;
• Quadrant IV (P>0, Q<0): active energy is sent out while the reactive energy is
absorbed.
1. Positive active energy and negative active energy: accumulated active
energy can be defined as positive and negative depending on the direction of
active current. When the direction of active current is positive (from power grid to
loads), active energy is positive (where active power P>0, corresponding to
quadrants I and IV, which means that loads are drawing energy from grid). When
current moves from loads to power grid, it is defined as negative active energy
(where active power P < 0, corresponding to quadrants II and III, which means
energy is provided to grid). Usually only positive active energy is taken into
account in active energy, but in practice negative active energy may be taken into
account as well, if necessary.
2. Positive reactive energy and negative reactive energy: If reactive power
Q > 0 (corresponding to quadrants I and II), it means power grid is providing
reactive energy to loads, so the energy is defined as positive reactive energy.
When reactive power Q < 0 (corresponding to quadrants III and IV), it means
that loads are providing reactive energy to power grid, so the energy is defined
as negative reactive energy.
WPt() td
0
T
∫uk() ik()
Δ
t
⋅⋅
k0=
N
∑
==
VrQ
0
T
∫t()dt=
w «at;
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 93
3. Fourquadrant reactive energy: metering reactive energy in positive/negative
reactive energy cannot truly reflect the status of reactive energy, whereas
4quandrant reactive energy measuring gives a true picture of energy exchange.
Reactive energy in four quadrants represents four different reactive energy (see
Figure C7). And the reactive energy is accumulated depending on which
quadrant it is located.
FIGURE C7: Definition Of 4 Quadrants To Measure Electrical Energy.
图2.4 电能测量四象限定义
Active in (+A)
I (RL)
II (RC)
Φ
III (RL)IV (RC)
Reactive in (+R)
Reactive out (R)
Active out (A)
A－有功电能；R—无功电能；RL—感性无功电能；RC—容性无功电能
电流向量
电压向量
图2.4 电能测量四象限定义
Active in (+A)
I (RL)
II (RC)
Φ
III (RL)IV (RC)
Reactive in (+R)
Reactive out (R)
Active out (A)
A－有功电能；R—无功电能；RL—感性无功电能；RC—容性无功电能
电流向量
电压向量
Active in (+A)
I (RL)
II (RC)
Φ
III (RL)IV (RC)
Reactive in (+R)
Reactive out (R)
Active out (A)
A－有功电能；R—无功电能；RL—感性无功电能；RC—容性无功电能
Active in (+A)
I (RL)
II (RC)
Φ
III (RL)IV (RC)
Reactive in (+R)
Reactive out (R)
Active out (A)
A－有功电能；R—无功电能；RL—感性无功电能；RC—容性无功电能
电流向量
电压向量
Voltage vector
Current vector
Where:
A=is active energy,
R=is reactive energy
RL=is inductive reactive energy
RC=s capacitive reactive energy
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 94 © 2009 Microchip Technology Inc.
C.12 HARMONIC COMPONENTS OF CURRENT, VOLTAGE AND TOTAL
HARMONIC DISTORTION
In Section C.3 “The Harmonic Analysis Algorithm Of Quasisynchronous Sam
pling”, we discussed the measuring of current and voltage signals for each order of
harmonics. 3 parameters are used to show to what extent a distorted wave deviates
from a sine wave. They are: harmonic content, total distortion and harmonic ratio of the
kth harmonic. The term harmonic content means the root of square of effective values
for all harmonics, which is defined as:
EQUATION C60:
The total voltage distortion ratio of harmonics is the ratio of harmonic content to the
fundamental in percentage, which is defined as:
EQUATION C61:
The kth harmonic ratio for voltage is the ratio of the kth harmonic to the fundamental
in percentage, defined as:
EQUATION C62:
Similarly, harmonics of each order for the current and total distortion ratio can be sorted
out.
UHUk2
k2=
N
∑
=
THDU
UH
UI
 100%
×
THDUk
()
2
k2=
N
∑
=
THDUk
Uk
U1
 100%
×
=
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 95
C.13 COMPENSATION FOR RATIO ERROR AND PHASE LAG
The error of the current transformer (CT) is a complex, which can usually be expressed
by two orthogonal parts, current error (f) and phase lag (δ).
EQUATION C63:
The current error, also known as ratio error, can be written in percentage as:
EQUATION C64:
Phase lag, also known as angle error, is the phase difference between primary and
secondary current vector, in 'minute'.
Different current transformers have different errors. Current transformers are classified
into different accuracy classes depending on their error magnitudes. The accuracy
class of a transformer is nominated by the percentage of the maximal ratio error
allowed for a given rated current.
Accuracy classes and corresponding error limits for a current transformer are listed in
Table C1.
TABLE C1: ACCURACY CLASS AND ERROR LIMIT FOR THE CURRENT TRANSFORMER
ε
fj
δ⋅
+=
f 100 knI2I1
–()
I1

=
Where:
Kn=the rated current ratio
I1=the primary current
I2=the secondary current that passes I1
under the test condition
Accurate
Class
Ratio Error± (%) Phase lag
Rated Current (%) ± (%) ± (Grad)
Rated Current (%) Rated Current (%)
1 5 20 100 120 1 5 20 100 120 1 5 20 100 120
0.1 0.4 0.2 0.1 0.1 15 8 5 5 0.45 0.24 0.15 0.15
0.2 0.75 0.35 0.2 0.2 30 15 10 10 0.9 0.45 0.3 0.3
0.5 1.5 0.75 0.5 0.5 90 45 30 30 2.7 1.35 0.9 0.9
13 1.5 1.0 1.0 180 90 60 60 5.4 2.7 1.8 1.8
Rated Current (%) Phase difference
50 120
333 Phase difference of class 3 and class 5 are not specified.
555
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 96 © 2009 Microchip Technology Inc.
C.14 RELATIONSHIP BETWEEN ERROR AND CURRENT
For a given load and frequency, the absolute ratio error and angle error increase when
the primary current decreases from the rated value for uncompensated current trans
former. The reason is that with the decrease of the secondary current, the magnetic
permeability µ of the iron core varies nonlinearly, resulting in less reduction in the field
ampere turns.
Figure C8 is a typical curve for load current and the phase lag of a CT. Generally,
phase lag of the output signal is great when the load current is small, and also
increases at a fast rate.
FIGURE C8: Current Load Versus CT Phase Lag.
Current Load
Phase Lag
Inpm
Voltage
Inpm
Current
CT
2000:1
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 97
C.15 RATIO ERROR COMPENSATION
As nonlinearity and inconsistency exist in the sampling circuit (including CT and
backend shunt resistors) and the ADC circuit, it is necessary to compensate for ratio
error to the system. Figure C9 is the transfer link of the voltage and current channels.
The compensation for ratio error is quite simple. It compares the measured value
against the actual input value under certain input conditions and obtains a correction
coefficient.
EQUATION C65:
FIGURE C9: Error Caused By Sampling Circuit And ADC.
Since current has a large dynamic range, for a meter which requires high accuracy
(0.2s and 0.5s), the multipoint calibration method is needed to meet input requirement
for full range. The MCP3909 device's current channel includes an adjustable gain
amplifier. The ratio error must be recalibrated for different amplification, but only needs
to be calibrated once under the same amplification conditions.
Correction coefficient Coefficient before correction Calibration Value
Measured Value

×
=
Input
Voltage
R0 CT
1:1 ADC
R0 R0
Voltage primary
Sampling resistor
Voltage secondary
Sampling resistor
Input
Current
CT
2000:1 ADC
R2 R2
Current secondary
Sampling resistor
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 98 © 2009 Microchip Technology Inc.
C.16 PHASE LAG COMPENSATION
Phase lag of a CT has no effect on the metering of RMS current/voltage and apparent
power, but will affect the metering of power, since the phase lag will change the phase
relationship between the input current and the voltage. This will result in a deviation of
the calculated active power from the calculated reactive power.
Figure C10 shows how a transformer's phase lag affects the measured results under
both inductive and capacitive loads. Let's assume that the output of CT has no phase
lag from the input voltage, while the CT has a phase lag from the input signal. With
inductive loads, the phase angle increases between the volatge and the current
because of the phase lag induced by the CT, resulting in a decrease of the measured
active power and an increase of the reactive power. While with capacitive loads, the
phase angle between the voltage and the current decreases because of the phase lag
induced by the CT, resulting in a decrease of the measured reactive power and an
increase of active power.
There are many methods for phase lag compensation. In this design the result correc
tion method is used. It compensates with a coefficient after the active power and
reactive power are figured out, which has a small amount of calculation.
FIGURE C10: Measurement Change Caused By Transformer Phase Lag.
Assuming that the phase lag of CT is ϕi, of PT is ϕu, after PT and CT, the variation of
phase lag between current and voltage is:
Δϕ
=
ϕ
u–
ϕ
i.
FIGURE C11: Principle Of Phase Lag Correction.
Input
current
CT Output
current
Input
voltage
Capacitive
Load
Inductive
Load
Δθ
θ
Input
current
CT Output
current
Input
voltage
Capacitive
Load
Inductive
Load
Δθ
θ
F
Δf
S
P'
P
Q
Q'
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 99
Given that the phase lag between the input voltage and current is φ, after PT and CT,
the actual measured active power is P', reactive power is Q'. RMS current is I, RMS
voltage is V, input apparent power is S, actual input active power is P and reactive
power is Q, then Figure C11 can be drawn based on the principles of power triangle.
EQUATION C66:
EQUATION C67:
From the above 2 equations, we have:
EQUATION C68:
EQUATION C69:
Where:
EQUATION C70:
EQUATION C71:
By setting up certain input conditions, Δϕ can be measured, and then k1 and k2 can be
calculated.
In this design, we use an input of 0.5L for calibration. With this condition, Δϕ can be
calculated using the difference between the meaured and the actual input value of
active power. For accurate calculations, the user may also use the difference between
the measured cumulative energy and the actual cumulative energy to calculate the
difference.
EQUATION C72:
Where err is the error rate of the energy measurement, which results from calculating
the error between the actual energy measured by a standard meter and the energy
measured by the dsPIC devices. The error can be obtained from the output of the meter
calibration workbench.
EQUATION C73:
P'VI
φΔϕ
+()cos
⋅⋅
P
Δϕ
cos Q
Δϕ
sin–==
Q'VI
φΔϕ
+()sin
⋅⋅
Q
Δϕ
cos P
Δϕ
sin–==
Pk
1P'k2Q'+=
Qk
1Q'k2P'–=
k1
Δϕ
cos=
k1
Δ
sin
ϕ
=
Δϕ
aP'
2P
⋅

⎝⎠
⎛⎞
π
3

–cos a 0.5 1 err+()
⋅
()
π
3

–
⎝⎠
⎛⎞
cos==
err P'P–
P

Δ
P
P
 100
×
==
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 100 © 2009 Microchip Technology Inc.
Since the phase lag of a CT's output signal is related to the magnitude of current,
different correction coefficients, K, can be set according to different RMS current
values. In this design, 5 calibration points can be set. If it does not require highpreci
sion, fewer points can be set to simplify calibration.
If onetime calibration cannot meet the precision requirement, more calibrations can be
done. The new angle error may still be calculated using Equation C72. The new
correction coefficient is:
EQUATION C74:
EQUATION C75:
C.16.0.1 PHASE LAG COMPENSATION WHEN FREQUENCY VARIES
For the same current intensity, the signal delay caused by the CT is the same. When
the frequency of the input signal varies, the phase lag will be different. Normally,
calibration is done at 50 Hz. When the frequency varies, if the same phase lag
compensation coefficient for 50 Hz is still used, it will cause an error in the power
measurement. In most cases, the frequency varies in a small range (test specification
requires ±2.5%), so it has little effect on the measurement accuracy. For meters with
an accuracy of 0.5s or above, this measurement error can be ignored. But for 0.2s
meters, the error cannot be ignored and the frequency variation needs to be corrected
during calculation.
The phase lag compensation coefficient k1 and k2 are corrected during calculation.
Assuming that the freqnency is 50 Hz, the signal delay caused by CT is t, then after
correction, the compensation coefficient k1 and k2 will be:
EQUATION C76:
EQUATION C77:
When frequency varies, assuming that the frequency offset is Δf, i.e. the input signal
frequency is 50 + Δf, then the compensation coefficient will be:
EQUATION C78:
EQUATION C79:
k'1
Δϕ
1
Δϕ
2
+()cos k1
Δϕ
2
cos k2
Δϕ
2
sin
⋅
–
⋅
==
k'2
Δϕ
1
Δϕ
2
+()sin k2
Δϕ
2
cos k1
Δϕ
2
sin
⋅
–
⋅
==
k1
Δϕ
cos t 50 2
π⋅⋅
()cos==
k2
Δ
sin
ϕ
t502
π⋅⋅
()sin==
k'1
Δϕ
cos t 50
Δ
f+()2
π⋅⋅
()cos==
k'2
Δ
sin
ϕ
t50
Δ
f+()2
π⋅⋅
()sin==
Power Calculation Theory
© 2009 Microchip Technology Inc. DS51723Apage 101
To avoid complexity in calculation and to maximize the correction precision, the
following equations may be used to approximate K1 and K2 when the phase angle is
small.
EQUATION C80:
EQUATION C81:
k'1
Δϕ
cos
Δϕ
cos
Δ
f
50
sin2
Δϕ⋅
–
≈
=
k1
Δ
f
50
k2k2
⋅⋅
–=
k'2
Δ
sin
ϕΔ
sin
ϕΔ
f
50
sin
Δϕ Δϕ
cos
⋅⋅
–
≈
=
k2
Δ
f
50
k1k2
⋅⋅
–=
MCP3909 / dsPIC33F 3Phase Energy Meter Reference Design
DS51723Apage 102 © 2009 Microchip Technology Inc.
NOTES:
6‘
MICROCHIP
MCP3909 / DSPIC33F 3PHASE
ENERGY METER REFERENCE DESIGN
© 2009 Microchip Technology Inc. DS51723Apage 103
Appendix D. 50/60 Hz Meter Operation
D.1 FIRMWARE VERSIONS
There are two versions of firmware for the meter due to the quasisynchronous
sampling scheme employed by the dsPIC33F firmware. The design covers the
frequency of rated frequency ±2.5 Hz.
To change the rated frequency, just change the definition in the beginning of
cacul.h  #define STD_FREQ 50.0.
This is provided for download from Microchip’s website, file names and checksums
below.
At the same time you need to change the crystal to provide clock for metering IC.
TABLE D1: FIRMWARE FILES
Line Frequency Firmware Name Hex File Checksum YXX VALUE
50 Hz PM_1_50.ZIP TBD 3.857 MHz
60 Hz PM_1_60.ZIP TBD TBD
Q
‘MICROCHIP
DS51723Apage 104 © 2009 Microchip Technology Inc.
AMERICAS
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 852246199
Tel: 4807927200
Fax: 4807927277
Technical Support:
http://support.microchip.com
Web Address:
www.microchip.com
Atlanta
Duluth, GA
Tel: 6789579614
Fax: 6789571455
Boston
Westborough, MA
Tel: 7747600087
Fax: 7747600088
Chicago
Itasca, IL
Tel: 6302850071
Fax: 6302850075
Cleveland
Independence, OH
Tel: 2164470464
Fax: 2164470643
Dallas
Addison, TX
Tel: 9728187423
Fax: 9728182924
Detroit
Farmington Hills, MI
Tel: 2485382250
Fax: 2485382260
Kokomo
Kokomo, IN
Tel: 7658648360
Fax: 7658648387
Los Angeles
Mission Viejo, CA
Tel: 9494629523
Fax: 9494629608
Santa Clara
Santa Clara, CA
Tel: 4089616444
Fax: 4089616445
Toronto
Mississauga, Ontario,
Canada
Tel: 9056730699
Fax: 9056736509
ASIA/PACIFIC
Asia Pacific Office
Suites 370714, 37th Floor
Tower 6, The Gateway
Harbour City, Kowloon
Hong Kong
Tel: 85224011200
Fax: 85224013431
Australia  Sydney
Tel: 61298686733
Fax: 61298686755
China  Beijing
Tel: 861085282100
Fax: 861085282104
China  Chengdu
Tel: 862886655511
Fax: 862886657889
China  Hong Kong SAR
Tel: 85224011200
Fax: 85224013431
China  Nanjing
Tel: 862584732460
Fax: 862584732470
China  Qingdao
Tel: 8653285027355
Fax: 8653285027205
China  Shanghai
Tel: 862154075533
Fax: 862154075066
China  Shenyang
Tel: 862423342829
Fax: 862423342393
China  Shenzhen
Tel: 8675582032660
Fax: 8675582031760
China  Wuhan
Tel: 862759805300
Fax: 862759805118
China  Xiamen
Tel: 865922388138
Fax: 865922388130
China  Xian
Tel: 862988337252
Fax: 862988337256
China  Zhuhai
Tel: 867563210040
Fax: 867563210049
ASIA/PACIFIC
India  Bangalore
Tel: 918030904444
Fax: 918030904080
India  New Delhi
Tel: 911141608631
Fax: 911141608632
India  Pune
Tel: 912025661512
Fax: 912025661513
Japan  Yokohama
Tel: 8145471 6166
Fax: 81454716122
Korea  Daegu
Tel: 82537444301
Fax: 82537444302
Korea  Seoul
Tel: 8225547200
Fax: 8225585932 or
8225585934
Malaysia  Kuala Lumpur
Tel: 60362019857
Fax: 60362019859
Malaysia  Penang
Tel: 6042278870
Fax: 6042274068
Philippines  Manila
Tel: 6326349065
Fax: 6326349069
Singapore
Tel: 6563348870
Fax: 6563348850
Taiwan  Hsin Chu
Tel: 88636578300
Fax: 88636578370
Taiwan  Kaohsiung
Tel: 88675364818
Fax: 88675364803
Taiwan  Taipei
Tel: 886225006610
Fax: 886225080102
Thailand  Bangkok
Tel: 6626941351
Fax: 6626941350
EUROPE
Austria  Wels
Tel: 437242224439
Fax: 4372422244393
Denmark  Copenhagen
Tel: 4544502828
Fax: 4544852829
France  Paris
Tel: 33169536320
Fax: 33169309079
Germany  Munich
Tel: 49896271440
Fax: 498962714444
Italy  Milan
Tel: 390331742611
Fax: 390331466781
Netherlands  Drunen
Tel: 31416690399
Fax: 31416690340
Spain  Madrid
Tel: 34917080890
Fax: 34917080891
UK  Wokingham
Tel: 441189215869
Fax: 441189215820
WORLDWIDE SALES AND SERVICE
03/26/09
Products related to this Datasheet
IC MCU 16BIT 128KB FLASH 64TQFP
IC MCU 16BIT 128KB FLASH 64TQFP
IC POWER METERING1 PHASE 24SSOP
IC POWER METERING1 PHASE 24SSOP
IC MCU 16BIT 128KB FLASH 64TQFP
IC MCU 16BIT 128KB FLASH 64TQFP
IC MCU 16BIT 128KB FLASH 64QFN
IC MCU 16BIT 128KB FLASH 64TQFP
IC POWER METERING1 PHASE 24SSOP
REF DESIGN MCP3909 3PH ENGY MTR
REF DESIGN FOR MCP3909 W/18F2520
EVALUATION BOARD FOR MCP3909
IC MCU 16BIT 128KB FLASH 64QFN
IC MCU 16BIT 128KB FLASH 64TQFP
IC MCU 16BIT 128KB FLASH 64QFN
IC MCU 16BIT 128KB FLASH 64QFN
IC MCU 16BIT 128KB FLASH 64TQFP
IC MCU 16BIT 128KB FLASH 64TQFP
IC POWER METERING1 PHASE 24SSOP