CC Blog Projects Research & Design Hub

Build a Wattmeter/PowerGrid Analyzer

Figure 1 The finished, assembled Wattmeter/Power Grid Analyzer

A power analyzer measures the flow of power using one current and one voltage input in an electrical system. Arduino-based power grid analyzer can be a cost-effective and efficient solution. It is easy to reproduce or use for any project.

  • How to build a Wattmeter/PowerGrid Analyzer?

  • How to utilize display?

  • How to use a current sensor or a voltage sensor?

  • What is an anti-aliasing filter?

  • How to reduce the error in the computation of powers?

  • How do you represent the time domain and frequency domain?

  • Arduino Narrow

  • dsPIC30F6014 16-bit microcontroller

  • Sitronix ST75256 driver

  • LSI controller

  • LCD systems

  • ST75256 screen controller

  • True RMS voltmeter

  • LM4040 micropower shunt voltage references

A power analyzer measures the flow of power using one current and one voltage input in an electrical system. Arduino-based power grid analyzer can be a cost-effective and efficient solution. It is easy to reproduce or use for any project.

The project described here is an improved wattmeter/power grid analyzer (Figure 1), for displaying the electrical power of any circuit or electrically powered device. Expensive, professional ones are available, but demand exists for a low-cost, open-source meter. I wanted it to be as easy to reproduce and as flexible as possible. The objective was to display the waveforms of currents and voltages, the current’s spectrum, and four measures of power— apparent power, active power, reactive power, and deforming power. The meter in this project is dedicated to small powers of electrical current (I <10A or 20A), but one can choose another current sensor if more power is required.

This wattmeter (Figure 2) is based on an Arduino Narrow, the memory of which is wider than usual (16KB of RAM, 128KB of flash memory, and 4KB of EEPROM). This Arduino board requires the installation of MightyCore. The cost of the Arduino Narrow is about 35 $ and the cost of the entire project is between 80 and 100$. This project was part of the evolution of a personal project I’ve led with a dsPIC30F6014 16-bit microcontroller. Although basic Arduino boards are based on modest 8-bit microcontrollers, they proved to be as fast as my 16-bit dsPIC for this task, thanks to their reduced instruction set computer (RISC) architecture and optimized compilation.

Figure 1 The finished, assembled Wattmeter/Power Grid Analyzer
Figure 1
The finished, assembled Wattmeter/Power Grid Analyzer
Figure 2 The interior of the finished, assembled Wattmeter/Power Grid Analyzer
Figure 2
The interior of the finished, assembled Wattmeter/Power Grid Analyzer
DISPLAY

The display is a modest 256×160 pixels. It uses a Sitronix ST75256 driver and LSI controller for four-level gray-scale graphic dot-matrix liquid crystal display systems. The four gray levels offer more display possibilities than a monochrome display with only twice as much data, and the display refreshes much faster than a color LCD display. This is a good compromise in my opinion. One needs at least a 128×128 pixel zone for graphics, plus a zone for the measures and a zone for the menu. The definition of this screen exactly fits that specification.

To get fast rendering, the screen picture is created into the RAM (it takes over 10KB) of the Arduino Narrow, then the screen can be refreshed when desired. The refreshing time via SPI connection is about 100ms. This is fast enough to make the changes look instantaneous, knowing it is inferior to the settling time of the screen. Moreover, creating the picture to be displayed into the RAM is much faster than via the screen’s controller. With its 16KB RAM, the Arduino Narrow is helpful for this method. Finally, creating the picture plus refreshing the screen won’t be much faster than creating the picture via the controller, but it will be much cleaner.

An additional constraint was that I had to write my own graphical set of functions. The U8G2 library is supposed to support the ST75256 screen controller, but only in black-and-white mode. Consequently, only a few basic functions of this library were used.

— ADVERTISMENT—

Advertise Here

Note that with the chosen display mode, the controller’s RAM is organized as follows: there are 256 columns of 41 bytes each. Only the first 40 bytes of a column are displayed. The configuration I chose allows that pixel (0,0) will draw a pixel at the left-bottom corner, which is the common scientific mind-view.

SENSORS

The perfect transformer’s formulas are:

