00220awatt meter
DESCRIPTION
Application NoteTRANSCRIPT
-
AN220
OVERVIEWThis application note shows how to use a PIC16C923microcontroller to control operation of the CS5460power measurement integrated circuit from CirrusLogic/Crystal Power Measurement, to drive a liquidcrystal panel (glass), and to store and retrieve datausing the 24C01 Serial EEPROM.Energy transferred between the line and load is mea-sured by the CS5460. The PIC16C923 initializes theCS5460 with calibration data stored in the 24C01Serial EEPROM, records the total energy measured inthe 24C01, and displays results on the LCD panel.
INTRODUCTIONMost forms of AC power measurement have alreadybeen patented by various companies, so measuringAC power in a product intended for sale often involvespaying licensing fees to another company. TheCS5460 offers an integrated solution that provides apower and energy measurement sub-system, requir-ing only voltage and current sense inputs. In addition,calibration is accurate for any current waveform orpower factor that may be encountered.By using the CS5460, a PIC16C923 microcontroller, a24C01 Serial EEPROM, and an LCD panel, a simpleand compact device is constructed that displays RMSvoltage, RMS current, and the energy consumed by aload. These features are extended by including com-putation and display of apparent power, true power,and power factor.The PIC16C923 LCD controller can drive an LCD panelwith up to 4 common planes and up to 32 segments. 4Kwords of program memory, and 176 bytes of RAM areprovided. A Synchronous Serial Peripheral (SSP) pro-vides SPITM communications with the CS5460.Inter-Integrated CircuitTM (I2C) communications with the24C01 Serial EEPROM are provided by firmware.
FIGURE 1: WATT-HOUR METER
HARDWAREOn power-up, the PIC16C923 microcontroller readsthe calibration data, device serial number, and totalenergy from the 24C01, writes the calibration data tothe CS5460, initializes the CS5460, and reads thestate of the control buttons. If the control button state matches one of three pat-terns at RESET, a control mode is entered that allowssetting the real time clock (RTC), clearing the totalWHr and restoring default calibration values, or adjust-ing calibration constants.During normal operation, the PIC16C923 countspulses from the CS5460, reads CS5460 data regis-ters, drives the LCD panel to display the requesteddata, and monitors the control buttons. The pulses areused to update the total energy count and are periodi-cally written to the 24C01.The CS5460 measures line voltage and line current tocompute power and energy transferred on the line.When a unit of energy has transferred between theline and the load, a pulse with direction indication isgenerated.
Authors: Brett Duane, Stephen HumberdMicrochip Technology Inc.
Watt-Hour Meter using PIC16C923 and CS5460 2000 Microchip Technology Inc. DS00220A-page 1
The CS5460 power/energy measurement IC mea-sures instantaneous voltage and current four thousandtimes a second and uses these measurements tocompute VRMS, IRMS, instantaneous power, and accu-mulated energy results for read out. In addition, apulse is generated whenever a user specified amountof energy transfers between the line and the load.
-
AN220
FIGURE 2: SYSTEM BLOCK DIAGRAM
CS5460 Power/Energy Measurement CircuitThe CS5460 measures the instantaneous line voltageand line current, four thousand times a second. Thesemeasurements are used to compute instantaneouspower, energy transferred since the last measurement,RMS voltage, RMS current, and accumulated energytransferred. All measurements and results can be readby an external controller, via the SPI interface. A trans-fer of energy is also indicated by a pulse output at theEOUT pin. The direction of transfer is indicated by theEDIR pin.Communication with the CS5460 takes place over a4-wire SPI link with the PIC16C923. The CS5460 isconfigured and controlled over this link. Calculationresults are also read by the controller over this link.The line voltage may be sampled using a transformeror resistor divider. The differential input is limited to150mVRMS. In this application, line voltage is detectedfrom the secondary winding of the power supply trans-former, T2 (see Figure 3B and Figure 5). When oper-ating from 120V, there is about an 8V peak at VIN+ orVIN-. When operating from 220V, there is about a14.7V peak. This voltage is further reduced by a resis-tor network before being applied to the CS5460 (seeFigure 4A).The line current may be sampled using a currenttransformer or shunt resistor. Depending on the gain ofthe input channel, the differential input is limited toeither 30 mVRMS (gain = 50), or 150 mVRMS(gain = 10). In this application, the current channelgain is 10, for a maximum input voltage of 150 mVRMS.This voltage is provided by the current sense trans-former T1 and resistor R21, and is reduced by a resis-tor network similar to the line voltage channel (seeFigure 3A and Figure 4B).
There is no switching provided, or required for opera-tion from either 120V or 220V, 50Hz or 60Hz. How-ever, accuracy will decrease when operating from aline voltage different than the calibration conditions.By using the instantaneous voltage and current, theCS5460 computes the RMS voltage, RMS current,and instantaneous power. The instantaneous power isintegrated at the sampling rate (4000Hz) to computethe energy transferred. A new RMS value is availableevery 4000 samples. Samples are taken 4000 timesper second, or about 67 times per 60Hz cycle.When the integrated energy exceeds 10 WSec, a fixedwidth pulse is generated at the EOUT pin and the inte-grated energy is reduced by 10 WSec. These pulsesare counted to record energy consumption. The EDIRpin indicates the direction that the energy flows (reac-tive loads can return energy to the line). Depending onthe state of the EDIR pin, the pulse at the EOUT pincauses the PIC16C923 to either increment, or decre-ment the total energy count.
FIGURE 3: CIRCUITS THAT MONITOR LINE CURRENT (A) AND LINE VOLTAGE (B)
CURRENT LNG
LNG
CS5460
BUTTONS LCD
VOLTAGESENSE
24C01 PIC16C923
SENSE
SOURCE LOAD
GROUND
NEUTRAL
LINE
T2
T1
R21IIN+
VIN+
VIN-
LINE
NEUTRAL
3A
3B
D1
D2
56, WDS00220A-page 2 2000 Microchip Technology Inc.
-
AN220
FIGURE 4: CS5460 INPUT ATTENUATION
CIRCUITS
Power SupplyA transformer isolated power supply provides powerfor the Watt-Hour Meter. The transformer primary isconnected to the line between the power source andthe current sense transformer. The AC voltage fromthe transformer secondary is used to detect the linevoltage and is coupled to the CS5460 through a resis-tor network (see Figure 4A).The AC from the center tapped secondary is full waverectified, filtered, and provided to the 5V regulator. The5V loads are the power-on LED, the CS5460, andthe PIC16C923. The majority of the current is drawnby the LED, about 7.5mA. The rest of the circuit drawsless than 5mA.
FIGURE 5: POWER SUPPLY CIRCUIT
PIC16C923 MicrocontrollerThe PIC16C923 microcontroller provides a LiquidCrystal Display (LCD) driver module that drives theLCD panel directly. It also communicates with theCS5460 using the 4-wire SPI link (SDI, SDO, SCL,and CS) to issue commands, write calibration data,and read measurement and calculation results. Themicrocontroller also controls the CS5460 RESET line(see Figure 6).The controller system oscillator is driven by theCPUCLK output of the CS5460 and operates at4.096MHz. The system oscillator is configured for XTmode, but any crystal mode will work. A 32.768kHzcrystal has been provided for use with the Timer1oscillator. Since the CS5460 provides a 4.096MHzclock source to the PIC16C923, either source can beused for the real time clock source. The demonstrationunits have been configured to use the CS5460 clocksource for the real time clock.
FIGURE 6: CONNECTIONS BETWEEN THE CS5460 AND THE PIC16C923
R11
VIN-R12
VIN+R10 R25
C24C25
9 VIN+
10 VIN-R23
C15 CS5460
4A
CS5460R9
R20
15 IIN-
IIN+R22
C14
4B
IIN+ 16
100k
100k
1k
301
301
0.01F 0.01F
4700pF
0.015F
180k
10k
301
T2VIN+
VIN-
LINE
NEUTRAL C13 C12
D1
D2
78L05I
GO +5V
U4
0.1F1000F
C21
+5V
SDO
EDIR
EOUT
RESET
CS
CPUCLK
SCLK
SDI
CS
RESET
SCLK
SDO
CPUCLK
SDI
EDIR
EOUT
NC
10
12
13
14
15
16
2425
9 8 7
PIC16C923
RA4RB1
RB0
RC3RC4RC5OSC1OSC225
RA2
U1
22
23
21
19
241
CPUCLKSDI
XIN
EDIR
EOUTRESET
SDO
SCLK
CS
XOUT2
5
6
7
U2CS5460
R19
4.096MHZ
0.1F
10k 2000 Microchip Technology Inc. DS00220A-page 3
-
AN220
Interface to 24C01 Serial EEPROMThe Serial EEPROM stores the calibration constantsrequired by the CS5460 for accurate measurements,and the total accumulated energy transferred. Thecontroller communicates with the 24C01 via an I2Cinterface. Since the SSP module is already in use sup-porting SPI communications with the CS5460, thePIC16C923 must perform I2C communications in firm-ware, using RA0 (SCL) and RA1 (SDA) (see Figure 7).Either the 24C01, or the PIC16C923, may pull theSDA line low, depending on the direction of the dataflow. Since the PIC16C923 always drives the SCL line,no pull-up resistor was included. A memory map of theSerial EEPROM is included in Appendix A.
FIGURE 7: CONNECTION BETWEEN THE 24C01 AND THE PIC16C923
User InterfaceThe user interface consists of the LCD display, fourcontrol push buttons, one reset push button, and thepower-on LED.The PIC16C923 LCD module directly drives the LCDpanel. The panel can display eight, 7-segment digits(numbers only), seven decimal points and three colons.When pushed, each of the four push buttons pull therespective port pin low. The buttons are connected toPORTB and are numbered from 1 to 4, left to right.
FIRMWAREThe CS5460 transfers data in 4 byte groups (32-bits).The first byte contains the register address and a bitspecifying a read or write operation. The remaining 3bytes are transferred to or from one of the internal reg-isters. The CS5460 also accepts single byte com-mands. Such commands are followed by 3 SYNCbytes that are treated as NOP bytes.A write command is followed by 3 bytes of data to theCS5460, to be written to the selected register. A readcommand causes the 3 bytes of the selected registerto be output by the CS5460. If the command byte specifies an operation to be per-formed, or a read operation, the remaining 3 bytestransmitted by the PIC16C923 should be SYNC0bytes (0xFE).
Power-up and RESETA Power-on Reset initializes the CS5460 and clearsthe real time clock. Initialize On-Chip PeripheralsTimer1, Timer2, the SSP, and Ports A, B, and C areconfigured for operation. Interrupts are also enabled.The LCD module is then configured.Clear the LCD DisplayAll segment data registers are cleared to blank the dis-play. This routine is called frequently during normaloperation.Initialize VariablesIf this was a cold start (power has just been applied),the memory contents are cleared and the calibrationconstants are copied from the 24C01 to the CS5460.The device serial number and the current total WHrare retrieved from the 24C01. If a warm start hasoccurred, only the serial number is retrieved.Initialize the CS5460The CS5460 is configured to generate a pulse at theEOUT pin for each 10 WSec measured (360 pulsesper WHr). For 100W loads, this causes 10 pulses persecond to be generated.Check Button StatusThe status of the four push buttons is checked. If allfour buttons are pressed, the total WHr value in the24C01 is cleared and calibration values are copiedfrom the EEPROM to the CS5460. If the center twobuttons are pressed, the real time clock is set. If theouter two buttons are pressed, the Watt-Hour meterenters Calibration mode (see Table 1). If no buttonsare pressed, the CS5460 begins continuous measure-ments. Execution proceeds to the scrolling start-upmessage.
TABLE 1: BUTTON STATES CHECKED DURING RESET
Display the Start-up MessageA start-up message is displayed on the LCD. Thismessage scrolls across the display until any of the fourbuttons is pressed. This message displays the devicename and serial number.
C21
+5V
SCL
SCL
9 5
PIC16C923
RA1
U1
6
7
5
1
A0
A1
A2WP
SCL
GND
VCC2
3
6
4
U324C01
R3
RA0
SDA
+5V SDA SDA8
0.1F
4.7k
ButtonsControl Mode
1 2 3 4
X X X X Clear WHr, restore calibration values
X X Set Clock
X X CalibrationDS00220A-page 4 2000 Microchip Technology Inc.
-
AN220
Normal OperationResults of the various calculations are displayed onthe LCD. Each result is displayed for two seconds withan update after one second. If no buttons are pressed,the next mode is displayed. Holding any button keepsthe display in the present mode, for as long as the but-ton is held. New results will be displayed each second(see Table 2). TABLE 2: DISPLAY MODES
TimeThe first result displayed is the time of day in the formHH:MM:SS. If the time of day was not set at RESET,this indicates the time since power-up (days are notrecorded).RMS VoltageThe RMS voltage is computed by reading the RMSvoltage value from the CS5460. This is a 24-bit valuewith a range of 0.000 to 1.000, representing a fractionof the full scale voltage. The 16 most significant bitsare multiplied by the full scale voltage (as 16-bits) toproduce the actual RMS voltage on the line, as a16-bit binary number. This is converted to a 5 digitpacked BCD number. The LCD display is blanked andE and the appropriate decimal point are displayed.The packed BCD number is then displayed, afterdetermining which digits (leading zeros) should remainblank.After one second, the value is updated and displayedagain. After another second, execution proceeds tothe next mode if no buttons were pressed. If a buttonwas pressed, the two-second counter that controlswhen the next subroutine should be executed iscleared, extending the time that the value is displayed.This code is repeated in all display subroutines.RMS CurrentThe RMS current is computed and displayed similar tothe RMS voltage. The only differences are the fullscale current is used, a C is displayed and a differentdecimal point is turned on. The button state is againchecked to see if execution should remain in this sub-routine.
Apparent PowerThe apparent power is computed in a subroutine(CalcAP), called by both the apparent power loop(APLoop) and the power factor loop (PFLoop). Theapparent power is computed by reading the RMS volt-age and RMS current from the CS5460, as before.The 16 most significant bits of each are multipliedtogether, giving a 32-bit result. The 16 most significantbits of the result are multiplied with the full scaleapparent power (16-bits) to get the actual apparentpower in volt amps in binary. The 16 most significantbits are returned for use by the calling subroutines.APLoop then converts the apparent power in binary(16-bits) to a 5-digit packed BCD number for display.The LCD display is blanked, AP is displayed andafter determining which digits should remain blanked(leading zeros), the apparent power is displayed. Thebuttons are again checked, as before, to determine ifexecution should remain in this subroutine.True PowerThe CS5460 was programmed to generate a pulsewhenever 10 WSec of energy has been transferred.For a 250W load, 25 pulses each second will be gen-erated. These pulses have been processed in an Inter-rupt Service Routine. When 360 pulses have beenaccumulated, 3600 WSec or 1 WHr has been trans-ferred. The total WHr is then incremented. The pulsecount is also recorded for each second.The apparent power is computed in a subroutine(CalcTP), called by both the true power loop(TPLoop) and the power factor loop (PFLoop). Cal-cTP multiplies the number of pulses received duringthe last second by 10 to compute the true power con-sumed by the load. The result is returned as the truepower in watts as a 16-bit binary number.TPLoop converts and displays the true power in thesame way as APLoop displays apparent power. Theonly difference is that TP is displayed instead ofAP. The buttons are again checked as before todetermine if execution should remain in this subrou-tine.Power Factor (PF)The power factor is computed by calling the CalcAPsubroutine to get apparent power in volt amps andthe CalcTP subroutine to get true power in watts. Thetrue power is divided by the apparent power to get thepower factor as a binary result, in the range of 0.000 to1.000. The binary power factor is multiplied by 1000and converted to a BCD number for display. Theappropriate decimal point is turned on.The buttons are checked as before to determine ifexecution should remain in the power factorsubroutine.
Display Value Displayed
HH:MM:SS Time
E RMS Voltage
C RMS Current
AP Apparent Power
TP True Power
PF Power Factor
Hr Total WHr 2000 Microchip Technology Inc. DS00220A-page 5
-
AN220
If apparent power is equal to 0, there is no load(IRMS = 0). This can result in a division by zero condi-tion. If a division by zero is detected, a PF of 1.000 isreported.The calculated power factor can also greatly exceed1.0. When this occurs, the power factor is reported asbeing 1.000. This occurs when the load characteristicsare rapidly changing (as when a motor is starting). Allthe measurements are not taken at exactly the sametime and the RMS values are calculated over a onesecond period. When the load reaches a steady statecondition, the power factor will again be correct.Energy (Watt-Hours)The WHLoop simply displays the WHr counter value.The binary count is converted to BCD. The BCD num-ber is then displayed with leading zeros blanked, usingthe same subroutine used by the apparent power andtrue power displays. The WHr counter is 16-bits long,allowing a maximum of 65,535 WHr to be displayed.When this count is exceeded, the count rolls over to 0.
Control ModesIf any of the three control modes was selected duringRESET, execution branches to one of these modulesto control how the Watt-Hour meter functions.When the control mode is terminated, a warm startRESET is executed.Calibrating the Watt-Hour MeterThe user is given the opportunity to adjust the calibra-tion constants. These constants will not be stored to the24C01. When reset, using the reset button, the calibra-tion values entered in the Calibrate mode will be usedfor making measurements and operation will resume asnormal, except that the new calibration values are used.If reset by removing power, or reset while pressing allfour buttons (clear total WHr), the constants stored inthe 24C01 will be used for operation.Enter Calibration mode by holding the two outer but-tons while pressing the reset button. The first threedigits display CAL, and the remaining digits indicatewhich constant is being adjusted. CAL EOFF will bedisplayed first. This indicates that the value displayedthe next time button 2 is pressed, will be the calibrationconstant for the voltage offset. Pressing button 2 againdisplays the constants value.The decimal point is next to the digit to be modified.Pressing button 3 will move the decimal point to thenext digit to the right. Pressing button 4 will incrementthat digit. Each digit will cycle from 0 to F, then back to0. Only that digit will be affected. Pressing button 1 atany time will cause the value for that constant to besent to the CS5460 and display the next constantname. See Table 3 for button functions.
TABLE 3: CALIBRATION MODE BUTTON FUNCTIONS
Table 4 shows the constant names and typical values.It is essential that the offsets be minimized before set-ting the gains.To set the offsets, remove AC power from theWatt-Hour meter and apply DC power of 8 to 12 VDCto C13. Adjust the offset constants for minimum RMSresults (there is a null in both the current and voltagechannels). Record the offsets.Apply AC power to the Watt-Hour meter and removethe DC power from C13. Applying power in this orderprevents a loss of power to the CS5460. If power islost, reenter the offset values before adjusting the gainvalues. Apply a known resistive load to the Watt-Hourmeter output. Adjust the voltage and current gain con-stants so the indicated RMS voltage and currentmatch the actual load voltage and current. Adjust thepulse rate gain so the indicated true power matchesthe actual load power. Record the gain constants.Resetting the device now uses the constants justfound. If the total Watt-Hours is cleared, the originalconstants will be restored.The software was designed for demonstration pur-poses; therefore, the calibration constants cannot bewritten to the serial EEPROM. If desired, the user canmodify the code to write the new calibration constantsto the EEPROM.
ButtonFunction
1 2 3 4
X Writes constant to CS5460 and displays next constant name
X Displays each constant name and its value in turn
X Selects next digit and moves decimal point
X Increments selected digitDS00220A-page 6 2000 Microchip Technology Inc.
-
AN220
TABLE 4: CALIBRATION MODE INDICATIONS, CONSTANT AND TYPICAL VALUES
Clear Total Watt-HoursThis option causes the total WHr to be cleared fromthe 24C01 and RAM, and copies calibration datastored in the 24C01 back to the CS5460. The wordCLEAR is displayed until the buttons are released.Setting the Real Time ClockCL is displayed in the two digits at the left edge of thedisplay. The current time is displayed in the remainingsix digits.If buttons 2 and 4 are pressed together, the hours areincremented. If buttons 3 and 4 are pressed, the min-utes are incremented. If the minutes roll over from 59to 0, the hours will not be affected. If button 1 ispressed, CL is cleared from the display and execu-tion proceeds to the main loop. Pressing Button 2, 3,or 4 alone has no effect (see Table 5).TABLE 5: CLOCK SET MODE BUTTON
FUNCTIONS
POSSIBLE ENHANCEMENTSAn idea to simplify the calibration process is pre-sented, along with ideas for adding a battery backupand event logging.Power FactorAs reactive loads draw current out of phase with theline voltage, there is an associated phase angle. Thecosine of this angle provides the power factor.The power factor will never exceed 1.000. Resistiveloads will show a very high power factor, while reactiveloads, such as motors, will show lower power factors.Loads with great harmonic content (such as mostpower supplies) will also indicate a low power factor.Power Factor Correcting (PFC) loads will indicate veryhigh power factors.
CalibrationThe calibration process assumes the user has the timeand understanding to determine the calibration con-stants. This process can be greatly simplified. TheCS5460 has the capability of determining offsets andgains. By commanding the CS5460 to perform an off-set calibration, the offset constants can be found veryquickly. The calibration program would indicate themeasured value being calibrated and allow the user toadjust the constant, without actually having to knowwhat the constant was. When a satisfactory measure-ment is achieved, the constant would then be writtento the 24C01.The code presented in this application note almostcompletely fills the first code page of the PIC16C923.The second code page could be dedicated to a cali-bration program.Battery BackupSome users may wish to have the real time clock con-tinue to run, even during a loss of power. Thisbecomes possible by adding a backup battery topower the PIC16C923 and allow the Timer1 oscillatorto operate. This would be the time base for the realtime clock. The code to use Timer1 and its oscillatorhas been included. To extend the life of the battery, itwould power only the PIC16C923.Event LoggingThe 24C01 provides 128 bytes of non-volatileEEPROM memory. Currently, only 17 bytes are usedfor storing calibration data, total energy, and a deviceserial number. The remaining memory could be usedto record power line events, such as black-outs,brown-outs, surges and load peaks. With a real timeclock, the times of these events could also berecorded. Recording black-outs and brown-outs wouldrequire that the backup battery also power the 24C01.
Indication Constant Calibration Value(120V, 10A) CS5460 Default
EOFF Voltage Offset 0x00CCBB = +0.00624 0x000000 = 0.00000COFF Current Offset 0xFEB320 = -0.01015 0x000000 = 0.00000E GA Voltage Gain 0x2C2F62 = 0.69039 0x400000 = 1.00000C GA Current Gain 0x298610 = 0.64917 0x400000 = 1.00000P GA Pulse Rate Gain 0x01FEF2 = 510.95 0x0FA000 = 4000.000
ButtonFunction
1 2 3 4
X Done setting clock
X X Increment hours
X X Increment minutes 2000 Microchip Technology Inc. DS00220A-page 7
-
AN220
APPENDIX A: EEPROM DATA MAP APPENDIX B: SOURCES
The LCD routines came from PICDEM-3TM. Adjust-ments may have been made to the segment and com-mon definitions to account for the use of a differentLCD panel than was used in PICDEM-3.The BIN2BCD routine is loosely based on theB2_BCD_Looped routine in BCD.ASM of applicationnote AN544. This function was originally written for thePIC17CXXX family, but it has been modified for thePIC16CXXX family.The multiply and divide math routines were copiedfrom application note AN617.The data sheet for the PIC16C923 can be found athttp://www.microchip.com. Search for DS30444E orPIC16C923.The data sheet for the 24C01 can be found athttp://www.microchip.com. Search for DS20071J or24C01.The data sheet for the CS5460 can be found athttp://www.crystal.com. Search for DS279PP3 orCS5460.
Address Description
0x00 Device Serial Number
0x01 Voltage Offset MSB
0x02 Voltage Offset
0x03 Voltage Offset LSB
0x04 Current Offset MSB
0x05 Current Offset
0x06 Current Offset LSB
0x07 Voltage Gain MSB
0x08 Voltage Gain
0x09 Voltage Gain LSB
0x0A Current Gain MSB
0x0B Current Gain
0x0C Current Gain LSB
0x0D Watt-Hour MSB
0x0E Watt-Hour LSB
0x0F Pulse Rate Gain MSB
0x10 Pulse Rate Gain
0x11 Pulse Rate Gain LSBDS00220A-page 8 2000 Microchip Technology Inc.
-
AN220
APPENDIX C: SCHEMATICS
FIGURE C-1: PIC16C923 CONNECTIONS
32.768kHZ
Y1
33pF
C2C1
33pF .47F
C3 R1124k
12 RB113 RB014 RC315 RC416 RC517 C118 C219 VLCD220 VLCD321 AVDD22 VDD23 VSS24 OSC1
10 RA4
25 OSC226 RC0
59RG658RG557RG456RG355RG254RG153RG052RG751RF750RF649RF548RF447RF346RF245RF1
60RD5
44RF0
11 RA5
U116C923PLCC
CPUCLK
+5V
C5.47F
C6 .47FC7 .47FC8 .1F
SEG14SEG13SEG12
SEG19SEG18SEG17SEG16SEG15
SEG20
COM3
432
1S1
SCLK
SDOSDI
RB4RB5
RESET
COM2
SEG25SEG24SEG23SEG22SEG21
SEG26
+5V
RB7RB6
EOUT
R210k
C4
.1F
C10
.1F
+5V
COM1
8R
A27
VSS
6R
A15
RA0
4R
B23
RB3
2M
CLR
1N
C68
RB4
67R
B566
RB7
65R
B664
V DD
63CO
M0
62R
D7
9R
A3
61R
D6
29VL
CD1
30VL
CDAD
J31
RD
032
RD
133
RD
234
RD
335
RD
436
RE7
37R
E038
RE1
39R
E240
RE3
41R
E4
27R
C1
42R
E543
RE6
28R
C2
SEG
00SE
G01
SEG
02SE
G03
SEG
04
SEG
05SE
G06
SEG
07SE
G08
SEG
09SE
G10
SEG
11
EDIR
CSSDASCL
RESET
TOCS5460
TO CS5460
TO 24C01FROM BUTTONS
NC 2000 Microchip Technology Inc. DS00220A-page 9
-
AN220
FIGURE C-2: LCD, 24C01, PUSH BUTTONS
432
1PB1
+5V
432
1
+5V
RB4 RB5 432
1
+5V
432
1
+5V
RB6 RB7
R1410k
R1510k
R1610k
R1710k
C17
.1F
C18
.1F
C19
.1F
C20
.1F
+5V
C11.1F
5SDA1A02A13A24 GND
7 WP
6 SCL
8 VCCU3
24C01
+5V
R34.7k
LCD DISPLAY
LCD1
SEG19
SEG21
SEG15
SEG13
SEG10
SEG07
SEG04
SEG01
SEG20SEG18SEG22SEG17SEG26SEG16SEG14SEG23SEG12SEG25SEG11SEG09SEG08SEG06SEG24SEG05SEG03SEG02SEG00
1
234
567
8
91011
1213
141516
17
181920
21
22
414039
383736
35
3433323130
292827
26252423
42COM3 COM3
COM2COM1
COM2COM18F, 8E
1B, 1CNC2B, 2C, 1DPNCNC3B, 3C, 2DPNCNC4B, 4C, 3DPNCNC5B, 5C, 4DPNCNC6B, 6C, 5DPNCNC7B, 7C, 6DPNC8B, 8C,7DP
8A, 8G, 8D7F, 7E
7A, 7G, 7D6L
6F, 6E6A, 6G, 6D
5F, 5E
5A, 5G, 5D4L
4F, 4E4A, 4G, 4D
3F, 3E
3A, 3G, 3D2L
2F, 2E2A, 2G, 2D
1F, 1E
1A, 1G, 1D
PB2 PB3 PB4
SDASCLDS00220A-page 10 2000 Microchip Technology Inc.
-
AN220
FIGURE C-3: POWER SUPPLY, VOLTAGE SENSE, CURRENT SENSE
VIN
R18470
D4
3 IN 1OUT
U4LM7805-TO92
C13
1000F
T2
TRANS-2102
R8
VIN+
VIN-
C12
.1F
D21N914
D1
1N914
1 L2 G3 N
J2
IEC_F
R21
56, 1/2 W
T11J8
1J7
1J6
1L2G3N
J1
IEC_M1 J3
1 J4
1 J5 12 GA Wire
IIN+
GND2
+5 VREG
MOV
LOADSOURCE 2000 Microchip Technology Inc. DS00220A-page 11
-
AN220
FIGURE C-4: CS5460 CONNECTIONS
R11
1 k
R910k
IIN+VIN-
180k
R20 R12
100k(1)
VIN+100k(1)
R10
+5V
CPUCLK301
R25.01F
C24C25
.01F
10
R6
C16
.1F
R2610k
SCLK
CSSDOSDI
Y2
4.096MHz
EOUT
9 VIN+
12 VREFIN11 VREFOUT
13
VA-
4
DGND
21EOUT
22EDIR
20INT
5SCLK
6SDO
23SDI
7CS
19RESET
24XIN
1XOUT
2CPUCLK
17PFMON
3VD+
14VA+
15 IIN-
10 VIN-16 IIN+
U2
CS5460
RA4
+5V301R22
R23 301
C15
4700pF
R1910k
C9
.1F
C21
.1F
C14
0.015F
R2410k
+5 VREG
EDIR
VIN
Note: R10 and R12 are 121 kOhms for 220V Watt-Hour meters.DS00220A-page 12 2000 Microchip Technology Inc.
-
AN220
APPENDIX D: BILL OF MATERIALS
Cnt Component Name RefDes Description Digikey2 1N4001 D1-2 IN4001DICT-ND1 16C923PLCC U1 PIC16C924 (Microchip)1 SOCKET U1 A2144-ND1 24C01_TSOP U3 24CO1-BC (Microchip)2 CAP150 C1-2 33pF Capacitor P4843-ND12 CAP0805 C4, C8-12,
C16-21.1F Capacitor PCC1864CT-ND
2 CAP1206 C24-25 .01F Capacitor PCC103BCT-ND4 CAP1206 C3, C5-7 .47F Capacitor PCC1891CT-ND1 CAP1206 C15 4700pF Capacitor PCC472BCT-ND1 CAP1206 C14 15000pF Capacitor PCC153BCT-ND1 CAP-RAD400D C13 1000F Capacitor P5142-ND1 CRYSTAL Y2 4.096MHz Crystal X082-ND1 CRYSTAL_32KHZ Y1 32kHz Crystal SE3201-ND1 CS5460 U2 CS4560 (Crystal Semiconductor)1 CSE187-L T1 Current Transformer 10515-ND1 IEC_F J2 Socket 509-1271 (Allied)1 IEC_M J1 Plug 509-1269 (Allied)1 LCD_VIM-808-DP LCD1 VIM-808-DP-RC-S-HV 153-1057-ND1 LED_SMT D4 LED, Green LT1120CT-ND1 LM7805-TO92 U4 Voltage Regulator NJM78L05A-ND1 MOV R8 MOV P7259-ND1 RES600 R21 56 1/2W Resistor 56H-ND1 RES1206 R11 1k Resistor P1.0KECT-ND1 RES1206 R3 4.7k Resistor P4.7KECT-ND1 RES1206 R6 10 Resistor P10ECT-ND9 RES1206 R2, R9,
R14-17, R19, R24, R26
10k Resistor P10KECT-ND
1 RES1206 R1 124k Resistor P124KFCT-ND1 RES1206 R20 121k Resistor P121KFCT-ND3 RES1206 R22-23, R25 301 Resistor P300ECT-ND1 RES1206 R18 470 Resistor P470ECT-ND2 RES1206 R10, R12 100k Resistor P100KECT-ND5 SW-B3F1000 S1, PB1-4 SW404-ND5 KEY CAP S1, PB1-4 SW450-ND1 TRANS-2102 T2 Transformer 12 VAC/0.09 A MT2113-ND1 Plastic case 141840 (Jameco)1 Printed Circuit BoardMisc:4 4-40 X 3/8 machine screw for J1, J24 4-40 hex nut2 ft 12 ga stranded copper wire1 20-pin machined pin IC socket to cut up for pin extensions for S1-S5 2000 Microchip Technology Inc. DS00220A-page 13
-
AN220APP
END
IX E
:SO
URCE
CO
DE
MPASM 02
.30.
11 Intermedi
ate
WAT
T_MT
R.AS
M
5-25
-200
0 1
3:31
:13 PAGE 1
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00
001
l
ist
st
=off
;
sup
pres
s li
st f
ile
symb
ol t
able
00
002
l
ist
n=
0 ; suppress li
st f
ile
page
bre
aks
00
003
00
004
;***
****
****
****
****
****
****
****
************************************
00
005
; Co
nfig
urat
ion
swit
ches
. Th
ese
control
what
cod
e is
ass
embl
ed.
00
006
00
007
;
Sele
ct t
he d
esir
ed o
pera
ting
volta
ge b
y co
mmen
ting
out
all
but
00
008
;
the
desi
red
volt
age
rang
e 00
009
#
defi
ne
VO
LT120
;
120
V no
mina
l fu
ll s
cale
ran
ge 00
010
;
#
defi
ne
VO
LT220
;
220
V no
mina
l fu
ll s
cale
ran
ge 00
011
00
012
;
Sele
cts
the
real
tim
e cl
ock
frequency source,
00
013
;
#
defi
ne
TM
R1OSC ; de
fine
d if
usi
ng 3
2kHz
T1O
SC,
comm
ent out if
ano
ther
RTC source
00
014
00
015
;***
****
****
****
****
****
****
****
*****************************
00
016
; So
ftwa
re L
icen
se A
gree
ment
00
017
; 00
018
; Th
e so
ftwa
re s
uppl
ied
here
with
by Mic
roch
ip T
echn
olog
y In
corp
orat
ed (
the
00
019
; "C
ompa
ny")
for
its
PIC
micr
o M
icrocontroll
er i
s in
tend
ed a
nd s
uppl
ied
to
Softw
are
Lice
nse
A
gree
men
tTh
e so
ftwa
re s
upp
lied
here
with
by
Mic
roch
ip T
ech
nolo
gy I
nco
rpor
ate
d (th
e Co
mpa
ny) f
or
its P
ICm
icro
M
icro
con
trolle
r is
inte
nde
d an
d su
pplie
d to
yo
u, th
e C
ompa
nys
cu
sto
me
r, fo
r u
se s
ole
ly an
d e
xclu
sive
ly on
Mic
roch
ip P
ICm
icro
M
icro
con
trolle
r pro
d-u
cts.
The
softw
are
is o
wn
ed
by th
e C
om
pany
a
nd/
or
its su
pplie
r, a
nd
is pr
ote
cte
d un
der a
pplic
abl
e c
opy
right
la
ws.
Al
l rig
hts
are
re
serv
ed.
Any
use
in vi
olat
ion
of t
he fo
rego
ing
rest
rictio
ns m
ay
subje
ct th
e u
ser
to cr
imin
al s
anct
ion
s u
nde
r app
lica
ble
law
s, a
s w
ell a
s to
ci
vil
liabi
lity fo
r th
e br
each
of t
he te
rms
an
d co
ndi
tion
s o
f thi
s lic
ense
.
THIS
SO
FTW
ARE
IS PR
OVI
DED
IN A
N A
S IS
CO
NDIT
ION.
NO
WAR
RAN
TIES
, W
HET
HER
EXP
RES
S, IM
PLIE
D O
R ST
ATU-
TORY
, IN
CLUD
ING
, BUT
N
OT
LIM
ITED
TO
, IM
PLIE
D W
ARR
ANTI
ES O
F M
ERCH
ANTA
BILI
TY AN
D F
ITN
ESS
FOR
A PA
RTIC
U-LA
R P
UR
POSE
AP
PLY
TO TH
IS SO
FTW
ARE.
TH
E CO
MPA
NY
SHAL
L N
OT,
IN
AN
Y CI
RCUM
STAN
CES,
BE
LI
ABLE
FO
RSP
ECIA
L, IN
CID
ENTA
L O
R CO
NSEQ
UEN
TIAL
DAM
AGES
, FO
R AN
Y R
EASO
N W
HAT
SOEV
ER.DS00220A-page 14 2000 Microchip Technology Inc.
-
AN220 00
020
; yo
u, t
he C
ompa
nys customer, fo
r us
e so
lely
and
excl
usiv
ely
on M
icro
chip
00
021
; PI
Cmic
ro M
icro
cont
roll
er p
rodu
cts.
00
022
; 00
023
; Th
e so
ftwa
re i
s ow
ned
by t
he C
ompa
ny a
nd/o
r its suppli
er,
and
is p
rote
cted
00
024
; un
der
appl
icab
le c
opyr
ight
law
s. A
ll r
ight
s are reserved.
Any
use
in
00
025
; vi
olat
ion
of t
he f
oreg
oing
res
tric
tion
s ma
y subj
ect
the
user
to
crim
inal
00
026
; sa
ncti
ons
unde
r ap
plic
able
law
s, a
s we
ll a
s to civ
il l
iabi
lity
for
the
00
027
; br
each
of
the
term
s an
d co
ndit
ions
of
this
license.
00
028
; 00
029
; TH
IS S
OFTW
ARE
IS P
ROVI
DED
IN A
N "A
S IS
" CO
NDITION. NO WARRANTIES, WHETHER
00
030
; EX
PRES
S, I
MPLI
ED O
R ST
ATUT
ORY,
INC
LUDI
NG,
BUT NOT LIMITED TO, IMPLIED
00
031
; WA
RRAN
TIES
OF
MERC
HANT
ABIL
ITY
AND
FITN
ESS
FOR A PARTICULAR PURPOSE APPLY
00
032
; TO
THI
S SO
FTWA
RE.
THE
COMP
ANY
SHAL
L NO
T, I
N ANY CIRCUMSTANCES, BE LIABLE
00
033
; FO
R SP
ECIA
L, I
NCID
ENTA
L OR
CON
SEQU
ENTI
AL D
AMAGES, FOR ANY REASON WHATSOEVER.
00
034
00
035
00
036
;***
****
****
****
****
****
****
****
****
****
****
*****************
00
037
; Au
thor
: St
ephe
n Hu
mber
d, B
rett
Dua
ne 00
038
; Co
mpan
y: M
icro
chip
Tec
hnol
ogy
Inc.
00
039
; Re
visi
on:
1.1
00
040
; Da
te:
5-15
-200
0 00
041
; As
semb
led
usin
g MP
LAB
4.99
.07,
MPA
SM 2
.30.
11 00
042
;***
****
****
****
****
****
****
****
****
****
****
*****************
00
043
; In
clud
e Fi
les:
CAL
.INC
ca
libr
atio
n co
nstants
00
044
;
PR3
.INC
LC
D se
gmen
t de
finiti
ons
00
045
;
P16
C924
.INC
St
anda
rd M
icro
chip in
clud
e fi
le f
or P
IC16
C923
/924
00
046
;***
****
****
****
****
****
****
****
****
****
****
*****************
00
047
; Th
is p
rogr
am c
ontr
ols
and
read
s da
ta f
rom
The Crystal
CS45
60 00
048
; Si
ngle
Pha
se B
i-Di
rect
iona
l Po
wer/
Ener
gy I
C 00
049
; an
d di
spla
ys i
t on
a e
ight
dig
it L
CD u
sing
the LCD dr
ive
00
050
; fu
ncti
on o
f a
PIC1
6C92
3. 00
051
00
052
; Th
e CS
5460
mea
sure
s li
ne v
olta
ge a
nd c
urre
nt transfe
red
betw
een
00
053
; th
e li
ne (
sour
ce)
and
the
load
. Th
e in
stan
taniou
s vo
ltag
e an
d cu
rren
t 00
054
; me
asur
emen
ts a
re u
sed
to c
ompu
te (
with
in t
he CS54
60)
inst
anta
niou
s po
wer,
00
055
; RM
S vo
ltag
e, R
MS c
urre
nt,
and
accu
mula
ted
energy. All
of
thes
e 00
056
; me
asur
emen
ts a
nd c
alcu
lati
on r
esul
ts a
re a
valibl
e to
the
PIC
16C9
23 v
ia S
PI.
00
057
; 00
058
; Th
e RM
S vo
ltag
e an
d RM
S cu
rren
t ar
e di
spla
yed and
used
to
calc
ulat
e ap
aren
t 00
059
; po
wer.
00
060
; 00
061
; A
puls
e ou
tput
(EO
UT)
on t
he C
S546
0 in
dica
tes whe
n a
prog
rama
ble
amou
t of
00
062
; en
ergy
has
bee
n tr
ansf
erre
d be
twee
n th
e li
ne and
the
load
. An
othe
r ou
tput
00
063
; (E
DIR)
ind
icat
es t
he d
irec
tion
of
that
tra
nsfer (i
f a
load
is
high
ly 00
064
; re
acti
ve,
eneg
ry f
lows
fro
m th
e lo
ad t
o th
e line
). T
hese
pul
ses
are
coun
ted
00
065
; by
the
PIC
16C9
23 t
o me
asur
e an
d di
spla
y to
tal energy transfe
rred
in
Watt
Hour
s 2000 Microchip Technology Inc. DS00220A-page 15
-
AN220
00
066
; 00
067
; Tr
ue p
ower
is
meas
ured
by
coun
ting puls
es f
or 1
sec
ond.
The
CS5
460
has
been
00
068
; pr
ogra
mmed
to
gene
rate
a p
ulse
for each
10Wa
ttSe
cond
s of
ene
rgy
tran
ferr
ed.
00
069
; Th
e pu
lse
coun
t is
mul
tipl
ied
by 10
to c
alcu
late
tru
e po
wer.
00
070
; 00
071
; Ap
aren
t po
wer
and
true
pow
er a
re dis
play
ed,
and
are
used
to
calc
ulat
e th
e 00
072
; po
wer
fact
or o
f th
e lo
ad.
00
073
; 00
074
; Th
e CS
4560
out
puts
a 4
.096
MHz
clock
for
use
by t
he P
IC16
C923
as
the
syst
em 00
075
; cl
ock.
Thi
s co
de o
ffer
s th
e op
tion of
usin
g th
is s
ourc
e as
the
rea
l ti
me c
lock
00
076
; so
urce
wit
h CC
P1 i
n co
mpar
e/in
terrupt only
/spe
cial
eve
nt m
ode,
or
usin
g th
e Ti
mer1
00
077
; os
cill
ator
wit
h a
32.7
68KH
z cr
ystal.
The
har
dwar
e pr
ovid
ed o
n th
e de
mo u
nits
00
078
; su
ppor
ts b
oth
opti
ons.
00
079
; 00
080
; Ev
ery
8 mi
nute
s, t
he c
urre
nt a
ccumula
ted
ener
gy (
WHr)
is
writ
ten
to t
he 2
4C01
00
081
; se
rial
EEP
ROM.
Thi
s sa
ves
the
total
ener
gy d
urin
g ti
mes
when
the
AC
powe
r is
rem
oved.
00
082
; 00
083
; Ca
libr
atio
n co
nsta
nts
are
also
stored
in t
he 2
4C01
. Th
ese
are
read
fro
m th
e 24
C01
00
084
; an
d wr
itte
n ba
ck t
o th
e CS
5460
when power is
rea
ppli
ed,
and
when
the
tot
al e
negy
is
00
085
; cl
eare
d fr
om t
he 2
4C01
. Th
e co
de to read
the
cons
tant
s fr
om c
al.i
nc a
nd w
rite
the
m to
00
086
; th
e 24
C01
has
been
inc
lude
d, b
ut has
bee
n co
mmen
ted
out.
00
087
; 00
088
; On
res
et,
the
PIC1
6C92
3 ch
ecks
the 4
cont
rol
butt
ons
for
3 sp
ecif
ic s
tate
s. O
ne s
tate
00
089
; al
lows
the
use
r to
set
the
tim
e of the
rea
l ti
me c
lock
. An
othe
r st
ate
clea
rs t
he 00
090
; to
tal
WHr
for
the
24C0
1 an
d re
writes the
cal
ibra
tion
con
stan
ts t
o th
e CS
5460
. A
00
091
; th
ird
stat
e al
lows
the
use
r to
adjus
t th
e ca
libr
atio
n co
nsta
nts
in t
he C
S546
0. 00
092
; 00
093
; Wr
itte
n by
Ste
phen
Hum
berd
, Mi
crochi
p Te
chno
logy
10/
08/1
999
00
094
;***
****
****
****
****
****
****
****
*****************************
00
095
; Op
tion
al R
eal
Time
Clo
ck s
ourc
es (T1
OSC
or C
S546
0 CP
UCLK
out
put)
00
096
; Mo
nito
r CS
5460
!ED
IR o
utpu
t. 00
097
; Ch
ange
Pul
se R
ate
from
128
pul
ses/KW
Hr (
1 pu
lse/
28,1
25Ws
ec)
00
098
;
to
1 pu
lse/
10Ws
ec (
100W
loa
d generates 10
pul
ses
per
seco
nd)
00
099
; Us
e 16
-bit
s of
CS5
460
data
rat
her tha
n 24
-bit
s 00
100
;
(CS
5460
set
ting
s ar
e st
ill
24-bit
s lo
ng)
00
101
; Ad
ded
Appa
rent
Pow
er,
True
Pow
er, and
Powe
r Fa
ctor
Fun
ctio
ns.
00
102
; Mo
ved
Puls
e Ra
te r
egis
ter
valu
e to EEPROM.
00
103
; Mo
difi
ed C
alib
rate
rou
tine
to
includ
e Pu
lse
Rate
"Ga
in"
func
tion
. 00
104
; Ge
nera
l co
de s
ize
redu
ctio
n. (
Fits in
PIC
16C9
23.)
00
105
; 00
106
; If
the
CPU
CLK
outp
ut o
f th
e CS
5460 i
s 4.
096M
Hz,
the
CCP1
mod
ule
00
107
; ca
n be
use
d (a
s is
) fo
r th
e re
al tim
e cl
ock
refe
renc
e in
stea
d of
the
00
108
; Ti
mer1
Osc
illa
tor.
If
the
CPUC
LK output is
som
e ot
her
freq
uenc
y, 00
109
; CC
PR1H
:CCP
R1L
will
nee
d to
be
adjusted
to m
ake
CCP1
gen
erat
e an
int
erru
pt 00
110
; ev
ery
0.5
seco
nd.
00
111
;DS00220A-page 16 2000 Microchip Technology Inc.
-
AN220 00
112
; If
the
Tim
er1
osci
llat
or i
s to
be
used
as
the Real
Time
Clo
ck b
ase,
00
113
; un
comm
ent
line
46
("#d
efin
e TM
R1OS
C").
Thi
s causes CCP1
code
to
00
114
; be
dis
able
d an
d T1
OSC
code
to
be e
nabl
ed.
00
115
; 00
116
; Mo
difi
ed b
y Br
ett
Duan
e, M
icro
chip
Tec
hnol
ogy 5/
25/2
000
00
117
;***
****
****
****
****
****
****
****
****
****
****
*****************
00
118
00
119
l
ist
p=16
c924
00
120
#
incl
ude
00
001
LIST
00
002
; P1
6C92
4.IN
C S
tand
ard
Head
er F
ile,
Ver
sion
1.01
M
icro
chip
Tec
hnol
ogy,
Inc
. 00
289
LIST
2007
3
FF1
00
121
_
_CON
FIG
_CP_
OFF&
_WDT
_OFF
&_XT
_OSC&_PWRTE_ON
00
122
00
123
e
rror
leve
l
-3
02
; suppress assembl
er w
arni
ng m
essa
ge "
Oper
and
not
in ba
nk
0" 00
124
e
rror
leve
l
-3
06
; suppress assembl
er w
arni
ng m
essa
ge "
Cros
sing
pag
e bo
unda
ry"
00
125
00
126
00
127
;***
****
****
****
****
****
****
****
****
****
****
************************
00
128
; va
riou
s eq
uate
s 00
129
00
130
; Mi
croc
hip
MATH
lib
rary
AN6
17 00
0000
07
00
131
MSB
e
qu
7
00
0000
00
00
132
LSB
e
qu
0
00
133
00
134
; CS
5460
var
iabl
es (
stri
ng e
quat
es)
00
0000
FE
00
135
SYNC
0
e
qu
0x
FE
; Sync by
tes
sent
as
dumm
y da
ta d
urin
g re
ads
00
0000
FF
00
136
SYNC
1
e
qu
0x
FF
; No more tha
n 3
SYNC
1 by
tes
at a
tim
e. 00
137
00
138
#
IFND
EF
TM
R1OS
C 00
0000
7F
00
139
CCPC
OUNT
e
qu
0x
7F
; Varia
ble
in s
hare
d RA
M. C
CP1
inte
rrup
t co
unte
r, 00
140
E
NDIF
; not used
with
Tim
er1
osci
llat
or.
00
141
00
142
;***
****
****
****
****
****
****
****
****
****
****
************************
00
143
; Va
riab
les
in R
AM 00
144
c
bloc
k
0x
20
; Load
vari
able
s in
to R
AM s
tart
ing
at 0
x20
00
0000
20
00
145
TEMP
A
;
scr
atch
pad
00
0000
21
00
146
TEMP
B
;
scr
atch
pad
00
147
00
0000
22
00
148
SECO
ND
;
TIM
E va
riab
les
00
0000
23
00
149
MINU
TE
;
TIM
E va
riab
les
00
0000
24
00
150
HOUR
;
TIM
E va
riab
les
00
151
00
0000
25
00
152
WATT
TMPH
;
ene
rgy
puls
e co
unte
r MS
B 00
0000
26
00
153
WATT
TMPL
;
ene
rgy
puls
e co
unte
r LS
B 00
0000
27
00
154
WATT
HRH
;
Acc
umul
ated
WHr
MSB 2000 Microchip Technology Inc. DS00220A-page 17
-
AN220
00
0000
28
00
155
WATT
HRL
;
Acc
umul
ated
WHr
LSB
00
156
00
0000
29
00
157
PULS
ECH
;
"Pu
lses
per
sec
ond" counter MSB
00
0000
2A
00
158
PULS
ECL
;
"Pu
lses
per
sec
ond" counter LSB
00
159
00
0000
2B
00
160
PULD
ISPH
;
"Pu
lses
dur
ing
previo
us s
econ
d" M
SB 00
0000
2C
00
161
PULD
ISPL
;
"Pu
lses
dur
ing
previo
us s
econ
d" L
SB 00
162
00
0000
2D
00
163
APH
;
App
aren
t Po
wer
MSB (1
6 bi
t) (
Volt
Amps
in
bina
ry)
00
0000
2E
00
164
APL
;
App
aren
t Po
wer
LSB
00
165
00
0000
2F
00
166
TPH
;
Tru
e Po
wer
MSB
(16 bi
t) (
Watt
s in
bin
ary)
00
0000
30
00
167
TPL
;
Tru
e Po
wer
LSB
00
168
00
0000
31
00
169
PFH
;
Pow
er F
acto
r MS
B (16
bit)
(un
itle
ss i
n bi
nary
) 00
0000
32
00
170
PFL
;
Pow
er F
acto
r LS
B 00
171
00
172
;Mor
e ge
nera
l va
riab
les
00
0000
33
00
173
POIN
TER
;
Poi
nts
to t
he c
haracters in
ini
tial
00
0000
34
00
174
PTRT
MP
;
scr
olli
ng m
essa
ge 00
0000
35
00
175
SERN
UM
;
uni
t se
rial
num
ber
00
0000
36
00
176
CALM
ODE
;
Cal
ibra
tion
Mod
e bein
g di
spla
yed
00
0000
37
00
177
CALD
IG
;
Cal
ibra
tion
dig
it bei
ng i
ncre
ment
ed 00
0000
38
00
178
UPDA
TEWH
;
Whe
n to
wri
te a
ccumula
ted
Watt
HOU
Rs t
o th
e EE
PROM
(ev
ery
8 mi
nute
s) 00
179
00
180
; SS
P va
riab
les
(SPI
mod
e) R
ecei
ve buf
fer
from
CS5
460
00
0000
39
00
181
RXDA
TA0
;
RXD
ATA
buff
er M
SB 00
0000
3A
00
182
RXDA
TA1
;
RXD
ATA
buff
er 00
0000
3B
00
183
RXDA
TA2
;
RXD
ATA
buff
er L
SB 00
184
00
185
; TX
DATA
buf
fer
(SPI
mod
e) T
rans
mit bu
ffer
to
CS54
60 00
0000
3C
00
186
TXDA
TA
;
com
mand
byt
e to
send
to t
he C
S456
0 00
0000
3D
00
187
TXDA
TA0
;
TXD
ATA
buff
er M
SB 00
0000
3E
00
188
TXDA
TA1
;
TXD
ATA
buff
er 00
0000
3F
00
189
TXDA
TA2
;
TXD
ATA
buff
er L
SB 00
190
00
191
; Mi
croc
hip
MATH
lib
rary
AN6
17 00
0000
40
00
192
AARG
B0
;
4 b
yte
argu
ment
and r
esul
t. B
0 is
alw
ays
MSB
00
0000
41
00
193
AARG
B1 00
0000
42
00
194
AARG
B2 00
0000
43
00
195
AARG
B3 00
0000
44
00
196
AARG
B4 00
197
00
0000
45
00
198
BARG
B0
;
2 b
yte
argu
ment
. B0 is
alw
ays
MSB
00
0000
46
00
199
BARG
B1 00
200 DS00220A-page 18 2000 Microchip Technology Inc.
-
AN220 00
0000
47
00
201
REMB
0
;
2 b
yte
rema
ider
(fr
om d
ivis
ion)
00
0000
48
00
202
REMB
1
;
B0
is a
lway
s MS
B 00
203
00
0000
49
00
204
TEMP
;
int
erna
l va
riab
les
00
0000
4A
00
205
TEMP
B0 00
0000
4B
00
206
TEMP
B1 00
0000
4C
00
207
TEMP
B2 00
0000
4D
00
208
LOOP
COUN
T 00
209
00
210
; 16
bit
bin
ary
to B
CD v
aria
bles
- S
ee a
pnot
e AN54
4 00
0000
4E
00
211
R0
; ou
tput
byt
es 1
0ks di
gits
00
0000
4F
00
212
R1
;
1ks, 10
0s di
gits
00
0000
50
00
213
R2
;
10s, 1
s di
gits
00
214
00
0000
51
00
215
TEMP
L
;
inp
ut b
ytes
(2
byte
bin
ary)
00
0000
52
00
216
TEMP
H 00
217
00
0000
53
00
218
COUN
T
;
int
erna
l va
riab
le 00
219
00
0000
54
00
220
BYTE
COUN
T
;
EEP
ROM
vari
able
s (f
irmw
are
I2C)
00
0000
55
00
221
EEAD
DR
;
EEP
ROM
addr
esse
s 00
0000
56
00
222
EEDA
TA
;
EEP
ROM
data
00
0000
57
00
223
EETE
MP 00
224
00
225
;pow
erup
var
iabl
es 00
0000
58
00
226
PWRU
P55
;
reg
iste
rs t
o te
st a
t po
wer
up to
00
0000
59
00
227
PWRU
PAA
;
see
if
warm
sta
rt o
r co
ld s
tart
00
228
00
0000
5A
00
229
LAST
RAM
;
dum
my m
arke
r (u
nuse
d) 00
230
00
231
e
ndc
00
232
00
233
c
bloc
k
0x
70
; Load
vari
able
s in
to R
AM s
tart
ing
at 0
x70
00
234
; "S
HARE
D" v
aria
bles
in
memo
ry l
ocat
ions
70h
-7Fh a
re a
vali
able
in
all
bank
s 00
235
00
0000
70
00
236
LCDT
EMP1
;
use
d by
LCD
rou
tine
s 00
0000
71
00
237
LCDT
EMP2
00
238
00
0000
72
00
239
MODE
INC
;
inc
reme
nted
eac
h se
cond
, 00
240
;
bit
7 s
et w
heve
r Bi
t 0
is s
et (ev
ery
odd
seco
nd)
00
241
00
0000
73
00
242
UPDA
TE
;
Bit
0 s
et e
ach
seco
nd 00
243
00
0000
74
00
244
BUTT
ON
;
ind
icat
es b
utto
n pr
ess.
Bit
0=1 = a bu
tton
is
pres
sed
00
0000
75
00
245
BUTT
ONTM
P
;
use
d on
ly i
n IS
R.
Bit
s
=1 =
but
tons
1-4
are
pre
ssed
00
246 2000 Microchip Technology Inc. DS00220A-page 19
-
AN220
00
247
; Sa
ve c
onte
xt b
efor
e in
terr
upt,
restore aft
er i
nter
rupt
00
0000
76
00
248
TEMP
FSR
;
sav
e FS
R re
gist
er dur
ing
ISR
00
0000
77
00
249
TEMP
PCLA
TH
;
sav
e PC
LATH
reg
ister du
ring
ISR
00
0000
78
00
250
TEMP
W
;
sav
e W
regi
ster
durin
g IS
R 00
0000
79
00
251
TEMP
STAT
;
sav
e ST
ATUS
reg
ister du
ring
ISR
00
252
e
ndc
00
253
00
254
#
incl
ude
;
cal
ibra
tion
def
init
ions
00
001
; So
ftwa
re L
icen
se A
gree
ment
00
002
; 00
003
; Th
e so
ftwa
re s
uppl
ied
here
with
by Mic
roch
ip T
echn
olog
y In
corp
orat
ed (
the
00
004
; "C
ompa
ny")
for
its
PIC
micr
o Mic
rocontroll
er i
s in
tend
ed a
nd s
uppl
ied
to 00
005
; yo
u, t
he C
ompa
nys customer, fo
r use sole
ly a
nd e
xclu
sive
ly o
n Mi
croc
hip
00
006
; PI
Cmic
ro M
icro
cont
roll
er p
rodu
cts.
00
007
; 00
008
; Th
e so
ftwa
re i
s ow
ned
by t
he C
ompany and/
or i
ts s
uppl
ier,
and
is
prot
ecte
d 00
009
; un
der
appl
icab
le c
opyr
ight
law
s. All
rig
hts
are
rese
rved
. An
y us
e in
00
010
; vi
olat
ion
of t
he f
oreg
oing
res
trictio
ns m
ay s
ubje
ct t
he u
ser
to c
rimi
nal
00
011
; sa
ncti
ons
unde
r ap
plic
able
law
s, as well
as
to c
ivil
lia
bili
ty f
or t
he 00
012
; br
each
of
the
term
s an
d co
ndit
ions of
this
lic
ense
. 00
013
; 00
014
; TH
IS S
OFTW
ARE
IS P
ROVI
DED
IN A
N "AS IS" CONDITION. NO WARRANTIES, WHETHER
00
015
; EX
PRES
S, I
MPLI
ED O
R ST
ATUT
ORY,
INCLUDING, BUT NOT LIMITED TO, IMPLIED
00
016
; WA
RRAN
TIES
OF
MERC
HANT
ABIL
ITY
AND FITNESS FOR A PARTICULAR PURPOSE APPLY
00
017
; TO
THI
S SO
FTWA
RE.
THE
COMP
ANY
SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
00
018
; FO
R SP
ECIA
L, I
NCID
ENTA
L OR
CON
SEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
00
019
00
020
; **
****
****
**
DEFA
ULT
VALU
ES T
O WRITE TO EEPROM **************************
00
021
; Af
ter
the
cali
brat
ion
valu
es h
ave be
en d
eter
mine
d fo
r a
new
00
022
; un
it t
hose
val
ues
can
be l
oade
d into the
se "
#def
ines
" an
d 00
023
; wr
itte
n to
the
EEP
ROM
(see
Cal
ibratio
n in
stru
ctio
n do
cume
nt)
00
024
00
025
#def
ine
S
ERNU
MBER
0x
01 ; Seria
l Nu
mber
00
026
00
027
#def
ine
V
OLTG
AINH
0x
29 ; volt
age
gain
MSB
00
028
#def
ine
V
OLTG
AINM
0x
66 ; volt
age
gain
00
029
#def
ine
V
OLTG
AINL
0x
6F ; volt
age
gain
LSB
00
030
00
031
#def
ine
C
URRG
AINH
0x
2A ; current gain
MSB
00
032
#def
ine
C
URRG
AINM
0x
2E ; current gain
00
033
#def
ine
C
URRG
AINL
0x
0A ; current gain
LSB
00
034
00
035
#def
ine
V
OLTO
FFH
0x
10 ; volt
age
offs
et M
SB 00
036
#def
ine
V
OLTO
FFM
0x
1A ; volt
age
offs
et 00
037
#def
ine
V
OLTO
FFL
0x
B6 ; volt
age
offs
et L
SB 00
038 DS00220A-page 20 2000 Microchip Technology Inc.
-
AN220 00
039
#def
ine
C
URRO
FFH
0x
FE
; current off
set
MSB
00
040
#def
ine
C
URRO
FFM
0x
DC
; current off
set
00
041
#def
ine
C
URRO
FFL
0x
16
; current off
set
LSB
00
042
00
043
#def
ine
P
ULSE
RATE
H
0x
02
; Puls
e ra
te "
gain
" MS
B 00
044
#def
ine
P
ULSE
RATE
M
0x
14
; Puls
e ra
te "
gain
" 00
045
#def
ine
P
ULSE
RATE
L
0x
CB
; Puls
e ra
te "
gain
" LS
B 00
046
00
047
; **
****
****
****
** F
ULL
SCAL
E VA
LUES
***
****
*******************************
00
048
; Th
e pr
esen
t re
v of
the
CS4
560
is n
ot l
inea
r over the
ent
ire
volt
age
rang
e 00
049
; Va
lues
use
d by
the
MAT
H ro
utin
es f
or c
oars
e cali
brat
ion
00
050
; ba
sed
on t
he v
alue
s we
cho
ose
for
the
volt
age di
vide
r 00
051
00
052
#def
ine
M
AXCU
RRH
0x
00
; Full
sca
le c
urre
nt M
SB .
.. 2
5.0
Amps
00
053
#def
ine
M
AXCU
RRL
0x
FA
; Full
sca
le c
urre
nt L
SB 00
054
00
055
#IFD
EF
V
OLT1
20
;
120V
nom
inal
full
scal
e 00
056
; fo
r 12
0V R
10 &
R12
= 1
00K,
R11
= 1
K 00
057
; us
e th
is v
alue
for
ful
l sc
ale
volt
age
00
058
00
059
#def
ine
M
AXVO
LTH
0x
00
; Full
sca
le v
olta
ge M
SB .
.. 2
37 V
OLTs
00
060
#def
ine
M
AXVO
LTL
0x
ED
; Full
sca
le v
olta
ge L
SB 00
061
00
062
#def
ine
M
AXPW
RH
0x
98
; Full
sca
le p
ower
MSB
...
237
V *
25.0
A =
5925
W 00
063
#def
ine
M
AXPW
RL
0x
CE
; Full
sca
le p
ower
LSB
00
064
#END
IF 00
065
00
066
#IFD
EF
V
OLT2
20
;
220V
nom
inal
full
scal
e 00
067
; fo
r 22
0V R
10 &
R12
= 1
21K,
R11
= 1
K 00
068
; us
e th
is v
alue
for
ful
l sc
ale
volt
age
00
069
00
070
#def
ine
M
AXVO
LTH
0x
01
; Full
sca
le v
olta
ge M
SB .
.. 2
82 V
OLTs
00
071
#def
ine
M
AXVO
LTL
0x
1A
; Full
sca
le v
olta
ge L
SB 00
072
00
073
#def
ine
M
AXPW
RH
0x
B3
; Full
sca
le p
ower
MSB
...
282
V *
25.0
A =
7050
W 00
074
#def
ine
M
AXPW
RL
0x
F1
; Full
sca
le p
ower
LSB
00
075
#END
IF 00
076
00
077
00
078
00
255
#
incl
ude
; LCD, I2C
, an
d ma
th l
ibra
ry d
efin
itio
ns 00
001
;***
****
****
****
****
****
****
****
****
****
****
*****************
00
002
; So
ftwa
re L
icen
se A
gree
ment
00
003
; 00
004
; Th
e so
ftwa
re s
uppl
ied
here
with
by
Micr
ochi
p Techn
olog
y In
corp
orat
ed (
the
00
005
; "C
ompa
ny")
for
its
PIC
micr
o Mic
roco
ntro
ller
is
inte
nded
and
sup
plie
d to 2000 Microchip Technology Inc. DS00220A-page 21
-
AN220
00
006
; yo
u, t
he C
ompa
nys customer, fo
r use sole
ly a
nd e
xclu
sive
ly o
n Mi
croc
hip
00
007
; PI
Cmic
ro M
icro
cont
roll
er p
rodu
cts.
00
008
; 00
009
; Th
e so
ftwa
re i
s ow
ned
by t
he C
ompany and/
or i
ts s
uppl
ier,
and
is
prot
ecte
d 00
010
; un
der
appl
icab
le c
opyr
ight
law
s. All
rig
hts
are
rese
rved
. An
y us
e in
00
011
; vi
olat
ion
of t
he f
oreg
oing
res
trictio
ns m
ay s
ubje
ct t
he u
ser
to c
rimi
nal
00
012
; sa
ncti
ons
unde
r ap
plic
able
law
s, as well
as
to c
ivil
lia
bili
ty f
or t
he 00
013
; br
each
of
the
term
s an
d co
ndit
ions of
this
lic
ense
. 00
014
; 00
015
; TH
IS S
OFTW
ARE
IS P
ROVI
DED
IN A
N "AS IS" CONDITION. NO WARRANTIES, WHETHER
00
016
; EX
PRES
S, I
MPLI
ED O
R ST
ATUT
ORY,
INCLUDING, BUT NOT LIMITED TO, IMPLIED
00
017
; WA
RRAN
TIES
OF
MERC
HANT
ABIL
ITY
AND FITNESS FOR A PARTICULAR PURPOSE APPLY
00
018
; TO
THI
S SO
FTWA
RE.
THE
COMP
ANY
SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
00
019
; FO
R SP
ECIA
L, I
NCID
ENTA
L OR
CON
SEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
00
020
00
021
;***
****
****
****
** E
EPRO
M I2
C co
mmunic
atio
ns *
****
****
****
****
****
****
****
* 00
022
#def
ine
S
CL
PO
RTA,0
00
023
#def
ine
S
DA
PO
RTA,1
00
024
#def
ine
S
DATR
IS
TR
ISA,1
00
025
00
026
;***
****
****
****
** S
SP *
****
****
*******************************************
00
027
#def
ine
C
S
PO
RTA,2
00
028
00
029
;***
****
****
****
** L
CD *
****
****
*******************************************
00
030
; We
def
ine
what
bit
in
what
reg
ister corresponds
to
each
LCD
seg
ment
00
031
00
032
#def
ine
D
1A
LC
DD02,2
;
DIG
IT 1
(LE
FT S
IDE)
00
033
#