MENU

Building a power meter application with an 8-bit MCU

Technology News |
By eeNews Europe

In this product how-to article Radomir Kozub describes how to use Freescale’s 8-bit MC9S08LH64 to build an intelligent and accurate single-phase power metering design, while keeping a low cost bill of materials.

Electro-mechanical power meters have now been replaced by electronic versions. Electronic meters have a number of advantages over their electro-mechanical predecessors. Namely, the mechanical construction is more cost-effective and is simpler due to the fact that there are no moving parts.

Electronic PMs also have better accuracy coupled with wider dynamic range. Electro-mechanical PMs have a standard dynamic range of 1:80 at two percent accuracy; whereas today’s static PMs have a dynamic range of power measurement of approximately 1:1000 with one percent accuracy.

This article focuses on the construction and features of a static single phase power meter with direct measurement. Static means that Power Meters (PMs) do not contain any mechanical parts; rather, static meters are microcontroller based.

Direct measurement is the current flowing to the load – it is sensed on the shunt resistor. Voltage and current is measured using a high-precision AD converter; power is then calculated using the measured values and finally the power is summed in time so that total active energy [Wh] can be determined. Considering that voltage is stable in the mains, dynamic range of the PM is given by the dynamic range of the current measurement.

In addition, electro-mechanical PMs register and display only active energy value; while electronic PMs can measure and show additional information like active power, voltage, current RMS, peak values, line frequency, power factor or temperature. These values may then be read via an electronic interface, such as RS232, RS485, MBUS or IRDA.

A static PM provides enhanced security as well. As today’s electricity rates continue to climb, tampering has become an increasingly common phenomenon. An electronic-based power meter has the capability to sense direction change in current flow, partial earth, missing neutral condition or lid removal.

Power consumption is an important component in meter design as well. Millions of the PMs currently installed consume a significant amount of power. Thus, the power budget for the meters themselves must be strictly limited. Total losses in current sensor and meter electronics are limited to 2W and 10VA.

Static single phase power meters should be compliant with EN62056 and EN50470 regulation. Particular requirements for static electricity meters for active energy (class indexes A, B and C) are stated in EN50470-3.

This regulation describes the requirements for voltage, current circuits, self power consumption and various tests for accuracy, the influence of noise, temperature, over and under voltage, over current or harmonics.

The EN62056 standard describes local data exchange and describes how to use COSEM over a local port (optical or current Single Phase Power Meter Basic Requirements). There are several features required for today’s PM design. All requirements must conform to regulation EN50470-3, including:.

 

a) Input voltage: PM should work with U.S. and European main voltage of 230 (120)V, 50 (60)Hz.

b)
Overall power consumption: This must not exceed 2W. This limits maximal resistance of the current sensing element and consumption of the electronic circuit. The power consumption of a PM (electronic circuit) itself is less than 100mW, and the majority of the power is consumed on shunt.

Shunt resistance is then R = P/I 2 = aprox.312 micro-ohms. A standard 300 microOhm shunt resistor is used in the design.

Therefore, PM consumption is restricted to 10VA as well, which restricts the amount of current drawn from the capacitive power supply. Using a capacitive divider power supply gives approximately 8mA power budget, if a 470nF capacitor is used.

c) Accuracy: PM accuracy is set to 5(80)A at one percent (B class of EN50470-3).

For today’s single phase PM, it is sufficient to meet 5(80)A specification, meaning the dynamic range of the measured current is 1:320.

There are some current thresholds, such as Istart, Imin, Itr that border on the accuracy needed by EN 50470. Maximal current Imax measured with full accuracy (one percent) is set to 80A. PM must withstand short over current Imax * 30 = 2400A.Reference current Iref is set to 5A. Iref is referenced to Imin, Itr and Istart by EN50470-3.

Imin = Iref / 20 = 250mA. Imin is minimal current where the PM must measure with determined accuracy (+-1.5% for B class). Out of those values, the dynamic range of the current measurement is Imax / Imin = .25 / 80 = 1:320.

