Question re: phase lag on energy measurements

What is the impedance of your mains?

Good question, Pito. I thought the impedance of mains is assumed to be very, very low. IIRC, the house has a 400 Ampere service feed @ 240VAC and the outlet is fed by 12AWG wire (@ 120VAC through a 15A circuit breaker). So I'd like to think that the impedance would be low. However, that jogs a memory. We did some past measurements here with high-powered microwaves that had a nasty tendency to depress the line voltage out of spec re: the test procedure. Only measuring at the panel worked (i.e. stay within 1% of the stated line voltage even with a 1800W load attached).

I will re-measure right at the panel and see if that influences the results. Thanks for the suggestion!

I've seen somewhere it could be (or it shall be) something like Z=0.4+j0.25 ohm in EU
PS:
IEC TR 60725: 0.4 + j0.25 ohm at 90% of sites
Zref_1phase = 0.40 + j0.25 ohm
Zref_3phase = 0.24 + j0.15 ohm
PS1: with precise measurements you have to consider impedance at higher harmonics too..

I hope to have a look tonight. Any idea how much the above references would influence the measurements of loads with a power factor of one? The two loads I tested both should be 1 as one is a light bulb, the other a toaster. Now the latter features relay/contactor and both also enjoyed a Killawatt being in the measurement circuit but I doubt the killawatt nor the contactor would have meaningful impacts on the measurements.

What was also very interesting is how much 'fuzzier' the current signal was. Far more noise there than on the voltage signal.

  1. Are you sure that your toaster is a pure resistive load? Many modern toasters include electronics to do timing etc. and the small amount of current taken to feed the electronics could be leading or lagging the voltage.

  2. Have you tried looking at the mains voltage directly with the oscilloscope, to see how much lead/lag the voltage transformer introduces?

  3. Do the voltages you get on the transformer secondaries look like good sinusoids? Can you see any variation of waveshape with load?

dc42:

  1. Are you sure that your toaster is a pure resistive load? Many modern toasters include electronics to do timing etc. and the small amount of current taken to feed the electronics could be leading or lagging the voltage.

Interesting thought. It never occurred to me that even a very small non-resistive component could have a measurable impact. I noted a similar lag however with an incandescent 40W lamp and a simple on/off switch.

dc42:
2. Have you tried looking at the mains voltage directly with the oscilloscope, to see how much lead/lag the voltage transformer introduces?

Whoa... I don't think I'm comfortable to stick a oscilloscope probe into a mains outlet, even with a voltage divider circuit, etc... call me a ninny but my oscilloscope is PC-based and I'd be afraid the computer would turn into molten slag rather quickly in my hands...

dc42:
3. Do the voltages you get on the transformer secondaries look like good sinusoids? Can you see any variation of waveshape with load?

The oscilloscope suggests that the curves are pretty good. However, one thing I noticed is that the usual approach of using sum(V^2) followed by a sqrt operation to determine Vrms is fraught with trouble when you start with a 16-bit ADC, take 1.4ksps, etc. Even the teensy 3 (a 32-bit platform) seems to require the use of the big numbers library to make it work because the Arduino 1.0x environment seems to continue to use 8-bit referenced variables (i.e. a long on a 32-bit ARM is not a 128 bit number).

Constantin:
The oscilloscope suggests that the curves are pretty good. However, one thing I noticed is that the usual approach of using sum(V^2) followed by a sqrt operation to determine Vrms is fraught with trouble when you start with a 16-bit ADC, take 1.4ksps, etc. Even the teensy 3 (a 32-bit platform) seems to require the use of the big numbers library to make it work because the Arduino 1.0x environment seems to continue to use 8-bit referenced variables (i.e. a long on a 32-bit ARM is not a 128 bit number).

Do you really need to use 16 bits to get the desired accuracy? I would have thought 10 to 12 was more than enough, so that the square will fit in 19 to 23 bits (bearing in mind that the square can be unsigned) and you can sum at least 512 samples using 32-bit maths.

Hi DC,

Well, put it this way - I'd love to be able to use a 16-bit number in order to differentiate this unit from the other stuff out there - like openenergymonitor, kill-a-watt, etc. The ADC can actually deliver a 24-bit output but I consider that resolution to be somewhat questionable in terms of what the upstream signal conditioning can handle, my ham-fisted attempts at PCB design :grin:, the ADC itself (MCP3911) and so on. So I stick to 16 bits. But summing squared 16-bit results does trend towards very big numbers!

Using a 16-bit ADC may give you a very high resolution, but it won't give a correspondingly high accuracy, because of errors introduced by the current and voltage transformers. The behaviour of real transformers is non-linear and temperature-dependent. Try searching for "current transformer errors", "current transformer accuracy", "current transformer linearity" and similar terms.

Even the teensy 3 (a 32-bit platform) seems to require the use of the big numbers library to make it work because the Arduino 1.0x environment seems to continue to use 8-bit referenced variables (i.e. a long on a 32-bit ARM is not a 128 bit number).. But summing squared 16-bit results does trend towards very big numbers!

