Power measurement module

This is a small power measurement module that continuously measures current and sends the measurements via USB to a PC. The module was created for my graduation project to measure the power consumption of sensor network nodes. The device can be connected using a standard USB connection which also provides power for the hardware. The board contains a voltage regulator to produce a clean 3.3V voltage on which a sensor node can be connected. An ATtiny26 AVR contains a small piece of firmware that continuously measures the current used on the 3.3V line and sends this to CP2101 chip. The CP2101 is an USB-serial converter that transfers the data output of the AVR to a PC.

Current is measured 5760 times a second, a rate that was chosen to be convenient for programming. A measurement has a resolution of 8 bits and indicates a current between 0 and 24.38 mA. This range proved to be sufficient for all measurements and provides accurate enough steps of 95µA per step. The internal 20x gain of the ATtiny26 AVR is used to measure the small current.

Schematic

The schematic is straightforward. A 3.3V regulator provides the output voltage of which the current is measured by measuring the voltage over two 10.5Ω 1% resistors (I just happened to have these and used two to get a lower value but maintain precision). The CP2101 has handshaking lines of which RTS is connected to the AVR but I ended up not using it because of timing constraints and the fact that it worked fine without handshaking as long as the USB line was not busy. The ADC of the ATtiny26 is used in differential mode.

Power meter schematic

Hardware

The finished PCB and components looked like this:
Power meter module PCB top
Power meter module PCB bottom

Firmware

The AVR firmware is small, it basically just requests an ADC sample continuously and while it waits for this sample (there is a relatively large delay) it sends out the previous sample over the serial line. All samples are 8-bit, the most significant bits of the ADC sample are taken. This limits resolution but was sufficient for my purposes. The samples are alternated with a sequence number, as some form of synchronization with the PC software. Not very fail proof but it worked good enough.

Software

The PC software connects to the virtual serial port, synchronizes using the sequence numbers and then displays the results in a running graph. A selection can be made and exported to a CSV file for further processing. The error counter shows errors detected in the sequence numbers. Normally only a few errors occur at startup before the system is synchronized, after that the error counter should not change. If it does, don't rely on the data.
Graph in power meter module PC software

Source code

Both the firmware for the AVR and the PC software written in C# are available for download here. An AVR studio project to compile the firmware and Visual C# express 2005 project for the PC software are included as well. The PC software requires a single parameter with the COM port (such as "COM5") when run.

Source code is released under the BSD license.

Download powermeter.zip (17.7 KB)