Measuring mains AC voltage through capacitive isolation - Page 1
Forum section: electronics / beginners

author: derGoldstein
author_rank: Regular Contributor
timestamp: January 28, 2023, 02:16:00 pm
content: Hello,I've been looking into compact methods of measuring AC mains voltage. Most of what I read involves using a small transformer block to step-down to a safe voltage, and then use a peak detection circuit.If I look at teardowns of consumer products, they'll often contain one of these instead:https://www.ebay.com/itm/323728670022(which I believe has a 1:1 turn ratio, but there are other configurations)Obviously I want to galvanically isolate the low-voltage side of the circuit, but does the coupling have to be magnetic?(this is the part where I describe what I assume is a very common circuit with a well-known name which I've managed to miss somehow)I'm wondering about a circuit like this (attached). The 3 capacitors will create a voltage divider on the mains side, however the conductive material between C1 and C2, as well as between C2 and C3, isn't electrically coupled with the mains. If I measure the voltage between them I should be able to get a "safe" reading. I then rectify it and feed that into a peak-detector circuit.To increase the insulation I could add more capacitors in series (second attached image). A quick parametric search shows quite a few compact MLCC capacitors capable of this.They're not cheap, if I use 5 of them it'll probably cost more than a cheaper transformer block. They're also not that small, and they'll need routing around them to properly insulate them from the rest of the circuit. However they areflat, which is a big advantage if I want to make a compact design.Could a circuit like this be used to safely measure AC voltage?

author: Ian.M
author_rank: Super Contributor
timestamp: January 28, 2023, 02:29:04 pm
content: No. Generic MLCCs aren't suitable for applications where the isolation safety of a Class Y capacitor is required. See:https://en.wikipedia.org/wiki/Capacitor_types#Class_X_and_Class_Y_capacitorsTwo chains of high value resistors between Line and the + input, and Neutral and the - input of an instrumentation amp or differential OPAMP would be preferable. Some care is needed to match stray capacitance.

author: Benta
author_rank: Super Contributor
timestamp: January 28, 2023, 08:08:49 pm
content: Yes, you need magnetic or optical or some other coupling. BUT NOT CAPACITVE!Your capacitive divider will provide a nice 230/2 = 115 VAC level with a lot of whammo. Likely won't kill a young person, but most probably someone with a weak heart.Don't go there.

author: Kim Christensen
author_rank: Super Contributor
timestamp: January 29, 2023, 12:33:49 am
content: Perhaps we should be asking you this:WHY do you want to measure AC mains voltage? What is the end goal?

author: MrAl
author_rank: Super Contributor
timestamp: January 29, 2023, 04:19:39 am
content: Quote from: derGoldstein on January 28, 2023, 02:16:00 pmHi,True isolation in a nut shell means no current to ground from either terminal.If you have a transformer with isolated secondary when you connect either output terminal to the input ground (or neutral) you get no current flow.Even if you connect either output terminal to the 'live' side of the input power line you get no current.With a capacitive only circuit when you connect either terminal to the input neutral you will see current flow. That current flow means it is not galvanically isolated.So in a nutshell, no current means isolated, some current even a small amount means non isolated.Now there may be some debate as to how small the current can be in order to call it isolated. That depends on the application. For something like human protection you may get away with a 1 megohm resistor to provide isolation, but in a medical environment that may not be acceptable. It may even be as low as 10k in some situations, but dont quote me on that because it can not be said without knowing the application and what the implications are when you have some 'leakage' current. Some isolation transformers may even have a small amount of leakage current so they should be tested to see if they fit your application.You might note that there are what some people call "ghost" voltages. These are voltages that appear only because the measuring impedance is so high that even a tiniest leakage current will cause a somewhat high voltage to be measured. Often these can be ignored but to test you have to lower the impedance of the measuring device (like a volt meter) so that it can shunt the small leakage current.I measured this in a bathroom one time in the overhead shower light. I also measured this another time in an older light switch that was turned to the 'off' position, but with no light bulb in the light bulb socket you could still measure 120vac 60Hz because the measuring device had very high input impedance (probably 10 Megohms). Lowering that impedance to 100k would have probably shunted the tiny leakage current and lowered the voltage to near zero.There are a lot of things to consider when thinking about galvanic isolation. You have to have some experience in this area or you could get into trouble.

