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.
Information contained in this publication regarding device
applications and t he lik e is provided only for your convenience
and may be su perseded by upda t es . It is y our 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 supp ort and/or safety ap plications is entir ely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless M icrochip from any and all dama ges, claims,
suits, or expenses re sulting from such use. No licens es are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, dsPIC,
K
logo, rfPIC and UNI/O are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
FilterLab, Hampshire, HI-TECH 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.
Analog-for-the-Digital Age, Application Maestro, chipKIT,
chipKIT logo, CodeGuard, dsPICDEM, dsPICDEM.net,
dsPICworks, dsSPEAK, ECAN, ECONOMONITOR,
FanSense, HI-TIDE, In-Circuit Serial Programming, ICSP,
Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB,
MPLINK, mTouch, Omniscient Code Generation, PICC,
PICC-18, PICDEM, PICDEM.net, PICkit, PICtail, 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.
Microchip received ISO/TS-16949:2009 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
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.
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 p age 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 up-to-date information on development tools, see the MPLAB
Select the Help menu, and then Topics to open a list of available online help files.
®
IDE online help.
INTRODUCTION
This chapter contains general information that will be useful to know before using the
MCP3901 and PIC18F65J90 Energy Meter Reference Design User’s Guide. Items
discussed in this chapter include:
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
DOCUMENT LAYOUT
This document describes how to use the MCP3901 and PIC18F65J90 Energy Meter
Reference Design as a development tool to emulate and debug firmware on a target
board. The manual layout is as follows:
• Chapter 1. “Product Overview” – Important information on using the MCP3901
and PIC18F65J90 Energy Meter Reference Design including a Getting Started
section that describes wiring the line and load connections.
• Chapter 2. “Hardwa re ” – Includes details on the function blocks of the meter
including the analog front end design, phase lock loop circuitry, and power supply
design.
• Chapter 3. “Calculation Engine and Register Description” – This section
describes the digital signal flow for all power output quantities such as RMS
current, RMS voltage, active power, and apparent power. This section also
includes the calibration register’s detail.
• Chapter 4. “Meter Protocol and Timings”– This chapter describes the protocol
used for accessing the registers, including commands that are used to interface to
the meter.
• Appendix A. “Schematic and Layouts” – Shows the schematic and layout
diagrams.
• Appendix B. “Bill of Materials (BOM)” – Lists the parts used to build the
MCP3901 and PIC18F65J90 Energy Meter Reference Design.
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
RECOMMENDED READING
This user's guide describes how to use the MCP3901 and PIC18F65J90 Energy Meter
Reference Design. Other useful documents are listed below. The following Microchip
documents are available and recommended as supplemental reference resources.
MCP3901 Data Sheet – “Two Channel Analog Front End” (DS22192)
This data sheet provides detailed information regarding the MCP3901 device.
AN994 – “IEC Compliant Active-Energy Meter Design Using the MCP3905A/06A”
(DS00994)
This application note documents the design decisions associated with using the
MCP390X devices for energy meter design and IEC compliance.
THE MICROCHI P 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 listin g
• 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:
The MCP3901 and PIC18F65J90 Energy Meter Reference Design is a fully functional
IEC Class 0.5 compliant single-phase meter. This low-cost design does not use any
transformers and requires few external components. The PIC18F65J90 directly drives
the LCD, and includes both an isolated USB connection for meter calibration and
access to the device power calculations. The system calculates active energy, active
power, RMS current, RMS voltage, reactive energy, reactive power, apparent power
and other typical power quantities.
The Microchip Energy Meter 1-Phase Software is used to calibrate and monitor the
system, and can be used to create custom calibration setups. For some accuracy
requirements, only a single point calibration may be needed. The energy meter
software offers an automated step-by-step calibration process that can be used to
quickly calibrate energy meters.
MCP3901 AND PIC18F65J90
ENERGY METER
REFERENCE DESIGN
FIGURE 1-1:MCP3901 and PIC18F65J90 Single-Phase Energy Meter.
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
1.2WHAT THE MCP3901 AND PIC18F65J90 ENERGY METER REFERENCE
DESIGN KIT INCLUDES
This MCP3901 and PIC18F65J90 Energy Meter Reference Design kit includes:
• MCP3901 and PIC18F65J90 Energy Meter Reference Design User’s Guide
• Important Information Sheet
1.3GETTING STARTED
To describe how to use the MCP3901 and PIC18F65J90 Energy Meter Reference
Design, the following example is given using a two-wire 1-phase, 220 V AC line voltage
and connections using energy meter calibrator equipment, or other programmable load
source. The meter design uses a 5A load for calibration current, and a maximum
current (I
To test a calibrated meter, the following connections apply for a two-wire connection.
1.3.1Step 1: Wiring Connections
Figure 1-2 identifies the line and load connections of the MCP3901 and PIC18F65J90
Energy Meter Reference Design.
MAX
) of 60A.
1
Line
Neutral
MAIN
2
3
4
Line
Neutral
LOAD
FIGURE 1-2:Example Connections using a 2-Wire System.
1.3.2Step 2: Turn On Line/Load Power to the Meter (Power the Meter)
The meter will turn on when the line connection has 220V connected. The LCD display
will show the total energy accumulated.
Figures 2-1 and 2-2 show the MCP3901 and PIC18F65J90 and Energy Meter
Reference Design:
MCP3901 AND PIC18F65J90
ENERGY METER
REFERENCE DESIGN
Chapter 2. Hardware
3
1
4
2
10
J2
U1
LCD1
9
D9D8
D1
P1
D3
J4
J3
D2
SW3
8
7
SW1
C40
SW2
DANGER
HIGH VOLTAGE
MCP3901 / PIC18F65J90 SHUNT METER
Legend:
1 = IR for meter communication7=Push button Switches
2 = Test points8=9-digit LCD Disp lay with icons for kWh and kVARh
3 = MCP3901 Analog Front End9=Pulse Output for Active and Reactive
4 = +9V DC Input (non-isolated)10=USB Connection (isolated)
5 = Connections to shunt
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
.
17
C40
R21
R20
X2
R28
R27 R26
C32
C24 C25
R19
U7
R17
U4
C7
R29
U2
C39
R33
C37
U5
R30
R34
16
12
13
DANGER
HIGH VOLTAGE
C6
C5
C41
R14
R12
C2
R15
R11
C1
L1
Q1
C38
D5
D4
U8
C30
C27
C21
C22
C10
R31
C23
D6
L2
L3
R24 R25
C19
C17
R18
C16
D7
C4
MOV1
U6
C8
C9
R32
U3
Legend:
12=Opto-isolators for Pulse outputs
13=Power supply
14=Non-volatile memory for calibration constants and energy usage data
15=PIC18F65J90
16=Isolation IC
17=MCP2200 for USB connection
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
2.2INPUT AND ANALOG FRONT END
The MCP3901 and PIC18F65J90 and Energy Meter Reference Design comes
populated with components designed for 220V line voltage. At the bottom of the main
board are the high voltage line and neutral connections. There are four connections
that are made from the PCB to the meter casing. They are labeled LINE, NEUTRAL,
SHUNT1, and SHUNT2. The shunt sits on the high or line side of a two-wire system
and the meter employs a hot or “live” ground. The wires going into the shunt to
SHUNT1 and SHUNT2 should be twisted together. The wires going into the LINE and
NEUTRAL side of the meter should be twisted together, and also kept away from the
SHUNT1 and SHUNT2 wires if possible.
The neutral side of the two-wire system goes into a resistor divider on the voltage
channel input. Anti-aliasing low-pass filters will be included on both differential
channels. The voltage channel uses two 332 kΩ resistors to achieve a divider ratio of
664:1. For a line voltage of 230 V
490 mV
PEAK
.
, the channel 1 input signal size will be
RMS
LINE_SHUNT1
Shunt
(external to
PCB part of
meter case)
LINE_SHUNT2
NEUTRAL
150 FB (Note)
150 FB (Note)
332 kΩ
332 k Ω
1.0 kΩ
10-step optional
resistor
ladder
1.0 kΩ
1.0 kΩ
1.0 kΩ
Note:FB = ferrite beads. Ferrite beads have an impedance of the
Chapter 3. Calculation Engine and Register Description
3.1CALCULATION ENGINE SIGNAL FLOW SUMMARY
RMS voltage, RMS current, Active Power, Reactive Power and Apparent Power, and
the calibration output pulse are all calculated through the following process described
in Figure 3-1. The calibration registers for each calculation are shown as well as the
16/24-bit
ADC
CURRENT
GAIN_
COMPENSATION
_90:
8
16/24-bit DS ADC
ADC
VOLTAGE
output registers.
ΔΣ
ADC
X
90°
with
Φ
Correction
Φ
OFFSET_I_RMS:
2
X
RMS Current
Reactive Power
O
FFSET_POWER_REACT:32
X
Active Power
PH
ASE_COMPENSATION:8
OFFSET_V_RMS:
OFFSET_POWER_ACT:
16
Σ
Σ
Σ
32
16
X
Apparent Power
8
NUMR_ENERGY_ACT:16
GAIN_
GAIN_DENR_ENERGY_ACT:
/
1/METER_CONSTAT
Σ
imp/kWh
DENR_ENERGY_REACT:8
GAIN_
imp/kVARh
Digital to
Frequency
Converter
Digital to
Frequency
Converter
NUMR_ENERGY_REACT:16
GAIN_
/
Σ
1/METER_CONSTAT
2
X
16
GAIN_POWER_REACT:
X
kVAR
32
POWER_REACT:
Σ
RMS Voltage
16
X
GAIN_ENERGY_REACT:
kVARh
REACT:32
ENERGY_
X
kVA
32
POWER_APP:
16
GAIN_ENERGY_ACT:
kWh
16
16
GAIN_V_RMS:
16
X
V
_RMS:16
V
X
GAIN_I_RMS:
GAIN_POWER_ACT:
A
_RMS:16
I
16
X
GAIN_POWER_APP:
kW
32
POWER_ACT:
16
XX
GAIN_ENERGY_APP:
kVAh
ACT:32
ENERGY_
APP:32
ENERGY_
FIGURE 3-1:PIC18F65J90 Calculation Engine Signal Flow
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
3.2REGISTER LIST
Note:Important! Not all registers and features
are implemented in this version of
firmware release.
TABLE 3-1:INTERNAL REGISTER SUMMARY
NameBits R/WDescription
MODE8R/W Configuration register for operating mode of the meter
STATUS8RSTATUS register
CAL_CONTROL8R/W Configuration register for calibration control
LINE_CYC16R/W 2n number of line cycles to be used during energy accumulation
LINE_CYC_CNT16RCounter for number of line cycles
2
RAW2_I_RMS64RRaw
RAW_I_RMS16RRaw RMS value from the current A/D converter in LSBs
I_RMS16RRMS value of the current, post Calibration
RAW2_V_RMS64RRaw
RAW_V_RMS16RRaw RMS value from the voltage A/D converter in LSBs
V_RMS16RRMS value of the voltage, post Calibration
LINE_FREQUENCY16RLine Frequency
RAW_POWER_ACT64RRaw Active Power
POWER_ACT32RFinal Active Power, units in watts (W)
POWER_APP32RFinal Apparent Power, units in volt-am peres (VA)
RAW_POWER_REACT64RRaw Reactive Power
POWER_REACT32RFinal Reactive Power, units in volt-amperes-reactive (VAR)
PERIOD32RPeriod register
ENERGY_ACT32RFinal Active Energy accumulated
RAW_ENERGY_ACT64RRaw Active Energy accumulated
ENERGY_APP32RFinal Apparent Energy accu mulated
RAW_ENERGY_APP64RRaw Apparent Energy accumulated
I_ABS_MAX8RNot implemented
V_ABS_MAX8RNot implemented
ENERGY_REACT32RFinal Reactive Energy accumulated
RAW_ENERGY_REACT64RFinal Reactive Energy accumulated
PHASE_COMPENSATION8R/W Phase compensation between voltage and current
OFFSET_I_RMS16R/W Offset adjustment for RMS current reading
OFFSET_V_RMS16R/W Offset adjustment for RMS voltage reading
GAIN_I_RMS16R/W Gain adjustment for RMS current
GAIN_V_RMS16R/W Gain adjustment for RMS voltage
OFFSET_POWER_ACT32R/W Act ive Power offset
GAIN_POWER_ACT16R/W Ac tive Power gain adjust
OFFSET_POWER_REACT32R/W Offset correction for Reactive Power
GAIN_POWER_REACT16R/W Reactive Power gain adjust to produce X VAR/LSB
GAIN_ENERGY_ACT16 R/W Not implemented
GAIN_ENERGY_APP16 R/W Not implemented
GAIN_ENERGY_REACT16 R/W Not implemented
CF_PULSE_WIDTH8R/W Defines CF pulse width from 0 to 255 x 0.8192 ms (0.209s)
GAIN_DENR_ENERGY_ACT8R/W Active Energy Pulse Output correction factor
GAIN_NUMR_ENERGY_ACT16 R/W Active Energy Pulse Output correction factor
MODE1_DEF16 R/W Power Up Configuration Register
CAL_STATUS16 R/W Calibration Status
MAXIMUM CURRENT16 R/W Maximum current of the meter (I
CALIBRATION_VOLTAGE16 R/W Calibration Voltage of the meter (V
CALIBRATION_CURRENT16 R/W Calibration Current of the meter (I
CALIBRATION_FREQUENCY16 R/W Calibration Frequency of the meter
METER_CONSTANT16 R/W Meter Constant in imp/kWh or imp/kVARh
CALIBRATION_LINE_CYCLE16R/W Number of line cycles for calibration
GAIN_DENR_ENERGY_REACT8R/W Reactive Energy Pulse Output correction factor
GAIN_NUMR_ENERGY_REACT 16 R/W Reactive Energy Pulse Output correction factor
PHASE_COMPENSATION_908R/W Phase delay for Reactive Power
CREEP_THRSHOLD_MINUTE8R/W No Load threshold time (minutes)
CREEP_THRSHOLD_SECOND8R/W No Load threshold time (seconds)
ENERGY_ACT32 R/W Active Energy
ENERGY_REACT32 R/W Reactive Energy
MAX
CAL
CAL
)
)
)
3.3MODE
The MODE register controls the operation of the energy meter. The bit functions are
defined by the table below.
REGISTER 3-1:MODE REGISTER
U-0U-0U-0U-0R/W-0R/W-0R/W-0R/W-0
————CFABSOLUTEPHASECREEP
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 7-4Unimplemented: Read as ‘0’.
bit 3CF: Active Energy CF Phase Enable bit
1 =Bit = 1 Phase is enabled to be accumulated into the total energy registers or CF pulse output
0 =Bit = 0 Phase is DISABLED and is not accumulated into the total energy registers or CF pulse
output
bit 2ABSOLUTE Positive Only Energy Accumulation Mode bit
1 =Bit = 1 Positive energy only
0 =Bit = 0 Both negative and positive energy accumulated (negative energy is subtracted)
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
3.4STATUS
The STATUS register contains the operational status of the energy meter. The bit
functions are defined in the table below.
REGISTER 3-2:STATUS REGISTER
U-0U-0U-0U-0U-0U-0RU-0
——————PH_S—
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 7-2Unimplemented: Read as ‘0’
bit 1PH_S: Phase Sign bit
1 = CT may be in backward (if enabled)
0 = Operation normal
bit 0Unimplemented: Read as ‘0’
3.5CAL_CONTROL
This is the Calibration mode control register. Bit 0 enables the Calibration mode. In this
mode, the power meter operates as normal, but no updates are made to the voltage,
current, power or energy registers as long as bit 1 is low. When bit 1 is set high, the
registers are updated for LINE_CYC line cycles (only power and energy registers are
updated). After this time, bit 1 is set low by the PIC18F65J90 and the update of the
registers will stop. This allows the calibration software to set bit 0, clear the registers,
set bit 1 and start reading the desired registers, as well as the CAL_CONTROL register,
to check the status of bit 1. When bit 1 goes low, the LINE_CYC line cycles have
passed and the registers are final. Note that bit 0 takes effect immediately, and bit 1 will
take effect on the very next line cycle. When bit 1 goes low, all registers will be ready
to read.
REGISTER 3-3:CAL_CONTROL REGISTER (NOTE 1)
U-0U-0U-0U-0U-0U-0R/W-0R/W-0
—————ReservedCAL_UPDATE CAL_MODE
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
Power and energy registers upda ted for LINE _CYC lin e cy cl es when cle are d. Bit mu st be set for registers to begin updating, which starts on the next line cycle after bit is set.
1 =When the CAL_MODE bit is set, set the CAL_U PDA TE bit to enable update of power and energy
registers starting on next line cycle. Bit = 1 Single Point Phase Correction.
0 =When the CAL_MODE bit is set and the CAL_UPDATE bit has been set, the CAL_UPDATE bit
will be cleared after LINE_CYC line cycles. At that point, all registers will be updated and no
further updates will be done until the CAL_UPDATE bit is set again, or the CAL_MODE bit is
cleared.
Note 1: This register is used in Multi-Point and Single-Point Calibration modes only.
3.6LINE_CYC
NameBitsCof
LINE_CYC16R/W
Number of line cycles as a power of two. A setting of 0 indicates 20 or one line cycle.
A setting of 1 is two line cycles (2
of eight which is 256 line cycles. When written, this register will not take effect until the
previous number of line cycles has been acquired.
3.7LINE_CYC_CNT
NameBitsCof
LINE_CYC_CNT16R
This register counts from 0 and finishes at 2
LINE_CYC represents the value in the LINE_CYC register.
3.8RAW2_I_RMS
NameBitsCof
RAW2_I_RMS64R
This register is the square of the raw RMS value from the current A/D converter in
LSBs. By definition, this register will always contain a positive value, including the situation where power is negative from a backwards CT or otherwise. This register is
overwritten every LINE_CYC line cycle and is written only once, if calibration is
enabled.
1
), a setting of 2 is four lines cycles (22), up to a setting
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
3.9RAW_I_RMS
NameBitsCof
RAW_I_RMS16R
This register is the raw RMS value from the current A/D converter in LSBs (square root
of the top 32-bits of RAW2_I_RMS + OFFSET_I_RMS). By definition, this register will
always contain a positive value (even if the CT is in backwards). This register is overwritten every LINE_CYC line cycle and is written only once, if calibration is enabled.
3.10I_RMS
NameBitsCof
I_RMS16R
This register is the RMS value of phase A current in X A/LSB, as determined by the
value in the GAIN _I_RMS regist er . When display ing the RMS curr ent, multiply the (decimal) value in these registers by X to get the display value in amperes. This register is
overwritten every LINE_CYC line cycle (written only once if calibration is enabled).
3.11RAW2_V_RMS
NameBitsCof
RAW2_V_RMS64R
This register is the square of the raw RMS value from the voltage A/D converter in
LSBs. By definition, it will always contain a positive value. This register is overwritten
every LINE_CYC line cycle (written only once if calibration is enabled).
3.12RAW_V_RMS
NameBitsCof
RAW_V_RMS16R
This is the raw RMS value from the voltage A/D converter in LSBs (square root of the
top 32-bits of RAW2_V_RMS + OFFSET_V_RMS). By definition, this register will
always contain a positive value. The register is overwritten every LINE_CYC line cycle
(written only once if calibration is enabled).
3.13V_RMS
NameBitsCof
V_RMS16R
This register is the RMS value of the voltage, in X 0.01 V/LSB, as determined by the
value in the GAIN_V_RMS register. When displaying the RMS voltage, assume a calibrated meter exists and multiply the (decimal) value in these registers by X to get the
display value in volts. This register is overwritten every LINE_CYC line cycle (written
only once if calibration is enabled).
This register holds the measured line frequency using the zero crossing technique.
3.15RAW_POWER_ACT
NameBitsCof
RAW_POWER_ACT64R
This register is the raw active power, as it represents the sum of current A/D value times
voltage A/D value results over LINE_CYC line cycles (each line cycle has 128 results).
Each current times voltage multiplication results in a 32-bit word. There are up to 256
line cycles with each line cycle being 128 results, and each result being 32-bit. Thus,
48 bits are needed. This is the register to be read during calibration for calculating the
offset and gain values associated with active power, OFFSET_POWER_ACT and
GAIN_POWER_ACT. This register is overwritten every line cycle, however if calibration
is enabled, the updates will stop once the LINE_CYC line cycles have elapsed.
3.16POWER_ACT
NameBitsCof
POWER_ACT32R
This register is the value for active power. The goal of the calibration is to get this register value to equal X W/LSB. This is done with the OFFSET_POWER_ACT and
GAIN_POWER_ACT registers. When displaying the power, multiply the (decimal)
value in this register by X to get the display value in watts. This register is overwritten
every LINE_CYC line cycle (written only once if calibration is enabled).
3.17POWER_APP
NameBitsCof
POWER_APP32R
This is the value of the apparent power. The goal of the calibration is to get this value
to equal X VA/LSB. This is done with the GAIN_POWER_APP registers. When displaying the power for phase A, multiply the (decimal) value in this register by X to get the
display value in watts. This register is overwritten every LINE_CYC line cycle (written
only once if calibration is enabled).
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
3.18RAW_POWER_REACT
NameBitsCof
RAW_POWER_REACT64R
This is the raw reactive power. This register is read during the calibration for calculating
the gain values associated with the reactive power and GAIN_POWER_REACT. This
register is overwritten every LINE_CYC line cycle (written only once if calibration is
enabled). This register is accumulated on a line-cycle basis.
3.19POWER_REACT
NameBitsCof
POWER_REACT32R
This is the value for reactive power. The goal is to get this value to equal X VAR/LSB.
This is done with the GAIN_POWER_REACT register. When displaying the power,
multiply the (decimal) value in this register by X to get the display value in watts. This
register is overwritten every LINE_CYC line cycle (written only once if calibration is
enabled).
3.20PERIOD
NameBitsCof
PERIOD32R
This 32-bit register represents the total number of clock ticks that elapsed over the most
recent LINE_CYC line cycle. Each LSB represents 1.6 µs with a 4 MHz clock on the
microcontroller. This register is overwritten every LINE_CYC line cycle (written only
once if calibration is enabled).
3.21ENERGY_ACT
NameBitsCof
ENERGY_ACT32R
RAW_ENERGY_ACT64R
The design updates the Energy register using the CF Pulse blink output count. In this
method, the Energy registers increments every pulse by a value equal to
1/(METER_CONSTANT).
ENERGY_ACT = ENERGY_ACT + (1/METER_CONSTANT)
The gain calibration registers GAIN_NUMR_ENERGY_ACT and
GAIN_DENR_ENERGY_ACT operate the same for this method also.
These two registers represent the total apparent energy accumulated so far.
3.23I_ABS_MAX
NameBitsCof
I_ABS_MAX8R
NOT IMPLEMENTED IN THIS FIRMWARE/SOFTWARE RELEASE.
3.24V_ABS_MAX
NameBitsCof
V_ABS_MAX8R/W
NOT IMPLEMENTED IN THIS FIRMWARE/SOFTWARE RELEASE.
3.25ENERGY_REACT
NameBitsCof
ENERGY_REACT32R
RAW_ENERGY_REACT64R
The design updates the reactive energy register using the CF Pulse blink output. In this
method, the Energy registers increment every pulse by a value equal to
1/(METER_CONSTANT).
ENERGY_REACT = ENERGY_REACT + (1/METER_CONSTANT)
The gain calibration registers GAIN_NUMR_ENERGY_ACT and
GAIN_DENR_ENERGY_ACT operate the same for this method also.
3.26PHASE_COMPENSATION
NameBitsCof
PHASE_COMPENSATION8R/W
Phase delay, signed 8-bit value, provides the phase compensation by sampling time/2.
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
3.27OFFSET_I_RMS
NameBitsCof
OFFSET_I_RMS16R/W
Square of the offset for RMS current reading, signed 16-bit value. Note that this value
should be similar to the ADC’s noise squared. At a gain of 1, the noise will be about
1 LSB, 2 LSBs at a gain of 2, 6 LSBs at a gain of 8, 11 LSBs at a gain of 16, and
22 LSBs at a gain of 32. There may be other sources of noise. Using the square of the
offset allows for higher accuracy. The value will be added before the square root is
taken when calculating the final RMS value.
3.28OFFSET_V_RMS
NameBitsCof
OFFSET_V_RMS16R/W
Square of offset for RMS voltage reading, signed 8-bit value. Note that this value
should be similar to the ADC’s noise squared. For the voltage channel, the noise will
be about 1 LSB. There may be other sources of noise. Using the square of the offset
allows for higher accuracy. The value will be added before the square root is taken
when calculating the final RMS value.
3.29GAIN_I_RMS
NameBitsCof
GAIN_I_RMS16R/W
Current gain to produce X A/LSB. The value is always less than one (for example,
32,767 = 0.9999695).
3.30GAIN_V_RMS
NameBitsCof
GAIN_V_RMS16R/W
Voltage gain to produce 0.1 V/LSB in the V_RMS register. The value is always less than
one (for example, 32,767 = 0.9999695).
3.31OFFSET_POWER_ACT
NameBitsCof
OFFSET_POWER_ACT32R/W
Active power offset (this is a straight offset, not the square, as with voltage and current).
A much larger value is needed because the power is a running sum. This is a 32-bit
signed value.
Active power gain to produce X W/LSB. The value is always less than one (for example,
32,767 = 0.9999695).
3.33OFFSET_POWER_REACT
NameBitsCof
OFFSET_POWER_REACT32R/W
Reactive power offset (this is a straight offset, not the square, as with voltage and current). A much larger value is needed because the power is a running sum. This is a
32-bit signed value.
3.34GAIN_POWER_REACT
NameBitsCof
GAIN_POWER_REACT16R/W
Reactive power gain to produce X W/LSB. The value is always less than one (for example, 32,767 = 0.9999695).
3.35GAIN_ENERGY_ACT
NameBitsCof
GAIN_ENERGY_ACT16R/W
Active energy gain to produce X Wh/LSB. The value is always less than one (for example, 32,767 = 0.9999695).
3.36GAIN_ENERGY_APP
NameBitsCof
GAIN_ENERGY_APP16R/W
Apparent energy gain to produce X VAh/LSB. The value is always less than one (for
example, 32,767 = 0.9999695).
3.37GAIN_ENERGY_REACT
NameBitsCof
GAIN_ENERGY_REACT16R/W
Reactive energy gain to produce X VARh/LSB. The value is always less than one (for
example, 32,767 = 0.9999695).
MCP3901 and PIC18F65J90 Energy Meter Reference De sign
3.38CF_PULSE_WIDTH
NameBitsCof
CF_PULSE_WIDTH8R/W
Defines the CF pulse width from 0 to 255. Length of width is valued
* 8 * (1/LINE_FREQUENCY)/128) ms. A maximum of 0.266 seconds for 60 Hz and
0.319 seconds for 50 Hz.
If the value is 0, no CF pulse is produced.
3.39GAIN_DENR_ENERGY_ACT
NameBitsCof
GAIN_DENR_ENERGY_ACT8R/W
8-bit signed value. Represents the number of shifts for active power energy register
ENERGY_ACT before GAIN_DENR_ENERGY_ACT is applied.
3.40GAIN_NUMR_ENERGY_ACT
NameBitsCof
GAIN_NUMR_ENERGY_ACT16R/W
Active power gain to produce a specified pulses per watt-hour. The value is always less
than one (for example, 32,767 = 0.9999695).
3.41MODE1_DEF
NameBitsCof
MODE1_DEF16R/W
MODE default power-up settings. On power-up, this register will be read and placed
into the MODEregister.
3.42CAL_STATUS
The CAL_STATUS register holds the calibration status for each individual phase.
Broken down by phase, these are the values that can be calibrated. Each bit has the
status of 0 = NOT Calibrated, 1 =Calibrated.
The Universal Asynchronous Receiver/Transmitter (UART) of the PIC18F65J90 is
used to access the register map of the meter. In addition to the reading and writing of
the registers, there are also dedicated commands for clearing calibration registers,
loading calibration registers and storing calibration registers to flash. The first byte
UART data is an ASCII character that represents the command, and each command
has a specific protocol. Each command ends with the ASCII character “X”.
4.1.1Command Description
The first byte of the data (byte 0) is an ASCII character E, L, S, W and R.
• E – Echo All Data Received (ECHO)
• L – Load Calibration Registers from Flash (LOAD)
• S – Store Calibration Registers (STORE)
• W – Write Bytes (WRITE)
• R – Read Bytes (READ)
The last data byte is always an 'X' character. All commands will result in the same
command being returned. The exception is the 'R' (read) command which will return
additional data in lieu of the number of bytes.
MCP3901 AND PIC18F65J90
ENERGY METER
REFERENCE DESIGN
4.1.1.1“E” ECHO: - ECHO ALL DATA RECEIVED
Example: 'EABCDEFGHIJKLMNOPQRSTUVWYZ1234567890X'.
Returns: 'EABCDEFGHIJKLMNOPQRSTUVWYZ1234567890X'.
4.1.1.2“L” LOAD: LOAD CALIBRATION REGISTERS FROM FLASH.
Example: 'LX'.
Returns: 'LX'.
This command is used to verify that the calibration values were actually written into
flash (or E EPROM) . Once the so f twa re exe cut es a 'SX' comman d, it shou ld v erif y th at
the values were stored by issuing an 'LX' command and then reading the calibration
values with a 'R' command.
4.1.1.3“S” STORE: STORE CALIBRATION REGISTERS INTO FLASH
Note that the store command will write all calibration values to internal EEPROM, and
this function takes some time. During that time, the meter is not functional. The store
command should only be used after calibrating the meter, and not while it is in actual
use.