Line power voltage measurement - Page 1
Forum section: electronics / beginners

author: Unknown
author_rank: Unknown
timestamp: December 06, 2009, 10:40:21 pm
content: I'd like to measure the AC line voltage from a microcontroller. Here in the US, that's typically 120VAC, 60 Hz.What's the easiest way to do this?

author: EEVblog
author_rank: Unknown
timestamp: December 06, 2009, 11:29:49 pm
content: Quote from: bmwm3edward on December 06, 2009, 10:40:21 pmThe safest and most foolproof would have to be a transformer with a known turns ratio and a True RMS to DC converter chip (Analog Devices make them).Safety is important here.Dave.

author: Unknown
author_rank: Unknown
timestamp: December 07, 2009, 12:47:10 am
content: Agreed: I have a lot of experience with house wiring, which augments the safety aspect and respect for working with AC lines.With your direction, I found this chip at Analog Devices:http://www.analog.com/static/imported-files/data_sheets/AD536A.pdfIt appears to be able to measure 0-7 volt RMS. With that in mind, should I assume that a 40:1 transformer would be ideal for 120V-240v line measurements? (240V would be stepped down to 6 Volts).The confusing part for me is in the datasheet. It says in the beginning "The AD536A computes the true root-mean-square level of a complex ac (or ac plus dc) input signal and provides an equivalent dc output level." Sounds good to me, but the only output pin is "Iout". I=Current, so that is confusing.In the specs table, under the Iout pin it says the output in, in Volts, is "?VS to (+VS ? 2.5 V)". Does that mean that the output Voltage is proportional to the supply voltage, minus 2.5 Volts? Eg, if I had a 9Vdc power supply voltage, and the chip was sensing 6 Volts AC RMS on the input, the output would be 6-2.5, or 3.5 Volts DC?

author: Zero999
author_rank: Super Contributor
timestamp: December 07, 2009, 11:01:09 am
content: Quote from: bmwm3edward on December 07, 2009, 12:47:10 amHow do you get hold of a 40:1 transformer? Just use a 240V to 6V transformer you might say. The trouble is it might not be 40:1. Transformers are normally specified at full load current which means the unloaded secondary voltage will be higher than the rating when unloaded. If you buy a 240V 6V transformer, the turns ratio will probably be something like 30:1 but you won't know because it isn't normally specified.QuoteIt's a constant current output.There's an inbuilt 25k resistor connected to the Rout pin if you don't want to add your own resistor.This is good and bad: the advantage is that you can easily choose a resistor that'll give you the voltage scaling you require, the advantage is that you need to account for the input impedance of the circuit connected to it unless it's really high.QuoteThat's the positive saturation voltage of the output stage i.e. the maximum output voltage - +Vs-2.5VDisclaimer: I've only skimmed though the datasheed and haven't read it in great detail.

author: Unknown
author_rank: Unknown
timestamp: December 08, 2009, 12:05:20 am
content: Very good info, and thank you for taking the time with this.QuoteWill I need to load the transformer? I assume your point is that transformers are spec'd according to voltage, not turns. Should I put a low pass filter (capacitor) to reduce noise since I only care about the 60 Hz stuff?QuoteThis is Iout - and my hope is I can wire this directly to the microcontroller - which is high impedance (eg, Arduino or PIC input ADC inputs), yes? Here's the specs on the Iout terminal:Iout Scale: 40uA/V rmsIout Scale factor tolerance: +/- 10%Iout Output resistance: 25k ohms (as you mentioned)Iout Voltage compliance: -Vs to (+Vs-2.5V)You said Iout is current constant - but it says "40ua/V rms" does this mean the current changes according to measured voltage? (eg, 5 V RMS woudl yield 200ua?). I care about Voltage output, I thought. What spec describes what Voltage I should expect to see on the Iout pin?

