AC power direction in energy monitor (working)

Thread Starter

JunkieNL

Joined Mar 19, 2020
22
Hello all,


I want to share my current project. It is working, but I am still looking for improvements. Feedback is appreciated.

Problem

My Raspberry Pi is monitoring the power output of my solar panels. Node-red calculates the power by measuring the time between energy pulses. I would also want to see the power going in or out of my house, but the energy monitor has been sealed by the energy company. The only thing I have to work with is an LED, flashing every Wh. Herein lies the problem. The LED will flash the same, regardless of the power direction.

Solution

The energy and power are measured by monitoring the LED. The direction of power and energy is determined by the phase difference between the voltage and the current. The voltage comes from a transformer that is used by the doorbell. It is an 8V transformer, but delivers 12.5Vrms without load. The current comes from a current transformer on the connection to the mains grid, similar like the one used on this very helpful site:

https://learn.openenergymonitor.org/electricity-monitoring/ct-sensors/introduction

This is the circuit that was build:
circuit.png

Results

It works well when a large power is flowing in or out of the house, but determining the direction of power becomes difficult when the power is less than about 200W.

Comparator output @ 2000W. Channel 1 is voltage, channel 2 is current.
comparator output 2000W ch1-V ch2-I.png

Comparator output @ 250W. Channel 1 is voltage, channel 2 is current.
comparator output 250W ch1-V ch2-I.png
The current looks great at 2000W, but has issues at 250W.

Looking at the current itself: (AC triggered so you can compare the phase as well)

900W flowing in the house:
current 900W in.png

900 W flowing out of the house:
current 900W out.png

At small power (about 50W):
current 50W.png

Previously I had this working with MCP602 rail to rail op amps. I don’t have any oscilloscope measurements of that but I think that was working slightly better. Looking for ways to improve I heard Dave Jones (of EEVblog) saying that using op amps as comparator is crude and that it was better to use purpose build comparators. That is why I switched to the LM339N.

I would like to improve this setup. Ideas I have:
* I have ordered a different current transformer (SCT-013-000 instead of SCT-013-050) from China, but that will take some time to arrive. The SCT-013-000 does not have a built in load resistor, so I can play with that.
* Maybe it is possible to filter the current signal. Would that cause phase shifts?

Let me know what you think….
 

MisterBill2

Joined Jan 23, 2018
6,071
Phase shifts in an AC circuit are either caused by reactive components, either inductive or capacitive, or else non-linear devices that alter their resistance during the cycle. An example of that is a rectifier going into conduction as the line voltage exceeds the voltage that the filter capacitor is charged to. The current suddenly rises far past the zero voltage point of the sine wave.
What I see on the pictures of the voltage and current waveforms is a lot of high frequency oscillation that is probably not present in the actual waveform being monitored. Certainly that portion of the signal makes calculation more complicated.
If a current transformer core is saturating so that it no longer provides an accurate copy of the current wave form that will also make accurate calculation a challenge.
 

AlbertHall

Joined Jun 4, 2014
9,873
The LM339 is open collector output. That means it pull its output down to close to zero but it cannot drive its upwards. That function is provided by a pullup resistor. In your circuit the pullup resistors are 10k, so allowing for the PC817 and LED voltages there will be about 0.2mA through the LEDs when the LM339 output is off, or high. This is very low. The PC817 specifies its transfer ratio at 5mA. To get that current the 10k pullup resistors should be reduced to 390Ω.

As I understand it, you are not trying to measure the current with the current transformer, you simply want to know the phase relative to the voltage.
If that is so, and you use a current transformer without an internal resistor then you could no load resistor but instead connect two back to back diodes across it which should give a square wave even with low currents but still limit the voltage going to the comparator.
 

Thread Starter

JunkieNL

Joined Mar 19, 2020
22
The LM339 is open collector output. That means it pull its output down to close to zero but it cannot drive its upwards. That function is provided by a pullup resistor. In your circuit the pullup resistors are 10k, so allowing for the PC817 and LED voltages there will be about 0.2mA through the LEDs when the LM339 output is off, or high. This is very low. The PC817 specifies its transfer ratio at 5mA. To get that current the 10k pullup resistors should be reduced to 390Ω.
Ah... I did not recognise the open collector output part. I did not have that problem when I previously used the op amps. I guess "open collector" also means I can get rid of the 330 ohm resistor and just add that to the pullup. Correct?

I also didn't know about the transfer ratio. Now I do. It looks like it does pretty well at 0.2mA. The Raspberry picks up the signals and is able to calculate the phase. I will raise the current anyways and use the scope to see if all pulses are accounted for.

As I understand it, you are not trying to measure the current with the current transformer, you simply want to know the phase relative to the voltage.
If that is so, and you use a current transformer without an internal resistor then you could no load resistor but instead connect two back to back diodes across it which should give a square wave even with low currents but still limit the voltage going to the comparator.
Yes, I am only interested in the phase. What do you mean with "back to back"? I would think that it means in series. Does that work? Shouldn't I then use zeners for that?

Or could I just put some regular diodes in parallel? Like this:
SCT-013-000.png
 

Thread Starter

JunkieNL

Joined Mar 19, 2020
22
Also, none of your comparators have hysteresis.
Powerlines are notoriously noisy.
I have a small debounce time on the software side. As long as the noise is smaller than the amplitude of the signal, I should be able te detect the zero crossing. I also average the phase readings so that when I have an early detection because of noise, at least time offset stays roughly the same.

I don't think a schmitt trigger will improve the situation ;)
 

MisterBill2

Joined Jan 23, 2018
6,071
Ah... I did not recognise the open collector output part. I did not have that problem when I previously used the op amps. I guess "open collector" also means I can get rid of the 330 ohm resistor and just add that to the pullup. Correct?

I also didn't know about the transfer ratio. Now I do. It looks like it does pretty well at 0.2mA. The Raspberry picks up the signals and is able to calculate the phase. I will raise the current anyways and use the scope to see if all pulses are accounted for.



Yes, I am only interested in the phase. What do you mean with "back to back"? I would think that it means in series. Does that work? Shouldn't I then use zeners for that?

Or could I just put some regular diodes in parallel? Like this:
View attachment 209004
OK,, Pen Collector means that the collectormgoes to the output terminal and the emitter is tied to the common. So you can connect pin #1 of the U7 to the V+, and U7 pin#2 , with the LED and resistor to the pin #1 of the comparator, since the output transistor is NPN.
 
Top