Whether it is in series or parallel, it can be used as a current sensor or a voltage sensor. In both cases, galvanic isolation is ensured. And in both cases, this kind of sensor is not suitable for continuous current, because of the magnetizing inductance. This is not an issue for our purpose, since the voltage won’t have a continuous part, and even if the current has, that won’t change the calculation of powers. Don’t expect to use the same transformer for the power supply and the voltage sensing, however, because of the transformer’s imperfect impedance.

Finally, there are 10 automatic ranges for the current’s display, so that it is always clearly displayed, though the resolution is not that comfortable, and there are two ranges for the current’s measures, through the use of two windings of 1 whorl and 9 whorls. Switching between those two measuring ranges is performed by the software and via a relay and freewheeling diodes that ensure the current’s continuity during switching. These freewheeling diodes also serve after switching to dissipate the energy stored into the 9-whorl winding. An intermediate transistor Q1 is necessary to support the 71mA current, and there’s also a freewheeling diode for the coil of the relay to protect Q1. One may use a sensor based on the Hall effect, but it may be noisier and not as linear.

The transforming ratio is k=1:1000 for both versions of the current sensor (10A or 20A), so we get k×R9=0.1 VA-1 if R9=100Ω, which is the recommended value by the sensor’s manufacturer for a 10A sensor, and k×R9=0.05 VA-1 if R9=50Ω for a 20A sensor. Thus the maximum voltage swing before the ADC will always be:

which represents 69% of the reference voltage. Getting closer to 100% is tempting because of precision issues, but in my opinion, it is better to keep a margin.

Consequently, one has to measure the output voltage without load, which is not the same from one manufacturer to another, and adjust the value of R7: 27kΩ for 9V to 47kΩ for 15V (for mine). RV2 can help adjust the voltage bridge. Fortunately, the voltage can be easily measured (more easily and safely than the current) with a True Root Mean Square(RMS) voltmeter.

SAMPLING RATE, ADC, AND FFT

The sampling frequency is fixed at Fs=64×Fpower_grid and the number of samples is fixed at 256. Thus, the frequency step of the FFT is:

and the Nyquist frequency is 32×Fpower_grid.

— ADVERTISMENT—

Advertise Here

So, the sampling frequency is 3,200Hz (50Hz) or 3,840Hz (60Hz). No windowing is required because the sampling frequency is a multiple of the power grid’s frequency. Nevertheless, I have included a triangle windowing option in the menu, just for aesthetic considerations.

Amplitudes of harmonics are indicated concerning the fundamental amplitude, which is set to 100%. This helps to utilize the small-definition screen.

The ADC of the Arduino is close to its maximal sampling rate, as we have to convert both current and voltage with a conversion time of 104µs. 2×104=208µs and 1/3,840=260µs.

[Note: The margin is low, so it does not help to do something other than waiting during the acquisition process based on timer interrupts.]

The voltage resolution is 0.8V (0.4V), and the current resolution is 4mA (8mA) in the smallest range. I wish it were a 12-bit ADC, especially to get 1mA resolution, but 10 bits is enough for powers as low as 1W.

The external analog reference is provided by a little shield having two outputs—2.048V and 4.096V. The 4.096V serves as a reference for the ADC, and the 2.048V serves as virtual analog ground. This shield uses two LM4040 micropower shunt voltage references.

PROCESSING POWERS’ CALCULUS

Here is how the measures are computed:

These are the RMSs of the voltage and the current.

Then S=U×I

and

These are the powers.

I won’t discuss the reactive power Q and its five or more possible definitions. The calculation method in the equation given here has the advantage of simplicity but can be modified if desired. In my opinion, one may legitimately desire good precision on the active power, but the precision on Q is rarely an issue. The simpler, the better.

The deforming power is “the rest of S,” but we won’t know about its sign, which is positive most of the time. Note that D can be negative if the power grid’s voltage is still deformed. This is a case study. The higher the number of samples per period and the better the anti-aliasing filter, the more precise the calculation will be. The more important parameters for the precision are the ADC’s quantum and linearity and the sampling frequency, but a good anti-aliasing filter helps, too.

ANTI-ALIASING FILTER

