Integrating AC current clamp output to get power - Page 1
Forum section: electronics / general

author: berke
author_rank: Frequent Contributor
timestamp: December 22, 2023, 06:22:28 pm
content: I'm trying to measure mains power P(t) = I(t)×V(t).To that effect I'm sampling the output of a clamp type AC current sensor (specifically TDK CCT272440-80-10-00) at 1 kHz on an ATmega644. I'm extracting phase and amplitude satisfactorily. (Two channels actually.)The problem is that the clamp, being a transformer, gives a signal proportional to the derivative of current, yet many if not most loads nowadays are highly non-linear and the current waveform can be quite far from a sine wave, see below the waveform captured from an RGB light bulb.The idea: Assume current goes to zero when mains voltage goes to zero. Shift the waveform accordingly. Integrate sensed dI/dt using e.g. trapezoidal integration.Is this a good idea? Is there a better way?For synchronization, I see the following options :Option 1 - Assume the phase of the 50 Hz component as currently extracted tracks the mains within a fixed offset. No need to rework PCB.Option 2 - Add a channel to sense the mains voltage for synchronization. (Small transformer, with its own adjustable offset.)Option 3 - Switch to a different kind of sensor (Hall effect.)

author: Kleinstein
author_rank: Super Contributor
timestamp: December 22, 2023, 06:39:32 pm
content: A current transformer wants a shunt / loading resistor on the output side. It than gives a relatively accurate representation of the current.1 kHz sampling is rather slow, if there is a complex waveform, like a phase angle dimmer / speed controller. One would normally use close to the maximum available ADC reading rate.

author: berke
author_rank: Frequent Contributor
timestamp: December 22, 2023, 09:03:49 pm
content: Quote from: Kleinstein on December 22, 2023, 06:39:32 pmThanks, I hadn't realized that the sensor has a large inductance which creates an integrator! I already have load resistors that I use to provide balanced impedances as I'm sensing the outputs differentially. The AC load comes to about 52 ohms. The inductance of the sensor is ~42 H at 120 Hz, with an internal resistance of 344 ohms. As a result starting from about 10 Hz I should indeed get an "accurate representation of the current" like you say.QuoteI don't disagree about the sampling rate but I can't do much better with the ATmega644's built-in ADC. You have to wait for its amp to settle after switching channels, and there is a penalty for triggered sampling and another one for differential/amplified inputs. Maybe I can squeeze 4 kSa/s tops if I went single channel.I picked the '644 because I didn't want to buy any new parts for this. I only re-used what I had in my drawers. I think I bought those microcontrollers 10 years ago.This is the prototype, the next board will have to have more channels, maybe 8 maybe more. Will have to figure out the ADCs/amps for it. I guess I'll have it fabbed too.This project is for monitoring the breaker panel. Turns out I have three phase power, so I already need three channels. The previous owner, a German, brought in a lot of appliances from Germany including a three-phase water boiler. I'm getting large utility bills and I'm wondering if the "Linky" power meter is well-calibrated (there have been stories about some of them being quite out of whack.) That, or aliens are stealing my power.There is also a photodiode (on the back side) that monitors the 1 blink per Wh pulse that comes out from the Linky.

author: johansen
author_rank: Super Contributor
timestamp: December 22, 2023, 11:41:09 pm
content: You may be able to alternate between measuring the current for 10 cycles, averaging the data, then disconnect the current sense resistor and let the voltage rise to charge up the power supply to run the microcontroller.322 ohms and 42H sounds like a 1,000 turn winding on a ferrite core. A burden resistor large enough to cause a 90 degree phase shift.. does not sound like an accurate solution...

author: coppice
author_rank: Super Contributor
timestamp: December 22, 2023, 11:52:25 pm
content: There are so many cheap, wide dynamic range and highly accurate power measurement options for mains power. They are made in large numbers for the utility meter market, Why not just use one of those?

