mains power measurement (again) - Page 1
Forum section: electronics / projects

author: djacobow
author_rank: Super Contributor
timestamp: November 05, 2017, 12:45:54 am
content: It seems every couple of years I want to measure the power consumed by mains devices.A few years ago, I built a one-off that used a CT for current measurement, and the output of the power supply transformer for voltage measurement, going into the ADCs of a micro. It worked OK, but was a bug bulky mess because of the transformers.More recently, I used an Allego hall effect device to measure current, and just assumed the voltage, for a crude device for power measurement (well, apparent power).I've been looking at energy measurement IC's like this one:http://www.atmel.com/Images/Atmel-46002-SE-M90E26-Datasheet.pdf.It has many things I want: it has the ADCs built in, so I can just talk to it i2c/SPI, and it is designed to work with only a shunt resistor for current a voltage divider for voltage, and it can handle the negative swing of the voltage rail. But I wonder -- what is the proper way to hook one of these up to a uC? The chip must be floated on the AC neutral, which if I'm to directly connect to a uC, then that must share the same power rails. But I really would ilke isolation between the AC and my uC. I could isolate a SPI interface pretty easily, but then I still have to power this chip. Do I use some reasonable isolated power supply for the rest of the design and a crufty capacitive dropper type PSU just for this chip?My design criteria are isolation, simplicity and compactness first, with price a second.How do people who know what they are doing build isolated power meters?

author: ovnr
author_rank: Frequent Contributor
timestamp: November 05, 2017, 12:55:46 am
content: "It depends".You could have the micro on the mains side too, and just isolate the comms to/from that. There are also SPI and I2C isolators. Incidentally the device you linked does SPI and RS232, not I2C.If you just want a simple solution: Grab something like theADUM5211for RS232 orADUM5411for SPI. They provide 30mA of isolated power (plenty for a energy metering AFE) + signalling, all in one chip.

author: IanB
author_rank: Super Contributor
timestamp: November 05, 2017, 01:15:00 am
content: Why wouldn't you use a Kill A Watt? It must surely be cheaper than anything you can make yourself?

author: djacobow
author_rank: Super Contributor
timestamp: November 05, 2017, 02:55:51 am
content: Quote from: IanB on November 05, 2017, 01:15:00 amI need something that I can physically embed in existing small appliances. This is for an instrumented kitchen/home science project. I don't want a meter hanging off the plug and I don't want a display.I've seen the kill-a-watt devices modified and the process looks pretty janky to me. And the guts of the kill-a-watt have changed more than once; your can't crack one open and already expect it to be a certain way

author: djacobow
author_rank: Super Contributor
timestamp: November 05, 2017, 03:00:00 am
content: Quote from: ovnr on November 05, 2017, 12:55:46 amThat chip looks brilliant!

author: djacobow
author_rank: Super Contributor
timestamp: January 10, 2018, 05:54:18 am
content: I am back to this project. Looking at the Adum5411 again. It seems to be out of stock at Digikey and Mouser. I'm looking at the TI ISOW7841 instead. They look to be about equivalent.Does anybody have experience with either? Both are pricey.

author: prasimix
author_rank: Unknown
timestamp: January 10, 2018, 10:13:44 am
content: Maybe a little bit cheaper could be using some of digital signal isolator with separate power isolation based on e.g.SN6505. It's stocked on Digikey as the required push-pulltransformer.

author: splin
author_rank: Frequent Contributor
timestamp: January 10, 2018, 03:30:21 pm
content: Just get one of these 1W dc-dc convertors and some cheap optisolators:https://www.ebay.co.uk/itm/New-Z3-B0505S-1W-DC-DC-5V-Power-Supply-Module-4-Pin-Isolated-converter/192339333650?epid=13007575701&hash=item2cc8515212:m:mCCj2bHRZtuPw9Pw2eiPMLQMake sure you meet the minimum load spec for the convertor (perhaps 10% or 20% full load) or the output voltage won't be regulated and could get excessive.

author: djacobow
author_rank: Super Contributor
timestamp: January 10, 2018, 05:07:12 pm
content: Wow, on the 5V/5V isolatd DC regulator. Same (similar?) part on legit supplier site is like $6. (Recom 0505S).

