Electricity Metering with Low-Cost Microcontrollers

Electricity Metering with Low-Cost Microcontrollers



A new electricity meter, based on a mixed-signal microcontroller, will automate the gathering and tracking of data about electricity usage. The new meter will be more accurate, reliable, and much more flexible than its mechanical predecessor. This application note discusses several topics, which must be addressed when designing a next-generation, microcontroller-based electricity meter. The reference design for a meter is presented.


Believe it or not, the first priority of electric utilities is not power generation or distribution, or even customer service. It is billing. Consider that every month, thousands of meter readers drive from home to home, manually reading millions of electricity meters. The collected data is then entered into billing systems, most often by workers reading the logbooks and keypunching the data. This veritable army of meter readers and office workers is, as much as anything, what keeps the utility financially alive. But to the utility companies, this labor expense is largely overhead. The reason the utility company needs to hire and train this army of employees is the electricity meter—usually a spinning disk in a glass case with a mechanical counter attached. With such meters, automation is difficult.

A new generation of electricity meters promises to automate the data gathering and tracking. Based on a microcontroller rather than a spinning disk, the next-generation electricity meter can be more accurate, more reliable, and much more flexible than its mechanical counterpart. Besides counting and automatically reporting the number of kilowatt-hours used by the customer, the microcontroller-based meter can also track when usage occurs, how much peak power was demanded, and whether the power factor is within acceptable limits.

This article describes how such an electricity meter can be constructed from a modern, mixed-signal microcontroller and a few additional parts.

Choosing the Right Microcontroller

In the past, microcontrollers were limited to supporting roles in most real-world systems. There were two reasons for this: first, most microcontrollers had very limited speed and storage resources; and second, microcontroller devices were strictly digital—any analog peripherals would represent another chip and more supporting components.

Modern mixed-signal microcontrollers put an end to these limitations. Combining high-performance analog circuitry, a high-speed CPU core, and a full range of communication and display peripherals, these microcontrollers serve well as the heart of a modern electricity meter.

Hardware Components

Choosing a microcontroller is, of course, only the first step. Components must also be selected to scale the voltage and current waveforms in the load, to provide the physical layer for the communication channels, and to provide nonvolatile data storage.

Deriving the voltage waveform is simple: a voltage-divider across the line serves nicely. To provide the -1V to +1V required by many ADC devices, it is necessary to divide the voltage waveform on a 240V circuit by a ratio of 400:1 to 600:1. A single-pole RC filter after the division performs anti-aliasing duty.

Measuring the current in the load can be performed in several ways, but the two most popular are to use a current transformer or a current shunt. A current transformer develops a voltage in its secondary circuit proportional to the current in the primary circuit. A current shunt used in this reference design (Figure 1) develops a voltage as a result of the IR drop across a resistance. To keep power dissipation low, the shunt resistor is often in the range of 250µΩ to 500µΩ. More details about the hardware components in this design can be found in application note 3819, MAX3120 Electricity Meter Reference.

Figure 1. A mixed-signal microcontroller is the heart of a sophisticated multifunction, multirate electricity meter. The reference design is based around the MAXQ3120 mixed-signal microcontroller. This microcontroller combines a robust analog front-end (including dual-channel 16-bit, ADCs with an internal voltage reference) and a powerful digital block (consisting of the 16-bit RISC core, a multiply-accumulate unit, two UART channels, and an integrated LCD controller).
Figure 1. A mixed-signal microcontroller is the heart of a sophisticated multifunction, multirate electricity meter. The reference design is based around the MAXQ3120 mixed-signal microcontroller. This microcontroller combines a robust analog front-end (including dual-channel 16-bit, ADCs with an internal voltage reference) and a powerful digital block (consisting of the 16-bit RISC core, a multiply-accumulate unit, two UART channels, and an integrated LCD controller).

In older power meters, communication was not an issue. When reading mechanical meters, the reader simply copied the value from the counter into a logbook. But modern meters use their communication channels to transfer billing information and configuration data using two mechanisms: noncontact and networked. This design provides both.

A noncontact reader transfers energy usage data without the device having to make physical contact with the meter. Often, a handheld instrument transfers the data using an infrared link. In this arrangement, a utility worker points a reader device at the meter, much as one might use a remote control to operate a television. A request packet is transmitted to the meter, which responds with the requested data. This usage data is stored on the reader until it can be transferred to the billing system.

A networked meter is usually found in a multifamily dwelling, such as an apartment building. In such an installation, all meters in the building "talk" on a network to a controller that polls them once a month. The controller then formats a set of messages containing the usage data for transmission to the billing authority. This meter uses RS-485 as a physical medium for networking.

For nonvolatile storage, the meter contains an I2C EEPROM device. Serial memory devices have provided reliable service over many years, and are available in sizes from 64 bits to 1Mb, or more. The device used in this design is 128kb.