author: berke
author_rank: Frequent Contributor
timestamp: December 25, 2023, 10:24:07 am
content: Quote from: johansen on December 22, 2023, 11:41:09 pmInteresting idea, maybe for a stand-alone clip-on sensor. In my case I'll just use a transformer with battery backup.Quote from: johansen on December 22, 2023, 11:41:09 pmIt is reasonably accurate (maybe 6%), with the ~52 ohm load resistor the self-inductance of the sense coil creates an integrator, so like Kleinstein said you get a good representation of the actual current (above ~10 Hz). I've just checked it feeding it sines, triangles, distorted sines and the waveforms are good enough, see below. X-axis: true RMS current (measured with a resistor), Y-axis: RMS value of voltage sensed by probe.Quote from: coppice on December 22, 2023, 11:52:25 pmSure, can you suggest one with the following features?Mandatory:- Clip-on sensors, no modification to mains panel required- Multi-channel- Counts the light pulses from the utility power meter- Can handle three-phase power- Measures and logs phase and RMS value for each channel- Measures and logs mains frequency- Has battery backup with remote low battery indication- Wireless, but does not use WiFi or Bluetooth- Does not require an app, login, signup or any kind of Internet connection to work- Radio receiver can use at most one USB2 port and one audio input, or one Ethernet port- Receiver software is Linux compatible and similarly open sourceNice to have:- Transmissions are encrypted with user-defined keys and quantum-resistant algorithms- Does not use custom proprietary ICs- Open source firmware and hardware, comes with full schematics, BOM, gerbers and source code- 5 year warranty with 24/7 on-site maintenance- Under 100€

author: NiHaoMike
author_rank: Super Contributor
timestamp: December 25, 2023, 01:01:40 pm
content: https://openenergymonitor.org

author: berke
author_rank: Frequent Contributor
timestamp: December 25, 2023, 02:15:39 pm
content: Quote from: NiHaoMike on December 25, 2023, 01:01:40 pmHeh, as usual there already is almost exactly what I was trying to do. The EmonTX is quite good. It basically ticks all the boxes. The firmware is open source so it would be easy enough to adjust some of the little things that bother me. But it is a bit expensive at 183 GBP + customs.It's tempting but it's just been replaced with a Pi version, which also is quite a bit more expensive (264 GBP + customs) and no longer open hardware (sorry the Pi boards are not open hardware, they won't even give you the schematic.) Plus you have to provide your own battery backup it seems.Anyway, my firmware is mostly done, I still have to write the receiver code, box it and install it.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 25, 2023, 06:14:56 pm
content: Quote from: berke on December 22, 2023, 06:22:28 pmThis is not what the current transformer does. You are confusing it probably with something like a Rogowski coil. But CTs directly output secondary current relative to primary current, with burden resistor converting that current to a voltage. They have good response usually to a few kHz or so, so no need to do anything but measure V and I, as simultaneously as possible, multiply them together for instantaneous power, and average that value to any arbitrary period you want.1kHz is on the low side. Many cheap microcontrollers can do a lot better. Even just 3-4kHz is quite OK.

author: berke
author_rank: Frequent Contributor
timestamp: December 26, 2023, 12:48:19 am
content: Quote from: Siwastaja on December 25, 2023, 06:14:56 pmAre the following statements true?1) If Is is the current in the mains wire encircled by the coil, it creates a field Bs proportional to Is. The flux F of that field in the coil is also proportional to Bs. The EMF between the coil terminals is E is dE/dT. If the coil is not loaded, that EMF is proportional to the derivative of the current Is.2) If the coil is loaded with a resistance R, a current I'=E/R is created, which creates a field B' which adds to the flux. The EMF from B' will be out of phase. The ratio is I'/Is = -a s / (s - R/L) where L is the coil inductance, a is a proportionality factor and s = j omega. The pole at R/L provides integration compensating for the differentiating effect of the coil at higher frequencies.QuoteMaybe I missed something but according to the datasheet the '644 can't go that high when multiplexing two differential and one single-ended channel at full resolution.