author: Zero999
author_rank: Super Contributor
timestamp: December 08, 2009, 12:57:55 pm
content: Quote from: bmwm3edward on December 08, 2009, 12:05:20 amYou shouldn't need to load the transformer.You should be able to calibrate it using a pot on the constant current output.QuoteIf the mains waveform is not perfectly sinusoidal (there's a good chance it won't be) then you need to worry about harmonics because they're responsible for power dissipation.An ordinary mains transformer could be used for voltage measurement but I don't think it would be ideal because it might not pass all harmonics equally, I think it's better if the transformer is unloaded.QuoteYes, it shouldn't be a problem if the input impedance is a couple of orders of magnitude higher than the current sense resistor.QuoteA tolerance of 10% isn't very good but that can probably be improved with calibration.QuoteYes, that's right.QuoteThe output voltage can be calculated, using Ohm's law.

author: qno
author_rank: Frequent Contributor
timestamp: December 08, 2009, 04:23:42 pm
content: Maybe there is a better option than a transformer.If you connect or disconnect the transformer to the mains you get some really big spikes.You need good input protection to have your meter survive this.In measurement equipment a normal resistor divider is used. Use resistors specified for the voltage you use or a series configuration.If you want to sample the output you somehow have to make a galvanic separation between your setup and the PC you are using.

author: jahonen
author_rank: Super Contributor
timestamp: December 08, 2009, 04:34:06 pm
content: I have used a little different method, but it is not so foolproof in case of an error. It can, however, be built without using exotic analog parts. If youknowwhat you are doing, then you can measure the line directly by using a difference amplifier with suitable input resistors.That means at least 3 or 4 big resistors in series to mains in each "leg" of the difference amplifier inputs. Resistors should be chosen so that in case of one or two short circuit failures, the leakage current is still not lethal. I'd use something like 470k-1M? resistors. 4x 470k resistors in series leak about 120 µA from mains, which is much less than leakage current of ordinary mains line filter (about 300 µA) (like used on a computer PSU). Two short circuit failures on the resistor chain increase current to 245 µA which is still less.Do not use single resistor in any case.Ordinary resistors are only rated about 200 volts, and you'll want that single short circuit failure will not cause hazard.You can see the schematichere. That schematic contains other things too, but the voltage measurement amplifier is built around U1. Umeas_cm needs to be at middle voltage of your ADC conversion range. In other words, if you are using 5 volt reference to the ADC, then Umeas_cm is 2.5 volts. That can be quite easily achieved by just with resistor divider. Upre goes into your µC ADC input. If you want to use filtering, I suggest that cut-off is set at least to 20 kHz or so.Then the resulting amplifier output can be directly sampled by µC ADC and true RMS value can be calculated in the µC. This is much cheaper (and accurate) than analog RMS chip & ADC approach, although it needs care when designing the input stage and some thought when RMS is calculated. Also, the RMS calculation period should be integral multiple of the line period.Regards,Janne

author: Unknown
author_rank: Unknown
timestamp: December 08, 2009, 08:38:45 pm
content: Hero: Thanks for the followup. I think I have enough info here to attempt a prototype with this chip. Operative word here is attempt. :-)QuoteWhat about a varistor to shunt these spikes? Any downsides here?QuoteI like the simplistic approach here. Seems a fuseable link would be in order here as well. How do you do calculate the "intergal multiple of the line period"? And will this tie up my MC moreso than a dedicated chip that does RMS calculations?Who would have thought doing something as simple as one function of a $5 digital multimeter would be this complex. Dare I even mention calculating real/apparant power?

author: Zero999
author_rank: Super Contributor
timestamp: December 09, 2009, 12:19:08 am
content: Whilst the differential amplifier will work, it does mean adding extra components.I'd recommend using a resistive divider, see attached.It's a good idea to use high voltage resistors with that can handle a peak voltage of 1kV.The example divides the input voltage by five, you might need a different ratio: check the datahseet.You might need to take the input impedance into account: it will be equivalent to a resistor in parallel with the middle resistor, check the datasheet.You shouldn't need a MOV if the IC has built-in protection diodes.

author: jahonen
author_rank: Super Contributor
timestamp: December 09, 2009, 04:15:40 am
content: Quote from: bmwm3edward on December 08, 2009, 08:38:45 pmI meant actually integer multiple of line periods, that means that calculation is done multiple of 1/line frequency, i.e. 16.666...7 ms with 60 Hz or 20 ms at 50 Hz mains. Actually, cheap multimeters do not calculate true RMS values in a way what I suggested. Instead, they just rectify and then filter the voltage. Then the RMS is shown by just scaling the result with some magic number, depending how the rectifying and filtering is done. Of course this requires an implicit assumption of the sine wave, unlike the suggested calculation which would give correct RMS result with any arbitary input waveform.Yes your µC would be doing square-and-accumulate operations for each sample and when desired number of line periods is computed, then you first calculate average of those squared values (divide the sum of the squares by number of samples) and finally square root of the result, and here is the RMS value of your input waveform. I have not personally used arduino, but used µC should probably have hardware multiplier to save few CPU cycles. It's kind of an engineering tradeoff, cpu cycles versus more complicated hardware.regards,Janne

author: Zero999
author_rank: Super Contributor
timestamp: December 09, 2009, 10:50:04 am
content: Quote from: jahonen on December 09, 2009, 04:15:40 amI don't see what difference filtering the output of a full-wave precision rectifier and your method would make. A precision full-wave rectifier would just output the peak voltage, sampling at 1/F would give the same result assuming that the sample rate is in phase with the mains. In fact sampling at 1/F isn't guaranteed to give you the average peak voltage because you can only sample the positive or negative peak and you have to make sure to take the sample at either 90° or 270°.QuoteTo get a true sine wave measurement you need to sample at double the highest significant harmonic frequency. If the waveform is perfectly sinusoidal and symmetrical then, yes you can sample at F, if it's purely sinusoidal but not symmetrical you need to sample at 2F but if it's distorted you need to sample at double the highest harmonic.At a guess, you'll probably need to sample to at least 5th harmonic which for 60Hz is a sample rate of 600Hz.Measuring the current is going to be tricky though because many appliances distort the current waveform so badly that I don't think your MCU will be fast enough to sample at a high enough frequency so a true RMS IC is probably your best bet.Just thinking, it would ideal to derive the PIC's clock frequency from the mains, using a PLL, so you don't have to worry about synchronisation, but that's a challenge in itself.

author: jahonen
author_rank: Super Contributor
timestamp: December 09, 2009, 06:26:10 pm
content: Yes, of course one would need plethora of samples per one line cycle to calculate the RMS, I was implicitly assuming that without saying it clearly, sorry. One sample at the peak is clearly not enough. What I meant that the sample rate should be set so that for each line period has integer number of samples, say, 6000 Hz for 60 Hz makes exactly 100 samples per line cycle. In fact, 6 kHz would work for both 50 and 60 Hz. That way the resulting RMS value is stable.Regarding of the MCU loading, I'm not sure how other MCUs will do, but I have been on a commercial project in the past where we sampled a three-phase currents and voltages and calculated the RMS values and real power based on the results without any problems using a 6 MHz MSP430F147. But the MSP430 has a hardware multiplier which can calculate 16 bit square-and-accumulate operation essentially without any delay for this kind of application. However, we didn't have much else to do, but doing some simple functions when pressing buttons.I have feeling that we used something like 10 kHz sample rate, and low-pass filtering of about 3 kHz. Initially, we used lower cut-off, but then our customer complained that it showed high errors for non-linear load, so we increased the current signal cut-off to 3 kHz.Regards,Janne

author: Zero999
author_rank: Super Contributor
timestamp: December 12, 2009, 03:25:07 pm
content: One thing you might need to consider with the resistor potential divider idea is the power supply to the MCU: is is an SMPS? If so it might not be possible since the secondary side is often connected to the mains via a Y-rated capacitor and a high voltage resistor which will interfere with the potential divider.