The voltage doesn’t need an anti-aliasing filter, but the current does. A third-order Bessel filter is used. The efficiency of anti-aliasing is moderate, but it’s also important that the step response has no overshoot. It also serves as an anti-noise filter. The frequency cut-off is 1,200Hz (or 1,440Hz). The voltage is filtered with the first order with a frequency cut-off chosen so that the time delay is about the same at Fpower_grid and first harmonics. Apply the same filtering on both voltage and current, but we can assume that the voltage’s harmonics are poor and that the power’s calculus won’t be affected.

The first stage of the filter is shown in Figure 3.

Where Iin is the current of the power grid and Iout is the output current of the sensor.

— ADVERTISMENT—

Advertise Here

A level adjustment is performed by U2:A and the second-order low-pass (completing the third-order Bessel filter) is performed by U2:B with a Sallen-Key structure. The capacitors are shown in Table 1.

A schematic of the mainboard is given in Figure 4.

Figure 3 Utilizing the current sensor—input current of the power grid and output current of the sensor
Figure 3
Utilizing the current sensor—input current of the power grid and output current of the sensor
Table 1 Choosing the capacitors
Table 1
Choosing the capacitors
Figure 4 Mainboard schematics, showing the Arduino Narrow, third-order Bessel filter, current and voltage sensing, and power supply
Figure 4
Mainboard schematics, showing the Arduino Narrow, third-order Bessel filter, current and voltage sensing, and power supply
PRECISION ISSUES

Let’s talk about the error in the computation of powers due to limited sampling rate, and how to reduce it. Let’s consider a simple example. The current is a series of impulses twice more brief than Ts. If the impulse is detected, then the error is +100%. If the impulse is not detected, then the error is -100%. (The corresponding point is encircled in Figure 4). If an anti-aliasing analog filter is inserted before the ADC, then the impulse is always partially detected. But what about the remaining error in the computation?

The answer is the result of rather heavy mathematical concepts led in the frequency domain and rather heavy computation that results in the curves shown in Figure 5, which gives the error vs. Ti/Ts where:

• Ti is the duration of the square impulse.

• Ts is the sampling period.

The demonstration is given as additional material.

Figure 5 Error due to limited sampling rate
Figure 5
Error due to limited sampling rate

What one can expect is that, whatever the configuration and the shape of the current are, the max_error on the power calculus will globally decrease like 1/Fs. In addition, in practice, one will be faced with a rectangle- or triangle-like impulses, not square. The consequence is that the max_error will be even lower in all cases.

Finally, one has to choose an anti-aliasing filter. Obviously, a first-order LP is not enough. I have chosen a third-order Bessel because it is a good compromise with concerning the efficiency and complexity of the circuit.

The worst-case scenario is the stand-by mode of an item using the combination of a Graetz Bridge followed by smoothing capacitors. This concerns low powers, so we can expect that the max_error will grow over 10% only for power <1W, so that the chosen resolution (0.1W) is consistent with that study. The combination of medium sampling rate and medium anti-aliasing filter is therefore a good choice!

TIME DOMAIN REPRESENTATION

Both voltage and current are plotted over two periods while four periods are acquired (256 samples). Note that acquiring three periods would only be enough to perform an appropriate trigger, but would not be enough for an appropriate FFT.

There are 64 samples per period, and the representation uses 1 pixel per sample. This is close to the minimum configuration for such a project. Triggering is performed on “the rising edge of the voltage.” The gray level of the voltage is 2, and the gray level of the current is 3 so they are relatively easy to distinguish. Both voltage and current are plotted in XOR mode. The XOR mode allows faster operation (because there is no need to redraw the chronogram), and provides rather esthetic effects where curves cross, which helps legibility.

FREQUENCY DOMAIN REPRESENTATION

The fundamental is set to 100%, and the rest of the spectrum is adjusted with respect to the fundamental. Theoretically, harmonics can be higher than the fundamental, but one will rarely face such a case in practice. Nevertheless, plotting harmonics higher than 100% is possible, just in case. Let’s recall that no windowing is required because the sampling frequency is chosen as a multiple of the power grid’s frequency. Anyway, the library allows you to add many kinds of well-known windows. As mentioned earlier, I added a triangle window option to the environment, motivated by purely aesthetic considerations. It is easy for you to replace it with any other.

The representation’s scale is 1 pixel per percent. To get better precision, the relative amplitudes of first odd harmonics are given with 0.1% resolution, so that a log scale is not required. Note that most of the time there will be only odd harmonics because most of the current’s waveforms will have a sliding symmetry. Nevertheless, in the future, I’ll add the ability to give also the amplitude of even harmonics. I will also add the ability to plot the voltage spectrum.