author: derGoldstein
author_rank: Regular Contributor
timestamp: January 29, 2023, 07:33:31 am
content: Thanks everyone for your replies!There's definitely more to this than I initially assumed.Quote from: Ian.M on January 28, 2023, 02:29:04 pmSo safety capacitors would be required for this application. Something like this:https://www.vishay.com/docs/28566/smdy1.pdfQuote from: Benta on January 28, 2023, 08:08:49 pmCould I get around this by limiting the current flowing into the capacitors? Something like (see attached) circuit.Also, by tweaking the capacitance ratio between the caps I would be able to limit the voltage at the 2 sensing points.Quote from: Kim Christensen on January 29, 2023, 12:33:49 amI'm trying to measure power going through an AC line. A current transformer is used for current measurement, but I want to take voltage variation into account.Quote from: MrAl on January 29, 2023, 04:19:39 amI see what you mean about current flowing between the low and high side, though wouldn't the Y capacitor in a switching power supply allow current to flow? Those connect the ground of both sides of the circuit, however since it's connected to the rectified part of the high side, possibly no current would flow under that condition? (I'm still trying to understand that)It seems like I may be introducing more problems than it's worth and I should stick to a transformer-based solution. I just thought it would be neat to flatten/miniaturize that part of the circuit.

author: shapirus
author_rank: Super Contributor
timestamp: January 29, 2023, 10:18:37 am
content: Quote from: derGoldstein on January 29, 2023, 07:33:31 amassuming the isolation problem is solved, how are you going to acquire/read/use the value?

author: Ian.M
author_rank: Super Contributor
timestamp: January 29, 2023, 10:33:59 am
content: To measure AC power (rather than VA) you need to multiply the instantaneous voltage by the instantaneous current and average that over a whole cycle. Seehttps://en.wikipedia.org/wiki/AC_powerAny significant relative phase shift between your voltage and current sensing and isolation circuits will result in gross errors. You don't appear to have the necessary experience to design a safe and accurate circuit to do this properly.Many manufacturers make AC energy metering chips that do all the 'heavy lifting' for you and provide an easy to isolate digital output - typically a SPI interface and a pulse output with pulse rate proportional to the average power. The energy metering chip will need a power supply - either a non-isolated capacitor dropper (as the metering chip runs 'mains live', typically with its 0V connected to AC supply Neutral), or an isolated DC-DC converter powered from the isolated low voltage domain containing your MCU. There's usually a reference design you can follow for board layout, and from a safety viewpoint, its hard to get it wrong following that reference design, if your creepage and clearance distances between the mains live, and isolated low voltage sections of your circuit meet the applicable standards, and all components that cross that isolation gap are genuine from a major distributor, with appropriate safety approvals tor that usage.If you want to do the math in your own code in a MCU on the isolated low voltage side, it may also be worth looking at schematics for high voltage differential oscilloscope probes, and their board layout and construction, as they face similar challenges but need even more bandwidth than a typical energy metering application

author: jonpaul
author_rank: Super Contributor
timestamp: January 29, 2023, 11:43:20 am
content: Waste of time and unsafejust buy a power watt meter $10..20 AZ epayplug-in, safe, measuring VI, W, PF, etc.j

author: Doctorandus_P
author_rank: Super Contributor
timestamp: January 29, 2023, 11:47:48 am
content: Reminded me of this capacitive voltage divider:HP 452ASo yes, you can make a capacitive voltage divider. They are even used to take off power from high voltage lines, but it's not trivial.For one thing, the capacitance of ceramic capacitors get lower as it's voltage rises (some types have half or even less of their capacity remaining at their nominal voltage). Another problem is that it's not a true galvanic isolation. Normally one side of your power input lines is already "earthed" and this will distort your measurement.Another problem is your diode, it will charge your measurement capacitors to some DC voltage and cause for further errors.I suggest you stay away from mains voltages until you have a few years more experience and have a better understanding what you're dealing with.

author: derGoldstein
author_rank: Regular Contributor
timestamp: January 29, 2023, 02:52:53 pm
content: Quote from: shapirus on January 29, 2023, 10:18:37 amConnect one side of the probe to a virtual ground and the other to a non-inverting amplifier. Then take that signal and connect it to a precision rectifier, and feed that to a peak detector. Then use an ADC to read it through a buffer, and log it. Among other things, I want to see what the voltage variability is over time.Quote from: Ian.M on January 29, 2023, 10:33:59 amI don't require incredible accuracy, nor do I expect to achieve it. So far just a current meter is close enough. Mainly the intent is to learn.I've looked into power metering chips like the CS5490. I might get an eval board so I have a good reference point, like this one:https://www.digikey.be/en/products/detail/cirrus-logic-inc/CDB5490U-Z/2797397(They're incredibly expensive though)I could design a circuit based on a CS5490, but then I don't think I'm learning much. Part of the exercise is to see how mains voltage fluctuates over time, and to see how accurate I can get by logging it and current separately.Quote from: jonpaul on January 29, 2023, 11:43:20 amI'm already using these as a reference. This isn't so much about solving a problem as it is about learninghowto solve it.Quote from: Doctorandus_P on January 29, 2023, 11:47:48 amI'm going to use magnetic coupling, I've been thoroughly convinced that's the safest option. However just for the sake of argument -- the diode and ground are just there as shorthand, which I realize I shouldn't have done in this context. I was going to log the peak-to-peak over time and see how it fluctuated. I wasn't expecting an accurate voltage measurement, but rather to see how much it changed over days and weeks.

author: shapirus
author_rank: Super Contributor
timestamp: January 29, 2023, 03:25:44 pm
content: Quote from: derGoldstein on January 29, 2023, 02:52:53 pmSounds like this will work fine for a rough estimation, and this is also why an isolation step-down transformer is a good choice because of its simplicity and safety, and, since you will rectify the wave anyway, you don't care if it doesn't translate the input waveform distortions precisely between the primary and secondary windings.I had a similar hobby task some time ago, which evolved like this:1) isolation: transformer, measurement: rectifier->ADC;2) isolation: optocoupler, measurement: resistive divider->buffer->voltage-to-freq-converter->SBC+software;3, final) measurement: resistive divider->buffer->ADC->(SPI isolation)ADuM2401->SBC+software, various measurements of the sampled waveform.The final solution turned out to be unexpectedly precise, I'm somewhat surprised and very satisified of how it works. It can measure RMS and Vpp voltage, frequency and how much the actual waveform deviates from an ideal sine wave. I posted more details in a similar topic here:https://www.eevblog.com/forum/beginners/power-company-voltage-waveform-measurement/msg4663045/#msg4663045,it may give you some ideas.It however wasn't estimated in terms of its safety by any experts, so you've been warned.

