📄 avr
字号:
AVR465: Single-Phase Power/Energy Meter
with Tamper Detection
Features
? Cost-Effective and Flexible Single-Phase Energy Meter
? Fulfills IEC 61036 Accuracy Requirements for Class 1 Meters
? Detects, Signals and Continues to Measure Accurately Under At Least 20 Different
Tamper Conditions
? Design Easily Downgrades to Fit Normal Single-Phase Energy Metering
? Compact Design With Internal Flash Memory, SRAM and EEPROM
? Includes USART and Programmable I/O
? LCD Is Easily Added By Migrating To Other AVR Microcontrollers
? Secure and Reprogrammable Flash Memory Enables Flexible Firmware Updates
? One-Time, Quick, and Accurate Digital Calibration Gives Added Benefits
- Calibration Can Be Automated
- No Need for Trimming Components
- No Need for External EEPROM, as Calibration Coefficients Are Stored Internally
? Adjustable Energy Pulse Output Goes Beyond 10.000 Impulses / kWh
? Active Power, Voltage and Current Measurements are Easily Accessible Over
USART Interface
? Design Easily Migrates to Any Other AVR Microcontroller
? Low-Power AVR Microcontroller Allows Operation Down To 1.8V
Introduction
This application note describes a single-phase power/energy meter with tamper
logic. The design measures active power, voltage, and current in a single-phase
distribution environment. It differs from ordinary single-phase meters in that it uses
two current transducers to measure active power in both live and neutral wires.
This enables the meter to detect, signal, and continue to measure reliably even
when subject to external attempts of tampering.
The heart of the meter is an AVR microcontroller. All measurements are carried out
in the digital domain and measurement results are available in the form of
frequency-modulated pulse outputs and as plain-text values, accessible over the
USART interface. This enables the design to be used in cost-effective applications
based on mechanical display counters. Alternatively, the design easily fits more
computerized applications with features such as remote reading (AMR), demand
recording, multiple tariffs, and other.
A prototype built for 230V and 10A operation showed better than 1% accuracy over
a dynamic range of 500:1. With careful PCB design and following the guidelines
given at the end of this document the accuracy can be further increased. The meter
is easily configured to fit any other voltage and current settings.
8-bit
Microcontrollers
Application Note
Rev. 2566A-AVR-07/04
2 AVR465
2566A-AVR-07/04
Overview
Power meters are sometimes referred to as energy meters and vice versa. Per
definition, (active) power is a measure of what is required (or consumed) in order to
perform useful work. For example, a light bulb with a 100W rating consumes 100
watts of active power in order to create light (and heat). Energy, per definition, is the
measure of how much work has been required over a known period of time. In the
light bulb example, leaving the bulb on for an hour it will consume 100W * 3600s =
360000Ws (watt-seconds) = 100Wh (watt-hours) = 0.1kWh (kilowatt-hours) of energy.
The meter described in this application note can be referred to as a power meter, an
energy meter or a kilowatt-hour meter. The Energy Pulse output (EP) is a ready
indication of active power, as registered by the meter; the frequency of the pulse is
directly proportional to active power. Integrating pulses over time gives active energy.
For storage purposes, the meter includes two pulse outputs (DPP and DPN) to
directly drive various display counters. All pulse outputs are easy to configure for any
reasonable rate. The default is 10.000 impulses per kilowatt-hour for the EP output
and 100 impulses per kilowatt-hour for the DPP/DPN pulses.
Not only pulse rates are readily adjusted; All measurement results can be calibrated
in the digital domain, removing the need for any trimming components. This includes
adjustments to compensate for phase delays in current transformers. The calibration
event can be automated, removing the time-consuming manual trimming required in
traditional, electromechanical meters. Digital calibration is fast and efficient, reducing
the overall production time and cost. Calibration coefficients are safely stored in the
internal EEPROM, further reducing the need for external devices.
The brain of the meter is the firmware, which is provided open source. Although it
includes all the functionality required for a tamper-proof, single-phase meter, it can be
modified and updated at any time. Even in the field. The firmware is entirely written in
C, which makes modifications easy to implement. Integrity and intellectual property
are yet easy to secure using Lock Bits of the AVR microcontroller.
Meter Hardware
The energy meter hardware consists of a power supply, an analog front end, a
microcontroller section, and an interface section.
The meter described in this application note connects to high currents and high
voltages. High currents and high voltages may be hazardous, even lethal. Hence, the
meter should be operated by qualified technicians only. Atmel takes no responsibility
for any consequence that may result from the use of this document or the application
described herein.
Warning:
Shock Hazard
AVR465
3
2566A-AVR-07/04
Figure 1. Electric Shock Hazard.
465
L N
LOAD
There is no insulation between line voltage and the meter. Hence, sections of the
meter contain high voltages and even the low-voltage output of the power supply is
connected to the mains. Use caution. The meter must be enclosed in a nonconductive
casing to avoid accidental voltage shocks.
The power supply is a low-efficiency, but cost-effective and compact design. It is
intended to provide just the amount of power needed by the meter at a cost as low as
possible. If enhancements are made to the meter it may be necessary to derive new
values for some of the components.
The following table summarizes typical current consumption of the main parts of the
meter.
Table 1. Typical Current Consumption of Main Meter Sections.
Section Includes Continuous Peak
Front End Operational amplifiers (1) 0.2 mA 0.2 mA
Microcontroller AVR (Active Mode, 4 MHz) (2) 1.8 mA 3.5 mA
LED All LED’s (each about 1 mcd brightness) None (3) 3.0 mA
Display Display counter (400 ? coil impedance) None (3) 7.5 mA
Notes: 1. Typical consumption, according to LMV358 data sheet
2. According to ATmega88 data sheet (2545B–AVR–01/04)
3. LED’s are mostly off and display counter is updated rarely
Peak currents are brief, mainly occurring when the display counter is updated. The
worst-case scenario is when the display counter is updated and all LED’s are lit.
Typically, the power supply needs to be able to supply less than ten milliwatts (at 3
volts), but it must also be able to deliver the brief bursts of energy required to turn the
coil of the counter.
The power supply is illustrated in Figure 2. The below schematic is identical to the
power supply section of the meter, as illustrated in the schematic at the end of this
document, but component numbers are not the same. Please note well the galvanic
connection between live wires and meter ground!
Power Supply
Power Budget
Theory
4 AVR465
2566A-AVR-07/04
Figure 2. Low-Cost, Transformerless Power Supply.
L
N
230V
R1
D1
VOUT
U1
+VIN
GND
VCC
D2
C2
C1
The power supply is based on halfway rectification. During negative half-waves
capacitor C1 is charged and during positive half-waves the capacitor is drained.
Zener diode D1 (minus the forward voltage of diode D2) dictates to which voltage C2
is charged. Voltage regulator U1 uses the energy stored in C2 to produce a stable
output voltage. Resistor R1 controls the charge and discharge of C1 and also limits
the current flow through zener diode D1.
Please note that the power supply can be a source of noise, if poorly planned and
realized. Ground connections are very important. For example, the current flow
through the zener is rather large and if the same ground track is shared by the zener
and, say, the operational amplifiers (see current front end) then measurement results
will be greatly degraded. Typically, this can be seen as odd harmonics in the
measured current signal.
It is recommended to use star topology in ground connections.
The dropout voltage for the 3.3V regulator U1 is about 5V. When input voltage falls
below the dropout level, the device ceases to regulate. The regulator input must be
kept above this level, even at the end of the drain cycle and at worst-case current
consumption.
As a starting point, the zener diode is specified to 15V. This leaves much headroom
for capacitor C2 to discharge before reaching minimum input voltage of the regulator.
Next, the size of capacitor C2 is calculated. The minimum size is derived based on
the general discharge function of the capacitor, as follows:
Equation 1. Equation To Calculate Size Of Charge Capacitor.
( ) 0
RC
t
V
V 0 ln R
t C e V V
×
? = ? × = ?
Here t is the discharge time, V0 is the initial voltage, V is the voltage after discharge
and R is the load discharging the capacitor. If the worst-case current consumption is
14mA (see previous table), then the equivalent load resistance is R = 3V/14mA = 214
?. Worst-case current consumption takes place when driving the display counter. The
length of the drive pulse is 100ms, by default. Assuming the voltage of the charged
capacitor is allowed to drop to regulator minimum during the length of one display
pulse, the smallest size of the capacitor is as follows:
Equation 2. Calculating Minimum Size of Capacitor C2.
( ) F 470 F .3 425
ln 214
0.1s C
15V
5V
μ μ ≈ =
× ?
? =
Source of Noise
Component Values
AVR465
5
2566A-AVR-07/04
Next, capacitor C1 is calculated. The size of the capacitor should be as small as
possible, since it dictates how much power is drawn from the mains lines. Also, the
larger the capacitor, the more expensive it is. The minimum size of the capacitor is
derived from the basic functions of stored charge (Q = CU) and current (I = Q/t). For
capacitor C1 it is no longer required to use the above worst-case current (14mA),
since capacitor C2 will store energy enough to maintain the current briefly. Assuming
10mA continuous current, and that the capacitor is drained over one 50Hz half cycle,
and that voltage is 80% of nominal, then the required minimum size of the capacitor is
as follows:
Equation 3. Calculating Minimum Size of Capacitor C1.
680nF F 0.543
230V 0.8
0.01s 0.01A
U
t I C
MAINS
≈ =
×
×
=
×
= μ
The capacitor needs to be fully charged each half-cycle. The charge time is dictated
by resistor R1, the size of which can be derived using the so-called 5RC rule of
thumb. The 5RC rule says that for a step change in voltage the capacitor charges to
within 1% of its final value in five time constants (RC). Specifying that the capacitor
should be (almost) fully charged at the peak of the positive half-wave, the maximum
size of resistor R1 can be estimated as follows:
Equation 4. Calculating Maximum Size of Charge Limit Resistor.
? =
×
=
×
= ? × × = 1470
0nF 68 5
0.005s
C 5
t R C R 5 t
Another limitation on resistor R1 is that it must be small enough for capacitor C2 to
charge enough during one half-cycle. The larger R1 is, the less C2 is charged each
cycle. On the other hand, it is unreasonable to specify R1 such that C2 charges to,
say, 99% during one half-cycle since this would make R1 very small and the power
consumption in zener diode D1 very large. Instead, a decent charge level is selected
and R1 is specified accordingly. For example, setting R1 = 470 ? the meter works
nicely (input voltage to regulator typically stays above 13V at all times).
The analog front end is the part, which interfaces to the high voltage lines. It
conditions high voltages and high currents down to a level where the signals cannot
harm the more delicate electronics. It converts high voltages and high currents to
voltages sufficiently small to be measured directly by the ADC of the microcontroller.
The nominal line voltage of the meter is 230V and the maximum rated current is 10A,
both of which obviously are way too large signals to be fed directly to any
microcontroller. The analog front end converts line voltage and line current to
voltages with amplitudes of no more than 1V peak-to-peak. The front end is easy to
configure for any other line voltage or current, as described in the following.
Line voltage is first downsized using a resistor ladder, then DC-filtered and finally DCbiased,
as illustrated in Figure 3. Note that component numbers are not the same as
in the full schematic at the end of this document.
Analog Front End
Voltage Front End
6 AVR465
2566A-AVR-07/04
Figure 3. Voltage Front End.
LOAD
230V
R2
R1
R4
R3
C1
VCC
The resistor ladder R1-R2 by default produces a 1.1Vpp signal when the line voltage
reaches 115% of nominal voltage, as follows:
Equation 5. Downsizing The Line Voltage.
PP NOM MAX 1.099V 0.388V
681k?
1k? 1.15 230V
R2 R1
R2 1.15 U U = =
× ×
=
+
× × =
The nominal voltage is 230V by default and the 265V limit is there to leave 15%
headroom for overvoltages.
The DC bias ladder R3-R4 positions the AC signal halfway up the ADC voltage
reference. By default, it has been sized to fit ATmega88 (1.1V reference) and 3V
supply voltage, as follows:
Equation 6. DC Bias Level Of Downsized Signal.
2
U 0.55V
3.68M?
680k? 3V
R4 R3
R4 U U AREF
VCC DC ≈ =
×
=
+
× =
Please note that the voltage front end handles voltages of considerable amplitude,
which makes it a potential source of noise. Disturbances are readily emitted into
current measurement circuitry, where it will interfere with the actual signal to be
measured. Typically, this shows as a non-linear error at small signal amplitudes and
non-unity power factors. At unity power factor, voltage and current signals are in
phase and crosstalk between voltage and current channels merely appears as a gain
error, which can be calibrated. When voltage and current are not in phase crosstalk
will have a non-linear effect on the measurements, which cannot be calibrated.
Crosstalk is minimized by means of good PCB planning and the proper use of filter
components.
The current front end is a little bit more complex than the voltage front end. This is
because line voltage remains constant at, say, 230V but line current varies with the
load. Line current typically ranges from some milliamperes to ten amperes, or more.
In order to achieve 1% measurement accuracy over such a wide range, the ADC
would need to have a resolution of around 16 bits. Since the target device includes
only a 10-bit A/D-converter the front end must amplify small-scale signals. The
current front end therefore includes a programmable gain stage, which is controlled
by the MCU.
Crosstalk
Current Front End
AVR465
7
2566A-AVR-07/04
The design criteria for the programmable gain stage are not very relaxed; the gain
stage must amplify AC signals up to around 100x, but provide little or no DC
amplification. This is because the input is a DC-biased AC signal and if the gain stage
provides even a small DC amplification the output will saturate. In addition, the gain
must be programmable by the MCU and the settling time must be considerably less
than a second. Finally, the design must be cost-effective.
There are many school examples of how to realize the above, but most of them are
sooner or later ruled out by at least one of the design criteria. A good starting point,
however, is the operational amplifier; they are common, exist in a wide variety and
can be very cost-effective.
A little experimentation soon shows that the non-inverting amplifier is not a viable
topology for this design, mostly because of the requirements for high AC and low DC
gains. Considering the frequency band of interest, AC-coupled, non-inverting
amplifiers require very large (and expensive) capacitors for the DC decoupling. Also,
a large DC decoupling capacitor leads to very long switching times when gain is
altered. Since the gain needs to be variable the DC levels cannot be trimmed to zero.
A viable solution is found from inverting amplifier topology, although it still requires a
rather (but not very) large capacitor to be used. Gain configuration resistors are
readily toggled in and out using low-cost switches from 74HC-series logic, as shown
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -