# High frequency mains sensing

I want to sense mains voltage at a frequency faster than 5000Hz, with a microcontroller. The idea behind this is to visualize the actual shape of the AC voltage, and eventually to compare it with the current to determine its cosphi.

I have read that I need to use a optoisolator to isolate both circuits. How do I choose which one I need for an analog output of the scaled voltage?

• Can you please provide a link to where you read that you should use an optoisolator in this case? Are there certain optoisolators that you are considering? – Joe Hass Feb 7 '14 at 17:37
• Originally it said "sense mains voltage at a frequency faster than 5k" - I assumed this might have meant sample at 5k or above. I'm not sure that the modification/edit is correct based on that - it now implies samping at least 10kHz. – Andy aka Feb 7 '14 at 18:20

I would look into putting the microcontroller circuit on the hot side, have it do all the measurements by being directly coupled, then send the digital results over a opto. This gets around having to use analog optoisolaters. You will only be shipping digital information accross the isolation barrier.

Of course you have to be careful about touching anything on the hot side, whether that includes a microcontroller or not. Initial debugging should be done a isolation transformer, and preferably at lower voltages.

• Thanks ! Now something that is not clear in my mind: the microcontroller must be supplied with a 5V DC power supply. Does it share the same ground with mains voltage ? – tfjgeorge Feb 12 '14 at 16:34
• @tfjg: You will need to arrange for 5V power for the micro on the hot side. If you buy something off the shelf for that, it will probably be isolated, so the ground reference can be whatever is most convenient for making the measurements. Otherwise, you can probably use something like a capacitive charge pump that uses the AC line frequency for the pumping. I'd probably use the AC ground as the microcontroller ground then. That works with the charge pump and should be useful for making the measurements. – Olin Lathrop Feb 12 '14 at 17:19

There are a number of analog optoisolators that will work for you. The Vishay (nee Infineon) IL300 is an old standard.

It is normally used in a circuit such as this:

Because a single LED illuminates two photodiodes, the LED drift can be largely compensated by the closed loop feedback circuit.

Note that you require a power supply on the high voltage side, so you may require an appropriate DC-DC converter.

More accuracy is possible from more recently developed similar parts such as the HCNR201.

As others have said, there are a number of other galvanic isolation technologies, digital and analog (your signal could be digitized on the hot side, so there is some percentage in considering digital methods). Magnetic (analog and digital) and differential capacitor coupling are a couple of common ones. Some are modules that have an isolated power supply incorporated. Of course, price escalates rapidly as such features are added.

Use a regular voltage transformer rather than an opto coupler - it will provide the isolation (safety) and give you a decent linear analogue signal to feed into your MCU.

When you come to look at current use a current transformer. Feed the single wire thru the CT's hole and you get a decent representation of current across its burden resistor.

If you are going to calculate power factor (I'm presuming that's what you meant by Cos Phi) be prepared for significant errors - you can't just use zero crossing algorithms unless the current is particularly clean and free of harmonics. See this answer - it may help you understand how tricky it may be to measure power factor.

• I wonder if typical transformers designed for power applications have the bandwidth to pass the entire signal of interest? – Chris Stratton Feb 7 '14 at 18:13
• @ChrisStratton if you are interested only in calculating power factor then you are only interested in fundamental frequencies (with the assumption that the voltage waveform is virtually sinusoidal). Apart from the fact that power transformers deliver the power to your home in the first place!! – Andy aka Feb 7 '14 at 18:16
• The poster expressed an explicit interest in getting a wider bandwidth view. Many types of power supplies do in fact introduce distortions at other than the fundamental frequency - that may not strictly qualify as "power factor" but it can be of interest and actual concern. While transforms involved in power delivery may attenuate these to some degree, an instrument is hopefully designed to reflect as true a measurement as possible, without introducing additional rolloff in the bandwidth of interest. – Chris Stratton Feb 7 '14 at 18:19
• @ChrisStratton I agree with what you say - wider bandwidth is better of course but I took the meaning of the question to be "sampled" at 5kHz which you've subsequently altered to bandwidth of 5kHz upping S to 10kHz. It's just my impression of what he said. – Andy aka Feb 7 '14 at 18:24
• The $cos(\phi)$ implies it's sinusoidal, but 5kHz implies a lot of harmonic content. Hard to tell without ESP. – Spehro Pefhany Feb 7 '14 at 20:58