I do not think it is an issue even for an 8bit arduino.. :slight_smile:

This works and takes 71ms per calculation (an example only):

int mil, i, j, adc_i, adc_v;
long long sum;
mil = millis();
for(i=1; i<=10; i++) {
	sum = 0LL;
	for(j=1; j<=512; j++){
		adc_i = 29342 - j;  // ADC I
		adc_v = -29342 + j;  // ADC V
		sum = sum + ((long long)(adc_i) * (long long)(adc_i));
		sum = sum + ((long long)(adc_v) * (long long)(adc_v));
	}
}
mil = millis() - mil;
Serial.println("############################");
Serial.println(sum);
Serial.println(sqrt(sum));
Serial.println(mil/10);

Results (sum, sqrt(sum), time elapsed for single j-loop):

############################
866291871232
930748.00
71

You can store a sum of 2billions of 16bit adc samples squared into a single "long long" (int64_t), supported by arduino.

Hi Pito,

You are correct, 2^64 numbers are supported on the math side of the IDE, but try printing one.

My comment re: the Teensy 3 is that the IDE apparently has not caught up with the numbers that a 32 bit MCU will easily handle, etc. Hence my use of the big number library since it also allows me to print big numbers for debugging purposes.

:slight_smile: And it prints 64bitters as well (see my above replay):

http://forum.arduino.cc/index.php?topic=179111.msg1375203#msg1375203

Just use the new print.cpp and print.h, it supports new floating point formats as well.
You have to enable it in print.h

// uncomment if you want: int64 support, scientific notation and overflow testing
#define PRINT_LONGLONG
#define PRINT_SCIENTIFIC_AND_ENGINEERING
#define PRINT_NAN_INF
	sum = 123456789123456789LL;
	Serial.println(sum);
        sum = -123456789123456789LL;
	Serial.println(sum);
..
123456789123456789
-123456789123456789

Hey, that's awesome news. I had no idea that Rob had updated print to allow longer numbers. I wish this was part of the default IDE.

Constantin:
Hi guys and gals,

I hooked up the front end of my ADC to my oscilloscope and measured something interesting. Specifically, there appears to be a variable phase lag between the transformer for the voltage signal (ERA 0.08VA) and the current transformer (CR Magnetics CR8348-2500-N) as a function of load. Voltage always is lagging current.

That's the difference between an actual and an ideal transformer. With no load the transformer will approximate
an inductor in series with a resistor.

There may also be time delays in the measuring chain, which can be calibrated if you replace the transformer
directly with a resistive mains load like a tungsten bulb.

CORRECT PHASE MATCHING BETWEEN CHANNELS
Phase matching of the system is another critical issue.
The errors induced in the system at PF = 1 are minimal.
A power factor of 0.5 with a phase error as little as
0.5 degrees will cause a 1.5% error in the power mea-
surement.

according to "AN-564 APPLICATION NOTE" from AD.

Put your transformer to rest, go with optical:
http://coolarduino.wordpress.com/2013/02/27/power-energy-meter-phase-power-and-energy/

Optically isolated measurements re: the voltage signal are an attractive option. The main issue as I see it is that the number of potentially 'hot' components goes up considerably. The transformer, fuse, switch-mode power supply, etc. are all explicitly UL-listed, which should allow me some day to get the whole assembly listed quite easily.

One attractive alternative to the above is the Avago series of precision opto's. Very linear. But the circuits required to make it all work are extensive, making for a much larger PCB than I would like.

Another option is to simply run the resistors straight into the ADC and then use the ADUM5401 series from Analog to provide power and a safe SPI bus interface. If I had to ditch the transformer, I would prefer this solution for its simplicity even if it means adding yet another 3.3V power supply to the design (one for the Analog, the other for the digital power supply of the MCP3911).

Hello everybody ,

Is there anyone completed MCP3911 project?

@Constantin ??

Constantin:
Hi guys and gals,

I hooked up the front end of my ADC to my oscilloscope and measured something interesting. Specifically, there appears to be a variable phase lag between the transformer for the voltage signal (ERA 0.08VA) and the current transformer (CR Magnetics CR8348-2500-N) as a function of load. Voltage always is lagging current.

The phase lag ranges from ~ 1.32ms at a 40W load to 0.722ms lag with a 1340W load. Both loads have unitary gain, i.e. a 40W light bulb and a toaster. Is this normal?

Firstly you ideally need to filter out the harmonics before measuring the phase of the fundamental, any
even harmonics will distort the waveform making it hard to distinquish true phase difference from
harmonic distortions. This is best done in software not by eye from the 'scope screen.

The source impedance of the mains is immaterial here, presuming the current measured is through the load
and the voltage across it.

In real money those times translate to 24 and 13 degrees (for 50Hz) or 28 and 16 degrees (for 60Hz)
which are quite substantial.

A toaster is a resistive load, any subsidiary electronics is miniscule compared to the nichrome heating
element and at mains frequencies that's just a resistor.

"Unitary gain"? Does not make sense here. 'Purely resistive', 'non-reactive' makes sense here.