author: Siwastaja
author_rank: Super Contributor
timestamp: January 29, 2023, 04:19:14 pm
content: I don't understand the comments of capacitive coupling being categorically wrong or unsafe.Y rated capacitors are used from mains live to chassis parts all the time and this is completely legal everywhere as far as I know, as far as leakage current is withing the legal limits.For voltage measurement, the problem I see is functional: the capacitor forms a voltage divider based on its capacitive reactance (1/(2*pi*f*C)), and while this has the property of limiting current to safe levels, the divided voltage will vary depending on C, and capacitors have poorly controlled capacitance values. You can of course buy precision capacitors, but they are not Y rated, then.For detecting phase angle, or approximate value for voltage, this would work. For accurate phase angle detection, you would need to add some calibration, anyway.

author: shapirus
author_rank: Super Contributor
timestamp: January 29, 2023, 04:30:19 pm
content: Quote from: Siwastaja on January 29, 2023, 04:19:14 pmNot to mention the change in capacitance over time as the capacitors age, which would require an occasional recalibration. Not sure how much of a trouble this is going to be with any given type of capacitor, though.All things considered, it seems to me that the magnetic transformer way of doing this seems to be a more reliable and accurate solution than using capacitors. Safer? Maybe yes, or maybe the same, if Y-rated capacitors are used, which are supposed to fail open. It would be interesting to hear other safety-related considerations. What else can go wrong besides a capacitor failing short?