author: johansen
author_rank: Super Contributor
timestamp: December 26, 2023, 01:26:35 am
content: The spiky waveform posted earlier may be due to the capacitive input filter of the load, rather than the CT Saturating as i suspected.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 26, 2023, 07:22:37 am
content: Quote from: berke on December 26, 2023, 12:48:19 amChoosing one of the microcontrollers with lowest sample rate ADCs on market for a job where you need more bandwidth than that is backwards. There are plenty of chips which are even cheaper but with much better sample rate, e.g. STM32F030 series with 1MSPS ADC.QuoteNearly two decades since I last used Laplace transform. This is one of the things where you can either observe apple falling down, or try to construct a mathematical model of it. I suggest starting with the observation; the fact that current transformers are used in gazillion of circuits where they provide measurement of current, not its derivative, which can be directly used for multiplication with voltage, is proof enough this is the case. If your math ends up with a different result, with apple levitating above the ground, there must be something wrong with the math, even if I can't say what exactly.

author: berke
author_rank: Frequent Contributor
timestamp: December 26, 2023, 10:23:07 am
content: Quote from: Siwastaja on December 26, 2023, 07:22:37 amPlease see above:Quote from: berke on December 22, 2023, 09:03:49 pmQuote from: Siwastaja on December 26, 2023, 07:22:37 amNo one is doubting that it works, the question was resolved following Kleinstein's comment in post #2.I've made some extra measurements to illustrate that omitting the load resistor causes the current sense transformer to produce a voltage proportional to the time derivative of the current.The figure below shows what happens to a 50 Hz triangular current. Green is the current, yellow is the output of the coil to which the scope probe is directly connected. There is some resonance due to the probe and stray capacitances.With 100 ohms resistor across the coil leads we recover the triangular shape of current waveform. The output amplitude is much smaller.

author: berke
author_rank: Frequent Contributor
timestamp: December 26, 2023, 10:32:18 am
content: Quote from: johansen on December 26, 2023, 01:26:35 amThe probe is nowhere near saturation, it's good to 80A. It must be the switching PSU of the LED bulb that draws current that way. I get nice clean sine waves using a heater, for example.I wish I had some kind of continuously adjustable resistive load for calibration. I've been using this POS "Silvercraft" heater has a fan, six buttons, an LCD display and can't decide whether it wants to run its fan or not, it clicks off and then right on continuously. Basically it has four modes : ~3W idle, ~20W when it runs the fan, 1 kW low heat, 2 kW high heat. My circuit does a good job of measuring it, but obviously it's not very reactive.I think I'm going to skip the voltage channel for now, the main thing I want is to get realtime feedback from the meter's light and to have a rough idea of what the heat pumps draw.Also looks like the new AVR's (e.g. AVR64DA64) are pretty sweet, bult-in op-amps, lots of channels, no silly restriction on differential channel pairs, and quite cheap.

author: Kleinstein
author_rank: Super Contributor
timestamp: December 26, 2023, 03:50:39 pm
content: With a resistive load, like a heater one could get away with scipping the voltage measurement and only do voltage and current one at a time. However for a ractive load (e.g. a motor and maybe the low power mode of the heater) one should measure both current and voltage, ideally at the same time ot at least in close sequence. For speed reasons one may have to use signle ended mode for both and not use the relatively slow differential amplifier of the AVR. The ADC can than run relatively fast (e.g. some 25 kSPS) and contineously with channel switching timed right, while the conversion is still ongoing.To get data for the same time one should average the voltage signals before and after, as the mains voltage is normally still close to a sine wave without large jumps. Interpolating the current would cause more error.The question if the core saturates depends on the burden resistor. With to much of a resistor (e.g. > 1 K) the core can saturate well before the 80 A nominal upper limit. There is not real need to go super low in the resistance, as there is still the winding resistance, that look rather high to me. Ideally one would use a negative external resistance to compensate - just hard to find them with good accuracy.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 26, 2023, 04:38:24 pm
content: Indeed, differential measurement is not needed. Just measure the CT signal single-ended. Track the long-term average (over tens of seconds for example) and subtract. You'd want to do that anyway, even with differential measurement mode because ADC has offset error in both operating modes.For even better results, you can try to detect zero crossings and average the offset over full number of cycles. Simpler alternative is to measure long enough (e.g. 60 seconds) so that any error caused by getting a partial cycle in becomes negligible.