author: splin
author_rank: Frequent Contributor
timestamp: January 10, 2018, 11:19:04 pm
content: Mornsun is a big Chinese manufacturer so it's not too surprising their convertors are cheaper than US or European manufacturers. I have no doubt that their products are good quality and perfectly safe. But caution is required, as with any safety related goods bought from an unknown Chinese vendor, given the amount of fake products on the market.To be certain you'd have to get several and dismantle one or more (might be potted so could be difficult) to check creepage/clearences and the transformer windings are safe, or at least do a hi-pot test. Hardly worth the effortOn reflection I wouldn't risk buying on Ebay/Aliexpress etc. This distributor is selling them for $1.85 each and claims to be an authorised seller.https://ttlelectronics.net/products/b0505s-1wr2-ic-dcdc-converter-1w-5v-sipI've no idea if they are a reputable supplier but I'd trust them far more than a Chinese Ebay sellor.Better still I see Digikey sell a Recom part for $2.64 - not a big premium when someones life could be at stake:https://www.digikey.com/product-detail/en/recom-power/ROE-0505S/945-1655-5-ND/3461632 There definitely are counterfeit Mornsun products out there (no surprise):http://www.mornsun-power.com/html/about/content/1800276.htmlhttp://www.mornsun-power.com/html/about/content/1800444.html

author: djacobow
author_rank: Super Contributor
timestamp: January 24, 2018, 06:25:10 pm
content: Thanks for the help with this project so far.I got my boards back and they work just fine. I tested them at first with a 24VAC sprinkler transformer, then I went up to an isolated mains transformer, and eventually with direct mains, taking the load all the way up 1500W. No smoke!I know you guys know a lot about this sort of project, but here are some of my thoughts/learnings:* I decided to use the ISOW7841 because of the simplicity of only one part, and it works fine and required zero debugging. Though I will be making a bunch (maybe a few tens) of these, the number is not so high that the price is that important.* My AFE is an ATM90E26. I stuck with the reference design concept, in that they put the mains "live" onto the "ground" for the AFE chip. I understand that I could have just let the CPU ride the mains along with the AFE, but I decided to isolate it, mostly because of ease during debugging. If I want to probe something on the CPU side of things, there's no fuss. Same with programming headers, etc.The uC side of things, by the way, is alternatively an Atmega328P which bridges between the AFE and a Raspberry Pi Zero W, or I can leave the atmega out entirely and talk to the the RPi directly. I thought I'd have the uC there in case I needed to do any real-time processing, but because the AFE integrates energy for me, there's little need for it, so I think I will spin the board again without the uC* If you want to get close to the promised accuracy, I need better tools for calibration. I used a single Fuke 87V to calibrate the voltage and current, with various "handy" loads, I had laying around: 800 ohm WW resistors, 40 W lightbulb, 150 W lightbulb, and 1500W space heater. All those loads have imperfect power factor and also change with their temperature, which obviously changes. One thing I noticed is that as I varied the loads, the voltage would change, so I really needed to voltage and current simultaneously, which I could not do. Also, mains voltage just varies a bit minute by minute on its own. Complicating matters further, I really need good measurements directly across the shunt in order to calibrate the energy metering (as opposed to just the Irms and Vrms measurement) and that's also not easy. One mistake I made was not putting test points for the shunt.So now I want a programmable AC load and a programmable AC source. Too bad I don't have funds for that!* In my boards, I only did the shunt measurement and left the CT measurement off entirely. I'm thinking of putting the CT onto a new board, probably use a CSE187L. But I'm not sure I need it. The AFE chip is designed to measure a voltage across a current shunt and from a CT. This is for tamper protection, mostly. You can put it in a mode where it alerts if one is missing, or it chooses whichever is larger. I don't need this. My main reason to consider the CT is that maybe it's more accurate than the shunt? Maybe not?Okay, enough for now.

author: David Hess
author_rank: Super Contributor
timestamp: January 25, 2018, 05:26:05 am
content: You could power it with an isolated high frequency inverter, or a small power transformer, or even with a series capacitor directly from the AC line if its current demands are low enough.

author: jbb
author_rank: Super Contributor
timestamp: January 25, 2018, 09:59:34 am
content: On the CTs vs shunt resistors:For small currents (< 5A I guess) a shunt resistor works well. They dissipate some heat, so dissipation and temperature coefficient can be an issue.For large currents (>20A I guess) a CT is used to reduce the current and then put it through a shunt. The current in the shunt is low so dissipation is low.There’s a range in the middle where things are open for debate :-)

author: coppice
author_rank: Super Contributor
timestamp: January 25, 2018, 12:50:45 pm
content: Quote from: jbb on January 25, 2018, 09:59:34 amFor utility energy measurement, shunts are extensively used up to 200A. The popular energy measurement chips have reasonably high gain ADC inputs, so a 100 micro-ohm shunt for 200A, or a 200 micro-ohm shunt for 100A works well when directly connected to them. The energy loss with those resistances is pretty low. Most energy meter specs define an upper bound for insertion loss, and shunt based solutions easily meet those specs.