HUMAN-MACHINE INTERFACE

A schematic of the Human-Machine Interface (HMI) for the screen is shown in Figure 6.

First, note that the screen is driven in SPI mode, whereas the names of the pins correspond to parallel mode, but it is how it is written onto the physical screen. That screen exists with different sizes (the one I used is the smaller), different colors (white or blue), and may or may not integrate a 3.3V regulator (this one has none). One can also buy this screen without a circuit board. My first intention was to use this version because it is a little cheaper and more compact, but it would have been too delicate to reproduce for many hobbyists.

The backlight is driven directly by a digital output D4 of the Arduino Narrow. The maximum current, with the chosen value of R12, is about 13mA. One can lower R12 with a comfortable margin because the digital outputs of an Arduino are supposed to provide up to 40mA.

There is a numerical joystick, which is demonstrated in a video that can be viewed via the QR code in Figure 7. The actions of which are: Up and Down to navigate inside the menu; Left and Right to change the values or to activate the functions. The joystick activates a voltage divider having four possible output levels: 4.096V×{4/4;3/4;2/4;1/4}. With this method, only one analog input is required. Nevertheless, the software has to wait for a value’s confirmation. This imposes a response time between 350ms and 700ms, because of the main loop’s duration. In practice, this is neither too slow nor too fast.

There is also an additional button, whose function is to switch between RUN and STOP modes (Figure 6). Unfortunately, no screenshot is possible during STOP. This is an enhancement I will have to perform in the future.

Figure 6 Schematic of the Human-Machine Interface (HMI)
Figure 6
Schematic of the Human-Machine Interface (HMI)
Figure 7 QR code linking to a YouTube video on the Power Grid Analyzer. In the video, the author explains the instrument and demonstrates the actions of the joystick and RUN/STOP button.
Figure 7
QR code linking to a YouTube video on the Power Grid Analyzer. In the video, the author explains the instrument and demonstrates the actions of the joystick and RUN/STOP button.
SOFTWARE

The software for this project is written in C, not C++. One only needs two libraries—one that helps drive the graphic controller, and one that helps perform the FFT for the frequency analysis of the current.

The graphic library U8G2 is only used for basic operations because it is not suitable for four gray levels mode. Though it was not written in C++, I tried to get it as clear as possible. One has to configure the program for 100V-127V or 220V-240V by setting power_grid_voltage, and for 50Hz or 60Hz by setting power_grid_freq at the beginning of the program. These two settings are separated because the four configurations are used in different countries.

The contrast, backlight and phase adjustments are set by the software via the menu, and all the settings are saved into the EEPROM. The phase adjustment is necessary to get a precise reactive power measure. A purely resistive load would be helpful for this adjustment (adjust until Q=0).

There is a screenshot function that sends a bitmap file, but it is not easy to use. Maybe I’ll write a software program to make the file easier to retrieve, or I’ll make a YouTube video to show how to proceed. I have not yet implemented ”save” and ”recall.”

The second required library is arduinoFFT-master. The remaining RAM is about 780 bytes. This is enough for future developments, such as an energy counter. The last thing is that I have integrated two pictures into the ABOUT that can be changed. The pictures are stored in the 4-bits-per-pixel (16 gray levels) BMP format (without the header) and are displayed with the “error diffusion” method.

EXAMPLES OF DISPLAYS

Three example screenshots of the display are shown in Figure 8 and discussed below.

Figure 8 Some example screenshots of the display
Figure 8
Some example screenshots of the display

The first example is a USB-C charger. The current waveform informs us that it is probably composed of a Graetz Bridge followed by a smoothing capacitor (and probably a step-down). This is a bad consumer with concerning the power grid (bad power factor), though it probably has very good efficiency, and the current’s spectrum is (too) rich but typical. Note that the amplitude of harmonics over 1,200Hz (or 1,440Hz) is not very reliable, since there is the growing action of the anti-aliasing filter, and there are aliased harmonics because of the imperfect anti-aliasing filter. Fortunately, both errors will partially compensate themselves in most cases.