author: MrAl
author_rank: Super Contributor
timestamp: January 30, 2023, 06:26:21 am
content: Hi,What cap are you referring to when you say, "Y cap in a switching power supply"?Not all switching power supplies are isolated. The ones that are using magnetic coupling and to get feedback some of them use opto couplers. The small wall warts almost all use opto couplers for the feedback voltage so they can still regulate the output without compromising the isolation properties.So the transformer provides the power isolation, the opto provides the isolated return feedback.

author: Siwastaja
author_rank: Super Contributor
timestamp: January 30, 2023, 06:34:30 am
content: Quote from: shapirus on January 29, 2023, 04:30:19 pmNot only they are "supposed" to fail open, they do fail open. Y capacitors are installed in millions and millions of devices to couple mains live to chassis. If they were unsafe, we would be in huge trouble.

author: MrAl
author_rank: Super Contributor
timestamp: January 30, 2023, 06:37:49 am
content: Quote from: Siwastaja on January 29, 2023, 04:19:14 pmHi,It depends on what kind of isolation you are looking for.If you need full isolation you dont want to use a capacitor, but if it is not a very high value it may be acceptable because the current flow partially depends on the value of the capacitor and a capacitor has impedance which means some AC current will flow along with a possibly huge current spike when the unit is first plugged in or turned on. This is similar to using a high value resistor which may not cause a problem, or having a small amount of leakage in the transformer. These may or may not cause a problem, but for max isolation you want as little leakage (AC, DC, or transient) as possible.Some of the old audio amplifiers used to connect the neutral right to the chassis, and the chassis was connected right to the ground of the microphone input jack. Thus, when the performer would touch the metal of the microphone they were touching directly to the neutral wire.That was no problem for a long time until performers started getting electrocuted, then they realized that if the plug to the amplifier was plugged in in reverse or the outlet was not wired correctly, that would cause the 'hot' wire to be connected to the performer and with the performer working outdoors standing on the ground they get a shock.I know how this works firsthand because back when i was in a rock band we did outdoor performances sometimes and one time i got a shock when my mouth contacted the microphone screen (which was metal connected to the metal of the mic which was connected to the ground lead of the mic cord going to the amplifier). I realized right then and there what the problem was because i was very familiar with how electronic equipment worked. I unplugged it and reversed it and plugged it back in.Years later they changed this, for one they went to three prong power cords and began to stress not using a three prong to two prong adapter.Just to note, the impedance of a capacitor is 1/(j*w*C) and the impedance of an open circuit is infinity :-)

author: Siwastaja
author_rank: Super Contributor
timestamp: January 30, 2023, 06:54:21 am
content: Quote from: MrAl on January 30, 2023, 06:37:49 amThere is no such a thing as "full isolation". There are classes like functional, basic and reinforced insulation, but Y capacitors can be legally used, and are commonly used in any of them.There are maximum leakage current limits for different applications, which requires reading the relevant standards - for example, Y capacitors are approved even in use of medical devices, but the leakage current spec is tighter, meaning C must be smaller.For approximate measurement of voltage or phase angle, one can use very small value of C. Case in point, I have evaluated non-contact measurement of phase angle by just attaching short piece of wire on top of existing double insulated cables. Of course the tiny capacitance (some pF) varies all over the place. But definitely safe and legal.

