The software is running on a PIC16F877a microcontroller made by Microchip. Some people have a programmer device which connects your computer to the microcontroller to upload programs and data. We will have preprogrammed chips available soon, so you won't need to have any extra tools or know how microcontrollers work to build one of these. They are really cool to have though. I own the
The analog circuit measures the voltage and current traveling through the mains. These are converted from large voltages (120VAC) and currents (0-20 A) to small voltages that can be read by the microcontroller and then displayed on the LED display.
The analog circuit connects with the digital circuit through 5 signals:
All of the signals are connected to the PIC's analog to digital converters. vref- and vref+ are used by the converters as the minimum and maximum range for the other 3 signals. These sample the voltage of each signal at around 2khz with a resolution of 10 bits (possible values are 0-1023). These samples are then used to compute the power consumed and the output is displayed on the LED display.
Power is computed by multiplying the voltage and current and then averaging these values. This calculates the real power. For more information about what exactly power is, please see the Power page on wikipedia.
First, the voltage reference is subtracted from the samples read from voltage and current. This is because they are sin waves whose center is at voltage reference. These centered values are multiplied together and then added to a total for calculating an average. The values are sampled or measured about 1000 times per second. Each reading is currently 256 samples long. The averages are then fed through a 5 value running average to provide a more stable reading. This running average is the value displayed.
How does an LED display work?
To accomplish this, each digit must be turned on in between sampling the data. So, a few samples are read from the pins, the first digit is turned on. Then a few more samples are read and the next digit turns on. The digit is rotated about every 4 samples, however this may be changing in the near future with due to a faster clock speed.
More details coming soon. If you have specific questions post a comment here or in the forums. I hope to explain a lot of this in a lot more detail, but I can start with the things people are most interested. There are also some comments in the code. So please refer to that to better understand how this is working.
The code is available at the bottom of the page. hex files, c code and asm code are all provided. All coding was done with piklab compiling with sdcc under linux (although these tools also work under windows and mac). The code should work with minimal changes using other compilers. Let me know if you'd like to get it working in another environment, I will try to help, I have used others before and might know where to look for changes. To those of you who don't know what any of this means but would still like to build one of these, let me know, we are trying to determine the demand and should be getting you hooked up soon (free hardware?)