Preface
Project Log
| 2010-05-15 | This project is not dead, although I haven't worked on it for some time now. The software and PC
interface are collecting data and has been for quite some time now. I have always intended this
page to be mostly inspirational for like minded since I don't offer a finished product but I
must admit with no offering of any working software or proper examples, and the fact that the
schematics are not up to date it has become quite below what I would call a fair minimum. As the entry from 2008-04-12 states I have mounted a cap somewhere. None of the schematics shows where and I too have forgotten where I put it. The only way is to reverse engineer it. While doing so data cannot be collected which I'm not keen on. |
| 2009-04-16 | I'm still actively working on this project. I'm slowly making improvement on the applications. If you have any question feel free to contact me: m-larsen at post6.tele.dk |
| 2009-01-22 | I have removed the Linux software from "The PC Interface" section because I have discovered several errors in it. I will hopefully soon repost a better version which I am currently working on. |
| 2008-04-12 | The parallel port version showed some of the same hickups as the avr version so I mounted a 100nF capacitor. That immediately threw it into a 50 Hz oscillation frency. Now I have mounted a 10uF instead. That seems to work. |
| 2008-04-08 | I have restored the parallel port version, and I'm collecting data with it now. This has freed up my STK500 for other purposes. |
| 2008-03-20 | Michai Ramakers helped me correct a bug in the AVR code. The two bytes of the counter register must be read in the correct order. It's clearly stated in the datasheet, which I did read, and then did the complete opposite. Bummer! Anyway, it improved the readouts and the section "Let me be Frank" should be rewritten. |
The Math
The Basic Gizmo
Mount /dev/gizmo
Please note that although the IR diode is most sensitive to infrared light it picks up any kind of light.
My meter is located in a closet. When I open the door it instantly starts reading out bollocks, so to shield it from
unwanted light I have build a small cover from some cardboard. I does the trick.
The PC Interface
Of course the extra transistor causes problems too. The extra gain amplifies a small spike so it registers as
an extra pulse very shortly after the real pulse. Although being a torn in my sight, they are
easily spotted and compensated for in the software as they are calculated as a huge power surge (aka Great Scott! 1.21
Jigawatts???).
The Fancy Solution
I did a version on an ATmega8 where I run timer1 with no prescaler. At each pulse from the meter gizmo I calculate the difference in clock cycles between this and the previous pulse. The 32-bit value it leaves me with is the difference in time when divided by the crystal frequency.
In my initial version I only use the AVR as a timing device. I send the 32-bit value to my pc via a serial cable, where
I do the floating point math (divide by the crystal frequency).
This setup makes very precise meassurements but it can't timestamp them.
I haven't come up with a good solution for this problem yet. That's why I have spent my time on the PC version.
For inspiration the avr code: avrmeter.c
And a crude tool for the pc to read the data sent from the avr: avrread.c
These are the calculations I use when using the AVR solution.
3600 is seconds per hour. 10,000 is the pulses for 1 kWh. 3,686,400 is the microprocessor crystal clock speed.

Precision and calibration

The picture on the right is mostly a display of wishfull thinking. A very common output from GPS satellite synchronized
timing devices is a 1 PPS (Pulse Per Second). Such a 1 Hz pulse is perfect for testing, because it calculates to 0.360
kW.
Unfortunately I do not have access to such a thingy at home, but I do have the 4th best thing.
From an completely unspectacular 20 MHz oscillator, which I just happened to have, and a frequency divider (four 74HCT390)
build on breadboard I have a near 1 PPS source.
This little device has been invaluable when coding. Knowing what output to expect is a life saver.
Using it for precision testing a quite a another story.
The 20 Mhz oscillator itself is rated as having +/-100 ppm accuracy. This means it might actually be oscillating at 20.002.000
Hz or 19.998.000 Hz, or anything in between. But when divided 20 millions times in the frequency divider, so too is the
inaccuracy divided down. This means the 1 Hz might be anything in between 1,000.1 and 0,999.9 Hz. Calculated to Watts this
becomes values from 0.359,964 to 0.360,036 kW. In other words, rounded to 3 decimals, the value can be used.
The PC version introduces a whole other realm of problems.
The pulse triggers an interrupt on the pc. Inside the interrupt service routine a timestamp wihtin the microseconds
range from the operating systems clock is coupled with this reading. At first this sounds very simple, but the PC
services many interrupts which takes the CPUs attention, and the different interrupts are prioritized in an order where
it is unlikely that the parallel port interrupts has a very high priority.
All in all this makes for the worst possible scenario: Variable timing delay.
Poul-Henning Kamp has investigated this issue in his paper
"Raw data: Interrupt latency measurements".
Let me be Frank

Here is a dump from the PC version. For reference my desk lamp has a 20W bulp.
dt = 1.548220 s, 0.000064 KWh, 232.525093 W <-- Lamp on dt = 1.551745 s, 0.000064 KWh, 231.996881 W .. dt = 1.709931 s, 0.000058 KWh, 210.534811 W <-- Lamp off dt = 1.710194 s, 0.000058 KWh, 210.502434 W .. dt = 1.704476 s, 0.000058 KWh, 211.208606 W .. dt = 1.550534 s, 0.000064 KWh, 232.178075 W <-- Lamp on dt = 1.548024 s, 0.000064 KWh, 232.554534 W ..