author: berke
author_rank: Frequent Contributor
timestamp: December 26, 2023, 07:50:03 pm
content: Quote from: Kleinstein on December 26, 2023, 03:50:39 pmThe datasheet gives curves for resistances of 10, 100 and 1k, you see some saturation at 1k above 10 amps. I picked ~50 ohms to keep the signal within the range of the ADC with its internal 2.56V reference.Quote from: Siwastaja on December 26, 2023, 04:38:24 pmThe SNR is going to improve with a single-ended connection, but is it worth having a differential connection? Hard to say, as the low overall impedance of the loop is making it somewhat immune to capacitive coupling.But turns out only the differential channels allow you to use programmable gains of 10x and 200x on the '644. The signal level is already too low for small loads (say 20W) at the highest gain setting, and large loads saturate the 10x mode. So I have no choice but to use the differential model. Also I had to implement an AGC.QuoteI don't have a voltage connection (that would be for next time!), but I measure 48 cycles of current and compute the Fourier coefficients at 50 Hz. I'm assuming that if the load is not too reactive, the 50 Hz component of the current should be mostly in sync with the voltage.I also assume the mains voltage is constant, which certainly is the case within 10%, and I'm not expecting such accuracy with this setup anyway. I then compute the dot product of a phase-adjusted virtual voltage sine wave with the measured current from the Fourier coefficients. This gives approximate instantaneous power, which I integrate over time. Out of curiosity I also track the frequency for both channels, apparently it reflects the grid loading conditions.I finished the firmware and the receiver and boxed the thing. It's too dark and cold to install it next to the electrical panel tonight, so I've set it up in the living room. Reception is good at 1 kbaud. I'm using an old pair of 433 MHz ASK modules. IIRC I bought them 15 to 20 years ago from the Selectronic shop in Paris (now closed.) The receiver is connected to the audio input of a PC.Packets are sent at an average interval of 10 seconds (randomized) to comply with the ISM duty cycle requirement and look like this:Code:Packet {seq: 157, // Sequence numberflags: 1, // Status flags (1 = pulse good)res: [ // Reserved bytes, for message randomization93,146,206,],timestamp: 1994353, // Time since boot (ms)pulses: 0, // Number of utility meter pulses (not connected yet)vbat: 4.6714478, // Backup battery voltage (V)channels: [PacketChannel {e_tot: 51.300663, // Total accumulated energy (mJ)u_last: 0.04646478, // Last power estimate (W)phase: 6710, // Phase (pi/16384 radians)freq: 4998, // Frequency deviation (cHz)},PacketChannel {e_tot: 51.202053,u_last: 0.085046425,phase: 62634,freq: 4991,},],mac: 0, // Authentication code (should be zero)}

author: Kleinstein
author_rank: Super Contributor
timestamp: December 26, 2023, 10:21:18 pm
content: Measuring only the 50 Hz component of the load current is an indirect way of assuming that the votlage is a relative pure sine. In some areas the mains waveform is not really sine anymore, with low PF SMPS flattening the peaks, making it more square. It is also quite some effort to do an FFT.The more direct way of calculating the instant power and sum up is usually easier and more accurate. Most of the math can be done in real time while the data come in and no need for much memory (only a few sums: energy and if wanted correction terms for the DC offset to correct backwards for a possible offset). One should be able to get contineous readinds with only a few points droped on changes of the gain.The differential mode offers amplification, but a bit slow and noisy. The alternatve is to provide extranal gain with a separate amplifer, that can be lower noise and also run all the time. For gain switching a reasonable easy solution is using 2 amplfier stages and switch the input depending on the wanted gain.