author: Alti
author_rank: Frequent Contributor
timestamp: January 30, 2023, 05:54:45 pm
content: Quote from: derGoldstein on January 28, 2023, 02:16:00 pmWhat is wrong with resistive voltage divider?You can design divider to withstand any surge that is necessary to pass the EMC test and to be compliant. If that is between mains and low voltage circuit, you can include adequate clearance and creepage. Resistors have their voltage ratings specified in datasheet, just use as many as you need, in series.Of course if you use 10M divider, it might require some buffer to feed ADC but that is not terribly complicated.

author: shapirus
author_rank: Super Contributor
timestamp: January 30, 2023, 06:04:25 pm
content: Quote from: Alti on January 30, 2023, 05:54:45 pmdepending on the ADC and the sampling frequency, signal source impendance of as low as, say, 5-10 kOhm, may already be considered too high, so it's generally quite likely that the signal will have to be buffered. The ADC's datasheet should normally contain an answer to this, often even including suggested typical circuits.

author: MrAl
author_rank: Super Contributor
timestamp: January 30, 2023, 06:54:58 pm
content: Quote from: Siwastaja on January 30, 2023, 06:54:21 amNot sure what seem to be arguing here. Full isolation simply means no path for current. There is of course usually a voltage spec to go with that, but that would be in the specification. For example, some opto couplers are rated for something like 1500v maybe more. That would be considered full isolation in the applications that use that kind of device. A 0.1uf capacitor rated at 350v would not be considered full isolation in that application.If that's not good enough for you then use a laser to transmit a signal, bounce it off the moon, detect it with a photomultiplier. Compare that to the same signal sent to the same place with a 10pf capacitor. Which is more isolated. If you dont consider bouncing it off the moon to be 'full isolation' then i dont know what to tell youBut then who really cares what the definition of full isolation is. If it works for the application, it works for the application, and if it does not work for the application then we better get the laser out (ha ha) or just improve the isolation method.Yes there are different classes of protection. Is there no wording that actually states "full isolation"? So what.But feel free to use a capacitor anytime and any where you feel the need to do so. You could also research why you would want to use one in the first place. I very seriously doubt you will be using one to IMPROVE isolation as no matter what the application is i believe it will always degrade the isolation properties whether it is legal or not.One of the best isolation techniques i have seen for regular transformers is when the two windings are placed at different places on the core. That means they are actually spaced apart with an insulator between the coils, and they are not wound on top of each other. Makes for some extra leakage inductance but then that helps with rectifier circuits on the output that have to put out something that resembles DC.

author: Kim Christensen
author_rank: Super Contributor
timestamp: January 30, 2023, 11:15:35 pm
content: QuoteYea, that is what it comes down to in the end... How much isolation do you need/want. No matter how you do it, you're going to be touching the live AC wiring with some part of your circuit.The safest for a beginner hobbyist would be to get one of those AC-AC wallwarts and play around with the low voltage AC into an ADC or AC-->DC converter as a learning experience. Doesn't really matter if it's terribly inaccurate or not.For the more experienced, you could power a small MCU directly from the AC line via a capacitive dropper, sample scaled down AC with it's ADC, and send that data via an opto-isolator to another MCU where the main processing, logging, and USB interface, etc is done...