author: djacobow
author_rank: Super Contributor
timestamp: January 25, 2018, 05:39:54 pm
content: Quote from: coppice on January 25, 2018, 12:50:45 pmI only need to measure up to a US household circuit, so 20A. I'm using a 1 mOhm shunt (actually, two 2 mOhm in parallel) and did not notice any obvious warming even pulling 13A (1500W space heater) through it. Admittedly, I used the very unscientific measurement of putting my face very, very close to the shunts (without touching) to see if I could feel heat coming off. But at 20A, that's only 200 mW per resistor, and they were 2010 resistors rated for 1 W.One appeal I can see for the CT at high currents is that you can put the CT on the conductors and not have to route the current through your board, with the attendant self-heating, potentially enormous traces, and signal interference with other traces. But in my case, that's not practical or desired, and so I think I'm going to stick with the shunt only.

author: djacobow
author_rank: Super Contributor
timestamp: January 25, 2018, 05:50:31 pm
content: Quote from: David Hess on January 25, 2018, 05:26:05 amIn the board pictured, I am powering the Pi with an external USB PSU, but the idea of a project that touches mains but is powered separately offends me, even though it's probably the cheapest way to go. But in my subsequent board, there will be a board-mount Meanwell AC/DC switcher than can give 5V @ 1A to power the Pi and the atmega, and I will either stick with the ISOW7841 to power the AFE, or do as you say and use a capacitive dropper and cheaper optoisolation. The AFE only needs about 6 mA max, so this seems very feasible.

author: coppice
author_rank: Super Contributor
timestamp: January 25, 2018, 05:51:45 pm
content: Quote from: djacobow on January 25, 2018, 05:39:54 pmA 2 terminal 1 milli-ohm SMD shunt like that can work very well, as long as you are careful about the PCB layout. If you allow any copper to sit in the measured path, its 0.4%/C temperature coefficient can really hurt your accuracy over a reasonable temperature range. Thishttp://www.analog.com/en/analog-dialogue/articles/optimize-high-current-sensing-accuracy.htmlhas some pretty good info about getting reasonable accuracy from a 2 terminal shunt. Of course, 4 terminal shunts can do an even better job, but at a much higher price.

author: djacobow
author_rank: Super Contributor
timestamp: February 17, 2018, 02:23:01 am
content: Quote from: coppice on January 25, 2018, 05:51:45 pmWow, that link is interesting. I had no idea that the solder and copper leading to the pad such a short distance would be a significant fraction of the 1 mOhm resistance.I've redesigned my sense resistor into a "faux" 4-wire (faux-wire) pads for the next iteration of the board. The picture is with and without copper so you can see the layout. This is the bottom edge of the board, the only place where any real current flows. The J's are for quick-connect male tabs, and F1 is a 5x20 fuse.

author: djacobow
author_rank: Super Contributor
timestamp: February 28, 2018, 05:25:39 pm
content: Short writeup of my meter project:https://toolsofourtools.org/archives/725

author: coppice
author_rank: Super Contributor
timestamp: February 28, 2018, 05:40:45 pm
content: Quote from: djacobow on February 28, 2018, 05:25:39 pmIn your writeup you don't seem to understand why an energy calibration is needed in addition to the voltage and current calibrations. Its because you need to adjust the phase between the voltage and current samples. Around unity power factor this has almost no effect, but at poor power factors even a small fraction of a degree of phase error starts to affect the accuracy of the power measurements. Typically, a calibration is done with a 60 degree phase shift between the voltage and current waveforms exciting the meter under test. The meter under test is then compared with a reference meter measuring the same voltage and current signals (typically through the energy pulses from the meters, rather than the power measurement), and the phase correction is tweaked to make them match.Don't think you have a phase shift issue? Try looking at your design again.I say this because a number of people will say "I'm using a shunt. There is no significant phase shift.". However, by the time the voltage and current signals reach the measurement chip there is normally enough phase shift to need tweaking.

author: djacobow
author_rank: Super Contributor
timestamp: February 28, 2018, 05:49:40 pm
content: Quote from: coppice on February 28, 2018, 05:40:45 pmYeah, you are right, i didn't understand it, and I am surprised to hear that there is a phase shift between the shunt and the ADC inputs. But I believe you.Unfortunately, though I can scrounge up passable resistive loads, I don't know of a way to generate calibrated 60 degree or other shift. I mean, I could just make a little RC or LR network, but to get 60 degrees, we're talking a lot of L or C, particularly if the R is low enough that we're going well into the meter's range. That is, I'd get a much better calibration with a 3A current than at 30mA current.Do you have any suggestions for cheap / clever ways to get the energy cal done without spending the big bucks on the proper test gear?