author: berke
author_rank: Frequent Contributor
timestamp: December 26, 2023, 11:08:00 pm
content: Quote from: Kleinstein on December 26, 2023, 10:21:18 pmThanks I'll keep that in mind, so far the mains visually looks like a regular sine wave.QuoteIt's not an FFT but a single-point Fourier transform (sum_k cos(omega k t) x(k),sum_k sin(omega k t) x(k)) which is pretty cheap. The '644 has an 8x8 multiplier.QuoteI agree but I didn't include a voltage channel. I've found an old transformer since, though. Maybe I'll repurpose the second coil channel as a voltage channel.QuoteI'm throwing out buffers that contain saturated samples but it's not a biggie as the buffers are small (240 samples.) Switching gains is not an extra problem as I do that anyway when changing channels, throwing out the first sample as recommended in the datasheet.QuoteI don't understand, why do you say the differential mode is noisy? Due to the amplification? Or is this something specific you know about this AVR?QuoteIt's easy for 1 or 2 channels but how do I get say 8 differential channels with adjustable gain without throwing 24 ICs at the problem?EDIT: Fix formatting.

author: Kleinstein
author_rank: Super Contributor
timestamp: December 26, 2023, 11:33:38 pm
content: The ADC specs give a reduced effective resolution for the differential mode - this is likely to a large part from noise. Using a more digital CMOS process and rather low power the amplifier has to quite noisy compared to a more normal OP-amp. The limited speed is a problem as the amplifier is shared and thus only acting after switching the channel. There is no need to get a large number of gain steps, possibly just 2, e.g. the direct and amplified signal.For multiple channels the AVR would be a bit slow anyway and not much ADC speed to go around.There is not need to through out samples after switching between channels in single ended mode. It is perfectly fine to run the ADC in contineous mode and switch the channel after some 3 ADC clock cycles, so that the sampling phase is over. Dropping the first samples may be an issue in the differential mode and after turn on or change in the reference voltage (especially down).Using the single frequency fourier transform is using a sine (and cosine) instead of the measured voltage channel (ideally with interpolation). The direct use of the voltage signal would also include the phase and no need to measure that also.