Istart = Iref / 250 = 25mA. The PM must start to register energy when the current is bigger than Istart accuracy is not measured.

Irt =Iref/10 = 500mA (Itr is threshold for full accuracy – one percent).

d) Standard metering functionality: Voltage RMS, Current RMS, Active Power, Active Energy, Real Time Clock

e) Optoisolated and optical (LED) energy pulse output must be present to enable power meter calibration and accuracy verification.

f) LCD interface and button need to show all measured values. The button should switch among displayed values.

g) Tamper switch to detect lid removal: mains connectors should be placed under the lid. The PM monitors any manipulations with the mains connection, even if there is no voltage on the mains.

h) Infrared interface and RS232 opto-isolated serial interface are used for metering data reading.

Blocking out the design
As mentioned above, the design in Figure 1 below shows static single phase PM with direct measurement – shunt. The measurement segment is made up of the several blocks.


Figure 1. A reference design based on the 8-bit Freescale MC9S08LH64 MCU, suitable for metering applications as a single phase power meter.

The most important block for accurate measurement is the ADC converter and voltage reference. Precise time base is also critical, because energy is integral to the power in time and measurements must be made in real time due to tariff switching.
 

Interface parts include an LCD interface to drive display and a button for manual data reading. For automated data reading, the PM uses an infrared interface (EN62056-21), optoisolated RS232 and energy pulse output. Some interrupt input for tamper sensing is also needed.

ADC converter. An ADC with 14.5 ENOB accuracy is suggested for a single phase electricity meter application. Does the 14.5 ENOB work for accuracy requirements of 1:320 at one percent? Class B allows 1.5 percent error in interval

  ENOB = ln (1/DR * err)/ln (2) = ln (1/320*0.015)/ln(2) = 14. 38 bit

The MC9S08LH64 MCU provides an AD converter with 14.5 ENOB, which is sufficient for defined current dynamic range. The accuracy of energy calculation is further improved by averaging in the calculation algorithm.

Differential input should be used for current measurement in order to reach the best possible noise-free signal with doubled dynamic range. On the voltage measuring path, there are no strict requirements, as voltage of the mains vary from a maximum + or – 20 percent to a nominal 230(120)V.

If the MCU has only one ADC converter with MUX, the MCU has to switch ADC between voltage and current inputs. The MC9S08LH64 MCU provides hardware triggering with “ping-pong” mode, which takes the samples in the proper time and switches the two inputs via the hardware.

An interrupt is then issued once both conversions are finished. Ping-pong mode is ideal for PM applications as it minimizes CPU time needed for sampling. Phase shifts between voltage and current signal may be compensated by time delay between voltage and current samples. The A/D converter supports hardware averaging up to 32 samples.

Voltage reference. A 16-bit SAR AD converter may use internal voltage reference. Freescale’s 9S08LH64 voltage reference is based on compensated bandgap diode and has 1.2V @ 40ppm/°C. Reference is trimmable by 8-bit register in 0.5mV steps. For example, the micro adjusting of the reference voltage might be considered for use as the overall measurement error compensation against temperature. (Tip: Internal bandgap diode may be used for temperature measurement.)

Time reference. A 32.768Hz crystal reference might be used to pair both the precise CPU bus clock together with Real Time Clock signal source. Crystal frequency is multiplied in FLL module to get bus clock 19.922 MHz to utilize CPU calculation power.

The “Time Of Day” (TOD) module is embedded in the 9S08LH64 and may be sourced directly out of the crystal. The TOD module runs even if the MCU is in the stop mode and may wake up the MCU in pre-defined time. This functionality provides the advantage of creating real time and calendar time in software.

Stop mode and power consumption
Power consumption in the stop mode has a direct impact on the battery capacity needed. Thus, a microcontroller that offers great power consumption and a wide set of low power modes is most effective. The clock distribution module enables all peripherals to be clocked separately, therefore saving the battery capacity.

 