author: coppice
author_rank: Super Contributor
timestamp: February 28, 2018, 06:25:57 pm
content: Quote from: djacobow on February 28, 2018, 05:49:40 pmProfessionally these calibrations are done with expensive test benches that contain both a controllable signal source and a high accuracy reference meter. Professionally you don't want to be consuming many kilowatts as you test a meter. The test benches generate separate voltage and current signals, so you can avoid the consumption of power in a load. However, consuming substantial power for a short period is no problem as an experimenter. You just need a load with a horrible power factor, and an accurate meter to use as a reference.A lot of the kill-a-watt type meters don't do proper power measurements, and give horrible results at poor power factors. However, you seem to have a genuine kill-a-watt. When I have checked a couple of those, the results have been pretty accurate, but I don't know if that is the case with all their models. So, connect your meter and the kill-a-watt to a load with a horrible power factor, and see how their readings compare. You have self-powered your isolated area with a cap drop supply, so its pulling a little power from the input. The kill--a-watt is also self powered. Whichever you put first in the chain is going to measure the self consumption of the second in the chain. This consumption may not be that high, but it can be enough to distort the measurement results when you are trying to achieve well below 1% error. You could try swapping their orders in the chain, as see the effect on the readings.The Atmel/Microchip ATM90E26 is a nice device. It started life as an IDT product, and worked really well in customer testing. However, nobody seemed to sign up to use it in volume, and the sold the business was sold to Atmel. Atmel seemed to want it mostly to use the IP in their integrated metering ICs, but they still sell the standalone devices they inherited. Atmel has reduced the spec a bit (e.g. the temp coefficient), but it should still be a nice performer. With a good layout, and a good shunt, it can achieve 0.1% over a wide current range.If you want to see the main source of those phase shift errors, look at the RC filters they put in front of the ADCs. How well do you think the filter in the voltage channel matches the one in the current channel, especially considering the very different source impedances?

author: djacobow
author_rank: Super Contributor
timestamp: February 28, 2018, 06:47:46 pm
content: Quote from: coppice on February 28, 2018, 06:25:57 pmSo, I can make a load with a terrible pf. I mean, I just looked on mouser and I can get a huge inductor in the 10-50mH range that can handle 5-10 amps for something like $50 (probably a ton for shipping, though). I can also get beefy power resistors. So I can easily make a load that would lag by 60 degrees and pull 5A or whatever. But I am still stuck with the fact that I don't have a way to calibrate the load. The resistor has some parasitic inductance, the inductor has parasitic resistance, etc. I guess I could take my load somewhere and have it characterized and use it as a reference standard.Quote from: coppice on February 28, 2018, 06:25:57 pmI have two or three of them and they do not read within a percent of each other. That's why I'm a little skeptical. And, lacking something I can use for "ground truth", I don't know which, if any to trust.I am particularly interested in measuring reasonably low power devices, like USB chargers that are unloaded. These have horrid power factors, of course, and they are almost under the k-A-W's measurement threshold anyway. But I was thinking I could make an instance of my circuit with a much higher shunt value so that I could just scale it. (I tried the same surgery to a k-A-W, and it didn't go well. I'm not sure why.Quote from: coppice on February 28, 2018, 06:25:57 pmI actually have an older version of this circuit that has a separate power, I think I can get around the consumption of my own device.Quote from: coppice on February 28, 2018, 06:25:57 pmWell, I like to think I'm getting close! But the cal is going to be thorny, for sure.Quote from: coppice on February 28, 2018, 06:25:57 pmWell, I don't know the impedances of the ADC inputs, but I guess I figured those networks were for noise and would be practically invisible at 60 Hz. The one on the shunt is 100 ohm / 330nF and the one on the voltage input is 1k / 33n. I never simulated it because I just figured the ref designers knew what they were doing. Probably never a good idea.

author: jbb
author_rank: Super Contributor
timestamp: February 28, 2018, 07:15:18 pm
content: In short: Get thee to a calibration lab.In medium: your problem is you don't have any 'good' references around the place. Even a high accuracy true RMS multimeter won't do it, because the phase relationship - and especially distortion - are critical for active power measurement.So you should reach out to calibration labs in your area. If you can arrange a physical visit, great. If not, you'll need to prepare test samples (more than one!!!) and calibration instructions. Ask if they can help with a 'Debug' calibration for early product development.Before going to a lab, you should do your own rough 'calibration' at home to make sure that the software is stable and all your safety properties look OK (e.g. suitable creepage / clearance, correct isolator chips, boards are clean and tidy, boards are mounted in a box with suitable connections e.g. 4mm shrouded banana jacks).Once you're at the lab, time is money. Therefore everything should work nicely from the get go. Bring your own laptop where you know that the comms cable works right. Bring all the cables. Bring a camera and notebook.Finally, I would recommend against any trimpots for calibration. The cal lab would likely have to stop the test, turn off the calibrator output, fiddle with the pot, and restart the test. This can slow things down a lot...Alternatively, you could look at hiring (or buying second hand) an AC calibrator.

