English
Language : 

AN939 Datasheet, PDF (8/18 Pages) Microchip Technology – Designing Energy Meters with the PIC16F873A
AN939
FIGURE 5:
ENERGY METER FIRMWARE (ENERGY MEASUREMENT INTERRUPT ROUTINE)
Timer0 Interrupt
Sample Voltage and Current
Read Voltage at
Time 1 (V1)
Y
Is OFFSET true?
N
Read OFFSET
from ADC,
Set OFFSET to
False
Read Phase
Current (CP)
Sample Voltage
and Current
Read Voltage at
Time 2 (V2)
Calculate
Power
Have
20 samples Y
been taken?
N
(Gain and Fault Handling)
C
Is
Y
Total ≥ 1/3200
kWh?
N
Is
Y
Total ≥ 0.01 kWh?
N
Increment
OFFSET_CNT
Toggle Calibration
Pulse and LED
Set kWh Flag
to True
Is
OFFSET_CNT
Y
= 65536?
N
Return from
Interrupt
Set OFFSET
to True
Read Neutral
Current (CN)
Read Voltage at
Time 3 (V3)
Calculate Power
Calculate VP
and VN from
V1, V2 and V3
Calculate Signed
Values for Voltage
and Current
Adjust for Gain and
Calibration Values
Accumulate CN and
CP in CACCN
and CACCP Buffers
Integrate Energy
according to EARTH
and REVERSE Flags
Store Energy Value
in DECISION
and TOTAL Buffers
DS00939A-page 8
© 2005 Microchip Technology Inc.