In this reference design, the microcontroller core draws around 700nA@3V in the lowest power mode (RAM, registers, I/O pin state is maintained). Another current is required to run the crystal low-power oscillator, TOD module to keep the Real Time Clock (RTC) and KBI module for tamper and button. This means the overall power consumption of the PM running on battery is around 1.5 microamperes.

The LCD driver embedded in the microcontroller should have considerable low power performance so that the display may show values in stop modes as well. Driving all the segments to ON-mode in the lowest consumption power mode requires only an additional 2 microamperes.

LCD module
The LCD module on the MC9S08LH64 provides 64 LCD pins with selectable frontplane/backplane configuration (up to 63 frontplane and 8 backplane). The programmable LCD power supply switch makes the MC9S08LH64 an ideal solution for battery-powered applications.

Dual Array Flash Memory
Another feature that helps keep BOM costs low is dual-array Flash memory. The entire HCS08 Freescale family offers the possibility to write/erase flash memory in runtime. Dual-array flash memory makes it possible to run code from one flash array while simultaneously writing/erasing to the second array.

All calibration data, parameters, counters or tamper events may be stored in flash instead of in external EEPROM. The MC9S08LH64 can be flashed from as low as 1.8V supply voltage over the whole temperature range, which simplifies battery selection.

Metrology software processes voltage and current samples that calculate all metrological values such as Active Power P, Active Energy W, Effective Voltage Urms and Effective Current Irms.

The product of the voltage and current samples for given time periods results in Active Power [W] as shown below.

Summing the Active Power in time results in Active Energy as shown below.


In the design, both voltage and current are sampled at 6.4ksamples/sec. Mains frequency is 50Hz, which gives approximately 128 samples per one mains period. In Figure 2 below, the simplified calculation data flow can be seen and the individual steps are outlined below:

(1) With each ADC conversion complete interrupt (1/6400 sec), the voltage u(n) and current i(u) samples are processed.
(2)
Simple IIR filter is used to remove measured voltage DC offset.
(3)
Product of the filtered voltage sample and current sample (power) is accumulated 128 times. Filtered voltage sample is squared and summed 128 times as well.
(4)
For each 20msec (roughly one mains period), the power P is recalculated by the gain calibration coefficient Pgain.
(5)
The resulting PC divided by time (60 min * 60 sec = 3600) is added to the total Active Energy counter.
(6)
The PC is sent to the output energy pulse generator. The last operation in the mains period interval is Pc summing. Metrological values are updated on the display each second.
(7)
The Urms is counted as u’’ square root multiplied by gain calibration constant. Active power is the result of the one second integration and is updated to display value and is used for the current calculation. The value of the total active energy counter is updated for displaying. All mentioned display values are updated in one second interval.


Figure 2. Simplified power meter calculation data flow.

Conclusion
The Freescale 8-bit MC9S08LH64 offers the ideal set of features and peripherals to build an intelligent and accurate single-phase PM design, while keeping a low cost BOM. An impressive performance measurement chain – 16-bit SAR AD converter, together with precise trimmable voltage reference and hardware triggering makes it possible to build even an A-class PM with a reasonable current dynamic range.

The 8-bit CPU, running on the ~20Mhz bus clock is powerful enough to process a 6.4k sampling rate and to handle all necessary PM features. The dual array FLASH is ideal for storing the calibration values and tamper events, as well as counters without external EEPROM. The LCD module can drive up to 288 segments, which is sufficient for this type of application.

Power consumption of the entire design is essential, as it has a direct impact on the battery capacity needed. PMs draw around 1.5 microAmperes keeping real time, sensing tamper and button. The LCD display draws an additional 2 microAmperes, so values may be shown when running on battery. The MC9S08LH64 also provides many communication peripherals to meet all designer needs (SPI, IIC, UART).

Radomir Kozub is an application engineer at Freescale Semiconductor.


Share:

Linked Articles
eeNews Power
10s