author: MrAl
author_rank: Super Contributor
timestamp: January 31, 2023, 12:50:44 pm
content: Quote from: Kim Christensen on January 30, 2023, 11:15:35 pmOh yes i have used those 'offline' power supplies myself a few times they save on having to use a transformer.What is interesting about that, and glad you brought it up, is that if you do use that and the user has to turn a pot shaft to adjust something, you can use a pot with a plastic shaft so they are not touching anything metal. There would be at least an inch of plastic between the fingers and the circuit even if the other end touched a live wire. I would not trust a metal shaft with a plastic knob however because the knobs break sometimes exposing the metal, then have to hope the other end does not come into contact with any part of the circuit.Another little interesting thing that came up in the past was the LED night lights. They use that kind of power supply too, which means they use a series cap to drop some of the line voltage down to around 5v or so. When you unplug some of them if you place a finger across the two line power prongs, the LED lights up for a little while again (ha ha). The cap inside there supplies some energy for s short time and with the prongs shorted with a finger the current gets to the LED. You dont feel anything on your finger even though the voltage can be 100v or more when you first unplug it. if you wait too long through the bleeder resistor dissipates all the energy so the LED wont light up.

author: EPAIII
author_rank: Super Contributor
timestamp: January 31, 2023, 11:35:09 pm
content: In my mind there are so many unanswered questions here. Things like:Is this for a commercial product, to be sold to the general public?Or is it for your use only?Will others in your home or facility use it or come in contact with it?Will it be in a controlled environment?Will it be in continuous use? For long periods of time?Unsupervised and/or unmanned?Or only occasional use?Is it going to be a stand-alone device?Or is going to be part of a larger device?What type of case or enclosure?Do you need actual Voltage readings or just a power present/absent indication.What accuracy?More details on just what you are actually doing would make it easier to suggest practical circuitry.For instance, if I wanted to measure the AC Voltage at one of my workbenches, I would just grab a VOM with a CAT III or higher rating, set it for 500 VAC, and carefully insert the probes in the nearest AC socket.If this is not for a commercial product, a very safe way to do this for a device that can monitor that Voltage on a more constant basis might involve mounting an inexpensive digital meter device in a metal box and connecting the line to it via the necessary dividing resistors. The line cord would enter the box through a "D" pin, fused power entry connector (or one commonly used in your country) and the safety ground would be connected to the metal box near that "D" pin connector (I usually use one of the mounting screws). Since all the circuitry would be inside that grounded, metal box and the line would be fused at the entry point, there would be little need for additional protective measures in the circuitry. This method would work both for a simple Voltage monitor or as part of a larger device.If a DC Voltage meter is used, a rectifier diode and filter capacitor can be added to convert the AC to DC. The dividing resistors can be used before that rectifier if great accuracy is not needed or after it for better accuracy.When selecting the components I would look to older style parts with wire leads instead of surface mount ones. They will have higher Voltage ratings. 1 Watt resistors would be advisable and flame proof ones are available.If it is for a commercially sold device, then I would suggest that you consult the appropriate safety standards for the country or countries where it will be sold.

author: juan3211
author_rank: Contributor
timestamp: March 20, 2023, 09:18:14 pm
content: Hi, I have read this post because I also want to measure and "see" a wave form of mains, inverters (pure sine and modified) and compare them.I have a DSO battery powered so I can be "floating"I have a doubt about "small transformer block to step-down to a safe voltage" method.Does this transforme disturb/smooth the 50/60Hz signal? What about armonics? are they also affected?Thanks.

author: shapirus
author_rank: Super Contributor
timestamp: March 20, 2023, 09:28:48 pm
content: Quote from: juan3211 on March 20, 2023, 09:18:14 pmI once wanted to answer this question for myself, so I took a small 1.5VA 220V->18V 50Hz transformer and connected its primary winding to a signal generator putting out a 20 Vpp signal. There was no load on the secondary winding, except for the scope's input resistance. It worked quite well, at least, for visual inspection. Even the triangular wave was not visibly distorted in any way. Any changing signal is going to be ok, I guess, but, obviosly, the flatter the signal is (think clipped peaks, for example, with DC being the extreme case), the more it will be distorted.It was also good up to a few kHz, maybe even 10-20 kHz, I don't remember what max frequency I tried it with.