author: berke
author_rank: Frequent Contributor
timestamp: December 27, 2023, 09:02:09 am
content: Quote from: Kleinstein on December 26, 2023, 11:33:38 pmYou're right it's in the "Electrical specs" section. You're saying the poor CMOS differential amplifier eats 2-3 bits.At 1x I lose 12 dB SNR in differential mode, it probably makes sense to switch to single-ended, depending on the magnitude of the common-mode noise I pick vs. the loss due to the differential mode.QuoteVery rough eyeball count gives about 300 instructions per sample. The code is C compiled with -O3 and avr-gcc 5.4.0. It's not particularly optimized.The AVR runs at 10 MHz. It probably can easily handle 16 channels at 1 kSa/s each, but I'll run out of SRAM with the current code above 4 channels, I'd have to fold some of the processing into the ADC code. There is only 4096B SRAM.QuoteCorrect, but I'd need external gain.QuoteQuoteI'm trusting the datasheet there but it could be interesting to characterize the ADC and its modes.I've worked with MCP3424's previously which also seems to be a CMOS affair but sigma-delta not SAR. I was going to use them (they're quite expensive but I have leftovers) however the sample rate is really low (240 Sa/s max). The datasheet gives a rough input model but they don't tell you the internal clock frequency, how many times the input is sampled, the duration of the pulses, the actual impedances w.r.t. PGA and only make vague statements about the required source impedance. Looking at the input noise it looked like it runs roughly at 2^(n-1)/S_S (about 500 kHz).The ATmega644's model is even more spartan but at least you know it should sample only once.QuoteYes, it's approximate but good enough for now.QuoteI know. Any suggestions about how to best get the voltage? A PSU transformer seems the easiest option, but if I have three phases that's three transformers. Capacitive coupling? I guess it needs to be class Y.

author: Kleinstein
author_rank: Super Contributor
timestamp: December 27, 2023, 01:30:25 pm
content: Getting the voltage signal with isolation is a bit tricky. A simple small mains transformer is not working that well - it may need a little larger size of special low loss ones. Otherwise the mangentization current can cause some error. Class Y capacitors may be an option, though unusual and one would need the circuit at neutral. With capacitors using all 3 phases would be OK and would even cancel out the currents. One may still need to isolate the whole circuit (e.g. for the displaym keys and programming).Another one would be a combination of resistor and small 1:1 current transformers for isolation.The calculation of the power and also the current amplitude should be possible while the data are coming in. So I see no need to really use much memory. The version with the voltage measurement should be the simpler case. AFAIR there is an old ATMEL appl. not on how to do AC power measurement with an AVR.The problem with more channels is more the ADC speed (some 15 kSPS for full specs, and maybe some 24 kSPS (= 10 MHz/13/32) with not too much loss in accuracy).So 3 x current and 3 x voltage would be only some 4 ksps per channel and with 2 inputs per current channel one would need 9 ADC inputs.The MCP3424 is a relatively slow SD ADC and not that suitable. The gain is via more frequent input sampling, so no actual amplification of the voltage and a lower input impedance with gain.The analog input configuration for the AVR is shown for the single ended version. Not sure how it is in differential mode, but it should be a bit different. More frequent smpling is more a thing for low gains (e.g. 1,2,4,8).I would really prefer external amplification over using the internal gain. I would expect the ADC used for the current reading to be OK for well more than a 1:10 range, more like up to 1:100. So one could use something like the signal with no gain and a gain of some 100 or so.

author: coppice
author_rank: Super Contributor
timestamp: December 27, 2023, 02:24:51 pm
content: If you want isolation don't isolate the sensors, isolate the measured results. Just opto couple the results out of the measurement unit. This avoids any phase shifts and distortion of the voltage signal. If you use a cheap energy measurement chip, they take little power, and can easily be run from a cheap cap drop power supply.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 27, 2023, 02:45:16 pm
content: Algorithmically, sounds an interesting project, but I have one question. Did you evaluate how this isusuallybeing done, and dismissed it because of... what? I mean, if you don't have voltage measurement available, you just usually accumulate squares of measured current, and from the integration period of your choice, you take square root and multiple by assumed RMS voltage, and get apparent power, which is close to real power if loads have decent power factors. If you do have voltage measurement available, you just multiply V*I for each sample (the more the better), accumulate over integration period, and take average. I don't understand what you are gaining with Fourier analysis. There must be something, you wouldn't be doing it otherwise, yes? What I am missing?Range switching to utilize a poor ADC + built-in PGA seems quite complicated too, given that you could get a better ADC for less money, and get rid of all that complexity.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 27, 2023, 02:48:02 pm
content: Quote from: coppice on December 27, 2023, 02:24:51 pmThis is usually the best option because not only it allows simple voltage measurement using a voltage divider, without the complexity of analog isolation, it enables shunt resistor type current measurement in one go.One middle ground option is to power an external ADC through an isolated DC/DC converter + isolate the data; this allows you to poke around the microcontroller side e.g. with a debugger.

author: coppice
author_rank: Super Contributor
timestamp: December 27, 2023, 03:06:13 pm
content: Quote from: Siwastaja on December 27, 2023, 02:48:02 pmShunts are a big plus, but I didn't mention that because the OP seems to want a clamp on solution. If its wired in shunts are the way to do. No funky phase shifts with those, just make sure the input filters to the two ADC channels are balanced, which means differential inputs are also the best way to go. If you have a significant phase shift you can corrrect it by delays in software, but you can't beat the problem that wilth reasonably priced capacitors the filter will change with temperature and ruin accuracy at poor power factors.

author: berke
author_rank: Frequent Contributor
timestamp: December 27, 2023, 04:00:47 pm
content: Quote from: Siwastaja on December 27, 2023, 02:45:16 pmI know it's usually done by measuring V and I, however I don't have a V sensor, but I already have two current sense probes and a bunch of microcontrollers.QuoteIf you directly do the RMS sum, you will accumulate offset errors, but those are easy to fix. Let's say you're integrating over a multiple of the period and you've subtracted the average value so there is no DC component left.Still suppose your base current is I = I0 sin(w t) in phase with voltage V = V0 sin(wt). Now add a spike of amplitude I1 at time zero I' = I0 sin(w t) + I1 delta(t) where delta is the Dirac delta. This spike draws no power, yet you will see it in your RMS sum.The spike biases the phase estimate, but if the spike is not enormous the shift will be small and the result will still be close to the real value.So this method seemed more correct and at least bit better than RMS so I implemented it.Is it really better than plain RMS? That depends on the waveforms. You can now argue that all of that is unnecessary as spikes usually don't occur near the zero crossings. Maybe.QuoteLess money than zero implies people will pay me to use a better ADCI'm using leftover components with no plausible resale value, and holiday free time.EDIT: Fix wrongness.

author: berke
author_rank: Frequent Contributor
timestamp: December 27, 2023, 04:12:24 pm
content: [ Specified attachment is not available ]Quote from: Kleinstein on December 27, 2023, 01:30:25 pmRegarding capacitive coupling, I'm not sure how the Y connection you talk about would work, but I thought of the following. A capacitive divider with 1uF/1nF caps. I'm measuring the three phases P1,P2, P3 and the neutral N w.r.t. protective earth (in theory N = PE). An external instrumentation amplifier computes the difference between Pi and N. I could add a 3-to-1 analog mux in front. Mains voltage being scary I've added a fuse, a MOV and a resistor but I'm not sure if they are all necessary (or sufficient.) I can put the caps on a separate board to get isolation.EDIT: Fixed image, had caps backwards in divider (thanks to Kleinstein for pointing it out)

author: Kleinstein
author_rank: Super Contributor
timestamp: December 27, 2023, 04:36:35 pm
content: The capacitive divider would be the other way around: some 1 nF towards the phase and some 1 µF towards ground. The ground would ideally be linked to N or maybe PE as a substitute. Which ground to use is than one of the more tricky parts. When using N one may need extra isolation for the whole circuit.One would than likely need high impedance buffers for the capacitive voltages and for biasing high resistors (e.g. 1 M range) to a suitable DC level.The limitation to the 50 Hz fourier component would eliminate the harmonics from the current. With an ideal sine waveform for the voltage there is no real power from the harmonics. So this may justify the difference. On the other side if mains is no longer perfect even an ohmic load will have harminis in the current and than the harmonics can contribute to real power - though usually not very much.Ideally one would calculate both, so one was a kind of lower limit for the power from the 50 Hz part and an upper limit from the RMS current.The bigger issue may be the phase shift.Gain switching is a thing that can make sense, when one wants to make it work over a large current range, e.g. to test the power of things like a wall wart. For just an overall reasurement a higher resolution ADC and one range is the better choice - e.g. MCP3911 is such an ADC made for power measurement. A 12 bit ADC like in many more moder µC could be good enough for a start, though likely not enough to meet the metering requirements.

author: berke
author_rank: Frequent Contributor
timestamp: December 27, 2023, 05:15:42 pm
content: Quote from: Kleinstein on December 27, 2023, 04:36:35 pmOoops! Fixed.QuoteI'd go with PE, all accessible metallic parts are supposed to be tied to PE anyway. Besides they are tied together at the entrance box I think.QuoteOf course, it was a partial schematic to give an idea. Some instrumentation amps have a reference input for that. But I did forget the bias voltage in the PCB, I had to add it afterwards, that's why there is a through-hole LM317.QuoteI don't follow. I use the 50 Hz component of the current as an estimate of the voltage, but I still integrate the current with its sampled harmonics.I should add an AA filter for next time though.QuoteWell if we really want to get fancy I could add some non-linear filtering to remove spikes and/or use a robust fitting technique for the sine wave but at this stage it makes more sense to just measure the damn voltage and make Siwastaja happy.QuoteI found it useful to be able to measure wall warts and small fans when calibrating the circuit by comparing it to the output of a cheap power meter. If the ADC is good enough no need for multiple gains.QuoteThank you!That chip looks really great. I'm looking into it.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 27, 2023, 06:31:49 pm
content: Quote from: berke on December 27, 2023, 05:15:42 pmI think I got it now. An interesting approach for some specific types of loads where bulk of the current is in phase with voltage, but then there are spikes which reduce power factor (by the modern definition, not the original phase-shift "cos phi" one). You synchronize the generated voltage waveform by assuming the 50Hz component is without phase shift.But remember that there still are, and will be those loads with simple phase shift i.e., inductive or capacitive, and then I think this Fourier approach reduces to the same result as just measuring RMS current and multiplying by assumed RMS voltage - i.e., you simply get apparent power instead of real power. It could be quite confusing to understand what it actually measures if it's some kind of "a bit better estimate of real power than apparent power is, but not real nor apparent power".

author: berke
author_rank: Frequent Contributor
timestamp: December 29, 2023, 11:16:12 am
content: Field report after two days of operrationThe device works pretty well.The two coils are connected to the lines supplying the two AC units (aka air-to-air heat pumps.) For those loads, the measurements seem to be pretty accurate, probably within 5%. I know this because at night, during periods where the other loads (fridge etc.) switch off, the reading from the utility meter match the total from the two units. Also, the pulses I count match what the utility reports online (with a 24 hours delay and 30 minute granularity and an annoyinh 2FA login screen...)The only issue so far was the PMMA optical fiber that links the utility meter's LED to the photodiode moved slightly and the pulse count dropped to zero. I had to reposition it. I wrote code for adapting the threshold but it doesn't work very well and is not enabled by default. Instead I've put a manual threshold saved to the EEPROM, but the control is over the serial port.The receiver software running on a PC decodes the baseband coming from the 433 MHz receiver (connected to the MIC line). Packet loss rate is <10%, due to small burst errors. There is no FEC. The 6B8B code provides single-bit error detection. This should improve when I place the receiver closer to the device.The receiver simply fills a Postgres database. I discovered that Postgres has a lag operator which allows one to easily compute differences between the last two received totals and their timestamps and get an instantaneous power estimate.Checking the database using the command-line psql tool is enough for me, but I need to find a solution so that the wife and kids can be exposed to the meter readings and adjust their behaviours. Maybe a chat bot.Thanks to everyone who contributed!For the second version, I looked at the MCP3911 suggested by Kleinstein. One option is using 6 of them to measure 3 voltages and 9 coils with a '644 using a shared SPI connection.The other option would be to use multiple AVR's maybe in single-ended mode.I'm also thinking about replacing the 433MHz modules with low power ISM transceiver IC's to get a higher data rate and bidirectional operation. Also unlike the cheap 433 MHz OOK modules you can get the transceiver ICs from regular distributors. Some of these ICs are cheap and seem pretty easy to use needing just a 13.56 MHz crystal and some RF caps.The biggest expense is the sensing coils, the cheapest clippable ones are about 20€ a pop. There are non-clippable ones at about 5€.