Analysis of Meter Behavior

Once the hardware design is settled, the next question is software. But before the first line of code can be written, the system designer must determine how the meter should behave. That is, what is the meter actually expected to do?

Fortunately for the system designer, that question is largely answered in an international standard. IEC 61036 specifies a "Class 1" (1% accuracy) or "Class 2" (2% accuracy) electricity meter. This standard calls out not only accuracy, but mechanical, environmental, and safety parameters as well. In short, the IEC 61036 document describes what an electricity meter is. The standard has been adopted in one form or another as the national standard in nearly every country.

But IEC 61036 does not specify communication protocols that must be followed. This is a problem, as there is no single international standard for physical media, message protocol, or semantics for communication between a host computer and an electricity meter.

In the reference design presented here, we settled on a Chinese standard, DL/T 645. That document describes the physical layer, packet format, and rules for transmission that a meter (and a host computer) must follow.


The meter software can be broadly divided into two functional blocks. The first is the DSP subsystem. It receives the voltage and current samples from the ADC channels and calculates the voltage, current, power, and accumulated energy usage. The second block is the accounting subsystem. It takes the calculated energy from the DSP subsystem and accumulates it into one of several tariff registers. The accounting subsystem also manages communication, storage, and the display.

The process of measuring energy begins with the DSP subsystem. Every time a sample set is received from the ADC channels (in this design, every 48µs), the voltage and current samples are multiplied and accumulated. The product of instantaneous voltage and current is instantaneous power, and this can be accumulated to calculate the energy usage. The waveforms are also lowpass filtered to find the zero crossing. On every zero crossing, the accounting subsystem is notified.

When alerted, the accounting subsystem dumps the accumulated energy from the DSP into a larger accumulator, and clears the DSP accumulator. When enough energy has been accumulated, the accounting subsystem then updates the accumulated energy registers in the EEPROM. The accounting subsystem cannot update the EEPROM on every zero crossing because most EEPROM devices wear out after some number of write cycles.


There are four tasks that the communication subsystem must perform. First, some process must receive the stream of bytes from the communication driver and determine when valid messages have been received. Second, some process must receive the validated messages, and determine what they mean and what action should be taken. Third, when data is ready to be transmitted, some process must ensure that the raw data is formatted in a manner suitable for the communication packet. Finally, a process must physically build the packet and send it, byte by byte, to the communication driver. In this reference design, these four tasks are called the message checker, message decoder, message formatter and message builder, respectively.

When a valid message has been received and decoded, it is likely that the request will either be for the meter to send some measured value (energy, voltage, power, etc.), or to send or set some operational parameter (meter constant, serial number, etc.). In either case, the request is referred to the register manager. This software component is responsible for reading, writing, and maintaining the hundreds of registers that are defined in the DL/T 645 protocol. Please refer to the software discussion in application note 3819 (see above) for more specific details.


The display manager determines what data elements to display and how to display them. Making something appear on the microcontroller's display could not be simpler: the software just updates a register, and the display controller hardware in the chip does the rest.

The display controller selects an item to display and formats it for the LCD. In this design, the meter displays time of day, date, and accumulated energy. It then waits a prescribed number of seconds before selecting the next item and formatting that for the LCD. A detailed discussion of display parameters and display customization are found in application note 3820, Customization Guide for the MAX3120 Electricity Meter Reference Design.


An advantage of a microcontroller-based electricity meter is that it can assign energy usage to one of several tariff periods, which are defined by time of day and date. In this reference design, the schedule manager determines the tariff periods. Every minute the schedule manager checks whether a new tariff period is in effect. If it is, the schedule manager updates a RAM variable that contains the tariff period's number.

Obviously, the schedule manager requires an accurate clock; the electricity meter design provides a clock in one of two ways. First, the microcontroller contains a 32-bit UNIX-compatible system clock, complete with battery backup. While simple and cost-effective, the crystal that controls the clock is not temperature-compensated, and can drift when exposed to changes in temperature.

If a more accurate clock is required, an external, temperature-compensated time-of-day clock can be used. These devices contain a built-in temperature sensor and hardware that adjusts the clock operating frequency to compensate for the natural drift that affects all crystal oscillators over temperature. By using a temperature-compensated clock, accuracies of 30 seconds/month are achievable over the entire industrial temperature range. For more detailed information about utility tariff periods and how this reference design manages data collection from these tariffs, see application note 3793, Flexible Tariff Scheduling for Multirate Electricity Meters.


The methods for metering electricity are changing quickly. Within a few years, the wheel-based meter will be as quaint as the dial telephone. A new generation of microcontroller devices is paving the way for an electricity infrastructure that promises greater billing accuracy, more security, and more options for electricity service providers.

The complete electricity meter reference design on which this article is based, including Bill of Materials, is available for download.

A similar article appeared in the December 2006 issue of Metering International.