Electrical Measurement by Microcontroller
Electrical Measurement by Microcontroller
A
quiet revolution is in progress in the utility While a century of refinement has made the kilowatt-
industry. Electromechanical metering hour meter one of the most reliable mechanical products
devices, in use for the better part of a in wide production, it remains a mechanical device prone
century to record electrical energy usage to wear, shock and other events that affect anything with
in kilowatt hours, are gradually being moving parts. Another limitation is that the meter, as usually
replaced by multirate, multifunction meters capable deployed, maintains no record of the time when usage
of more accurately accounting for utility usage. A new occurred. The meter only counts revolutions of the wheel
generation of microcontrollers is speeding the progress of and does not record the times when the wheel is moving
this revolution. faster or slower.
It is useful to know when electric power is consumed,
Beginnings because the demand placed on the electric utility is not
In 1885, Galileo Ferraris discovered that a solid armature constant over time. In fact, much more power is used during
placed in an out-of-phase ac magnetic field would rotate at waking hours than overnight. Utilities must design their
a rate proportional to the flow of electrical energy in the delivery systems to meet demand in the “peak hour.” This
coils that generated the field. This discovery is the principle means that for all other times, generators will be operating at
on which the great majority of electric meters still operate less than peak capacity; and since electricity can’t be stored,
today. an expensive capital resource is being partially wasted.
In the typical meter, a solid armature is mounted on jeweled For this reason, electric utility providers have an interest
bearings and allowed to rotate freely in a sealed container. in encouraging energy conservation during peak periods
Coils apply the ac magnetic field proportional to the amount and consumption during off-peak periods. The best way
of power flowing through the meter, and a counter detects to do this is through selective pricing; that is, charging the
the number of revolutions made by the disk. customer more for energy consumed during peak periods and
providing a discount during slack periods. This is a function
400 kΩ
of which static kilowatt-hour meters are incapable.
Voltage Sense Hi
A third limitation of traditional meters is that they
Neutral measure only real power. In an ideal world, measuring real
power is all that would be necessary—current and voltage
1 kΩ
0.1 µF would flow in phase. However, devices such as induction
motors and fluorescent lamp ballasts cause current to flow
out of phase with the applied voltage. Only the in-phase
component is usable as power, the remainder is reflected back
Hot Voltage Sense Lo
into the power grid. As a result, fewer actual watts are used
1 kΩ compared to the number of volt-amperes delivered.
0.1 µF For large industrial customers, electric utilities have
long used VAR-hour meters to determine the amount of
out-of-phase or reactive power delivered to the customer.
Fig. 1. The voltage channel of the reference electric meter consists of a With a multifunction meter, utilities can extend power
simple voltage divider providing a ratio of 400-to-1. factor monitoring to smaller commercial customers and, in
EEPROM
Hz or 60-Hz signal Shunt
seem trivial. But on Tx Infrared
Line
Rx Communications
closer inspection, Interface
the job is a little
Time of
Day
tougher. Look at
accuracy first: most Meter
Pulse
specifications call
for the meter to Vdd
have 1% accuracy Tx
over its entire Power Rx
range—not just Supply Tx Enable
Isolated
EIA485
full-scale accuracy.
The reference Isolated Vdd
design described
Net
here has guaranteed Address
accuracy from 1 A Button
to 40 A. To meet
this requirement, Fig 3. Hardware components of the reference design meter. Because of the highly integrated microcontroller, all that
the meter must is needed is a display, a power supply, a nonvolatile memory, physical devices for communication, and passive signal
successfully resolve conditioning for measuring voltage and current.
current as low as
10 mA, but not saturate until it is measuring more than 40 ensure that the last reading displayed is maintained internally
A—a 4000-to-1 ratio. This means that the data converter by the meter.
can be no less than 12 bits, with a 14-bit or better converter There are simply too many communications schemes
preferable. in the market today to ever hope to cover every one in an
What about sample rate? If the fundamental frequency integrated peripheral. It is a reasonable bet, however, that
was all that was of concern, then sampling at some rate above for an inexpensive metering apparatus, it is likely going to
the Nyquist frequency (120 Hz for a 60-Hz system) consistent be some variant on simple asynchronous serial.
with conservative anti-aliasing filter design would be In the reference design for the MAXQ3120, we settled on
sufficient. However, most specifications require that the meter two serial peripheral channels. The first is based on the EIA-485
accurately measure power containing frequencies as high as standard. In this arrangement, the meters reside on a network
the 21st harmonic. In a 60-Hz system, that corresponds to that is managed by a PC acting as a central controller. As the
a frequency response of 1260 Hz and a sampling frequency PC polls the meters, they respond with data packets that
of no less than 2520 Hz. While these specifications are no represent usage. The PC can then aggregate and transmit
challenge for modern data converters, they may stretch the the information to a billing facility.
capabilities of some of the A/D converters built into many The second communication channel is an IR transmitter
microcontroller devices. and receiver system based on simple asynchronous protocols.
The communications protocol is based on a Chinese electric
Hardware Design Analysis meter specification, DL/T 645, which specifies an IR physical
The hardware for the reference design is shown in Fig. 3. layer that differs significantly from those found in commonly
The entire meter consists of the MAXQ3120 microcontroller, used standards. For details on physical layer encoding, see
a power supply, a display, an I2C EEPROM, the input sensors Fig. 4. In the transmitter channel, a circuit modulates the
and communication peripherals. output of the UART so that a “0” is transmitted as a 38-kHz
The reference design described here uses an LCD as signal and a “1” is represented by the absence of the signal.
a display element. The advantage is obvious. By using The receiver is implemented in an inexpensive IC that
annunciators, the display can indicate anything from energy integrates an IR photodiode and a 38-kHz detector. In this
to voltage to time of day. way, only the optical components themselves are required to
The disadvantage of an electronic display is that it shows implement a fully functional IR transceiver system.
nothing when the power is off. And while a mechanical Power is the simplest block. Since modern micro-
counter is inherently nonvolatile, measures must be taken to controllers are low-power devices, a simple transformer-
to endure between
Asynchronous Start Bit Bit Bit Bit Bit Bit Bit 10,000 and 1 million
Bit Odd Stop
Data Bit 0 1 2 3 4 5 6 7
write cycles. While Parity Bit
Part Number VCES IC(90°C) VCE(ON, 25°C)@ IC(90˚C) (TYP) EOFF@TJ=125˚Typ RTH(J-C) Package
IGBT Copacks
PLUS247TM-(X) ISOPLUS247TM-(R) IXGH16N170AH1 1700 V 11 A 4.00 V 1.1 mJ 0.65°C/W TO-247
CU IXGT16N170AH1 1700 V 11 A 4.00 V 1.1 mJ 0.65°C/W TO-268
PHASE LEG GU QU
IXGR16N170AH1 1700 V 8A 4.20 V 1.1 mJ 1.10°C/W †ISOPLUS247™
IXGH24N170AH1 1700 V 16 A 4.50 V 2.2 mJ 0.5°C/W TO-247
EU, CL IXGT24N170AH1 1700 V 16 A 4.50 V 2.2 mJ 0.5°C/W TO-268
IXGX32N170AH1 1700 V 24 A 4.20 V 3.0 mJ 0.35°C/W PLUS247™
GL
QL
IXGR32N170AH1 1700 V 17 A 4.20 V 3.0 mJ 0.65°C/W †ISOPLUS247™
ISOPLUS-i4PAKTM-(F) ISOPLUS-i4PAK-STM-(F..S) Phase Leg Packages
EL
If the application
Fig 5. Software components of the reference design meter. Each of the tasks is called by a central task wheel without
will be written in
pre-emption. Higher priority tasks occur earlier in the task list and thus get an earlier chance at processor cycles. The
C, plan on between message board facilitates inter-task notifications, as depicted by bold arrows in the diagram.
16 kbytes and 64
kbytes of code space. The reference design presented here needs to be updated. For these events, the system maintains
fits comfortably in 32 kbytes. a set of bits, each of which is set by one task to alert another
● Data space. Make sure your microcontroller has enough task that there is a condition that requires its attention. This
data RAM to accommodate your data structures. set of bits is called the “message board.”
● Data converters. While many microcontrollers have In a practical meter design, the data elements to be
“data acquisition systems” built onto the die, often they
are low speed, low resolution or both. An ideal converter
for a Class-1 meter as defined in IEC61036 would have
14-bits or better resolution, and 10-ksps sample rate or
better.
● Real-time clock. Make sure the clock is trimmable to
data, configuration
7. The Message Builder appends a preamble and information, and
1. Character by character, the calculates the checksum and passes the message,
Serial Port Driver alerts the byte by byte, to the Serial Port Driver. many commands
Message Checker that data Serial
is incoming. Port are transferred to
Driver and from the meter
2. Message Checker 8. The Serial Port Driver
acknowledges each acknowledges each byte as using a series of
character as received. it is transmitted.
registers. Each reg-
9. After the last
3. When Message Checker byte, the Message Builder Message
ister is designated
Message
receives a complete, valid clears the flag toward the Builder by a four-digit hexa-
Checker
message, it alerts Message Formatter.
the Message decimal number
Decoder. 6. After creating the response, the and contains one
Message Formatter alerts the
Message Builder. piece of informa-
10. As each flag is tion: register 9010
4. Messages that require a Message cleared, completion notification Message
register read are routed to Decoder flows up the chain until finally the
contains information
Formatter
the Register Manager. Message Checker is notified. The about current usage
system is now ready to
process the next message.
while register C032
5. The Register Manager contains the serial
Register retrieves data from the number of the
Manager register and passes it to the
Register Formatter. meter.
Figure 6 illu-
Fig. 6. Message processing in the electric meter reference design. Inbound messages are assembled, decoded and strates how a mes-
processed; outbound messages are formatted and built by separate tasks that communicate with one another using s a g e r e q u e s t i n g
a message board. data from a register
maintained in storage and the data formats will depend would be handled. In the illustration, the request begins
strongly on the communication protocols that are used. The as it is received at the serial port manager and flows
reference design was based on DL/T 645, a Chinese electric counterclockwise, activating each task along the way until the
meter communication standard. In this standard, usage requested data is finally transmitted at the serial port manger.
module. As each byte comes in, the serial port driver sets a
bit in the message board to notify the message checker task
of the event.
● When notified, the message checker consumes the