The second example is a 120W notebook power supply with a medium-quality Power Factor Corrector (PFC). There is a clear intention to lower the ×3 harmonics. This is enough to get the power factor close to 1. Unfortunately, these days, the H5 harmonics are the first enemy of your energy provider.

The third example is a small radiator. This load is almost purely resistive, though there may be a slight inductive part and a slight temperature undulation (≥ slight resistance undulation).

As you can see from these examples, this analyzer can give you an idea of “what’s inside the box” with a minimum of knowledge required.

THE BOX

Views of the front and rear bottom of the enclosure for the wattmeter/power grid analyzer are shown in Figure 9. This box was constructed using 3D printing.

STL files are provided, to allow readers to reproduce the box [Additional material]. There are four pieces to print. Using conductive PLA is recommended, except for the protection, but is not necessary, even considering noise issues. The time and PLA cost for producing the box are given in Table 2.

Table 2 Time and PLA costs for the box
Table 2
Time and PLA costs for the box

The resulting box is soft and flexible rather than rigid. Once the box is closed, it would break only if dropped. I thought it was important to provide this box, because the integration of a screen is always a problem, and I also provide a fairing option for those who wish to use a metal box.

The only difficulty comes from the joystick; different qualities of PLA give different sizes of holes, so one may have to adjust the size of the hole until it can be plugged.

BUILDING THIS ANALYSER

I’ve tried to make this project as easy to reproduce as possible. Artworks are given with 600dpi resolution and in mirror viewing for better insulation. I also give the Proteus files of the mainboard and the Gerber files for both of them.

Two small difficulties remain about soldering. First, on the HMI’s circuit board, the 14-pin connector has to be soldered on the copper side. Make 0.8mm holes, which are too small, but will maintain the connector during soldering. Second, on the main circuit board, the soldering of the two windings requires a little bit of attention, as shown in Figure 10.

Figure 10 Current sensor and windings. The first winding, (shown in red) from pins 1 to 2 is 1 whorl with 2.5mm2 isolated wire. The second winding (shown in green) from pins 3 to 4 is 9 whorls with 0.75mm2 isolated wire.
Figure 10
Current sensor and windings. The first winding, (shown in red) from pins 1 to 2 is 1 whorl with 2.5mm2 isolated wire. The second winding (shown in green) from pins 3 to 4 is 9 whorls with 0.75mm2 isolated wire.

The first winding (from 1 to 2) is 1 whorl with 2.5mm² isolated wire. The second winding (from 3 to 4) is 9 whorls with 0.75mm² isolated wire. Note that one should solder the current sensor and the two windings before anything other than the straps.

CONCLUSION

I hope that many readers will find this project easy to reproduce or to use for their projects (box, HMI). This may be a valuable device in the future for enhancing the power factor of an existing system or simply monitoring its consumption. It seems important to me to recall the necessity of consuming electricity with a good power factor. Remember, though, that low consumption is not enough.

I plan to update the software for this project in the future. The first evolution will be an energy counter. Of course, readers are free to change whatever they want in the software and even the hardware, since I provide the Proteus files of the mainboard. One can follow the evolution of this project and/or find additional materials on my website (muselec.fr).

My next project will be a active load for studying the behavior of a power supply downstream when this analyzer is used upstream. 

RESOURCES
Go Tronic | www.gotronic.fr
Mouser Electronics | www.mouser.com
Microchip Technology | www.microchip.com
MUSELEC | www.muselec.fr

PUBLISHED IN CIRCUIT CELLAR MAGAZINE • JUNE 2022 #383 – Get a PDF of the issue

Keep up-to-date with our FREE Weekly Newsletter!

Don't miss out on upcoming issues of Circuit Cellar.


Note: We’ve made the May 2020 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Would you like to write for Circuit Cellar? We are always accepting articles/posts from the technical community. Get in touch with us and let's discuss your ideas.

Sponsor this Article
Website | + posts

Circuit Cellar's editorial team comprises professional engineers, technical editors, and digital media specialists. You can reach the Editorial Department at editorial@circuitcellar.com, @circuitcellar, and facebook.com/circuitcellar

Supporting Companies

Upcoming Events


Copyright © KCK Media Corp.
All Rights Reserved

Copyright © 2022 KCK Media Corp.

Build a Wattmeter/PowerGrid Analyzer

by Circuit Cellar Staff time to read: 15 min