author: djacobow
author_rank: Super Contributor
timestamp: February 28, 2018, 07:18:33 pm
content: Based on your advice, Coppice, I just tried quick-n-dirty simulating the input filters based on the input impedances in the ATM90E26 datasheet (400k single-ended for the voltage inputs and 1k single-ended for the shunt input). Using a pretty significantly lagging load, I didn't really see much of a phase mismatch between the current in the shunt and the filtered voltage difference around it, nor did I see it between the voltage at the load and the voltage difference at the voltage inputs.I could have set this up wrong, of course. I'm attaching the shot of the circuit and plots.

author: djacobow
author_rank: Super Contributor
timestamp: February 28, 2018, 07:22:51 pm
content: Quote from: jbb on February 28, 2018, 07:15:18 pmWell, I was considering this the option of last resort. That's money and this is a hobby project.If I were to go, I'd go with my DUCs. There are no trimpots on this board. All cal is done in software.Though I have tried to be very careful with isolation, creepage/clearance, and I think it's probably about right, if not overkill for a 120V device, this is not a commercial product, and I don't need to meet UL standards.Quote from: jbb on February 28, 2018, 07:15:18 pmThat is an idea I can look into more. I mean, the hiring, not the buying.

author: floobydust
author_rank: Super Contributor
timestamp: February 28, 2018, 08:35:30 pm
content: I noticed R9, R10 are seeing near mains voltage according to your simulation. The current-sense voltage divider is going to smoke?Any high freq. noise bursts on mains overloads R7, R8, so they must be sized bigger than expected.

author: coppice
author_rank: Super Contributor
timestamp: February 28, 2018, 08:44:26 pm
content: Quote from: djacobow on February 28, 2018, 07:18:33 pmThe two things critical to getting the phase shift of the filter to zero are the source impedances feeding into it, and how well the two halves of the differential filter balance. Try opposite extremes of tolerance on the capacitors.How do you expect to see a fraction of a degree phase shift on those graphs?

author: djacobow
author_rank: Super Contributor
timestamp: February 28, 2018, 09:04:34 pm
content: Quote from: coppice on February 28, 2018, 08:44:26 pmYeah, well, not much I can do about the source impedance. The source impedance of the AC line coming is probably on the order of a couple of ohms. I don't think that would affect the current measurement much. The source impedance of the voltage measurement is high, though, because of the resistor divider.Quote from: coppice on February 28, 2018, 08:44:26 pmHow much does a fraction of a degree matter? pf = cos(phase_difference). So the maximum delta pf would be where the derivative (sin) is max, so pi/2, right? So, worst case error due to phase shift is when true phase is 45 degrees (and 135, 225, etc). So, say the phase angle is 45 degrees, but I measure 2 degrees off. That would get a pf of 0.731 where the true pf is 0.707, or 3.5% error. Not great, for sure, but something I'll have to think about tolerating given the calibration resources I have available to me.EDIT: Whoops, that's not right. That's the point of worst case error in pf, not the point of worst case relative error. The worse case relative, I guess, would occur at 90 degrees, where the true pf is 0 and a two degree error would yield a calculated pf of 0.035. Relative to 0, that's an infinity percent error. :-) Like if I had a 1kVAR load on there, I'd be saying there was 35W of real power, when in fact there should be none.I'll look into the caps being at opposite ends of their tolerance bands as you suggest. In general, I took 5 minutes to make that sim, and it needs more thought.

author: djacobow
author_rank: Super Contributor
timestamp: February 28, 2018, 09:21:31 pm
content: Quote from: floobydust on February 28, 2018, 08:35:30 pmWell, in the real circuit R9 and R10 are the inputs to the differential ADC, and they are high impedance relative to "ground" so they don't really blow up. But I misinterpreted what the data sheet means by "single ended input impedance" and those resistors should not be grounded, but only connect to each other and where they connect, that connected to ground through a ridiculously high impedance like 100M. Result isn't much different.Good catch on R7 and R8. Noise, and input protection are not something I have looked at.I suspect that these filter networks are not a bad starting point, but without proper measurement equipment, I'm not sure I'll ever know.