Measurement of AC voltage using OP-AMP

Thread Starter

alobaolalekann

Joined Jan 31, 2017
21
I want to use my microcontroller to measure AC voltage by using OP-AMP.
I saw an implementation using lm258 (Here).
What I have in my inventory is mcp6002.
I find it confusing that from the datasheets of both devices, the absolute and recommended input voltages are way below the 230VAC coming from mains. And I'm afraid the device would be damaged if connected. But it seem I am wrong. Can someone help me get what I may be missing? Thanks
 

WBahn

Joined Mar 31, 2012
32,745
It sounds like you are about to head down the road of connecting mains-level voltages to low-voltage circuits. This is highly discouraged here, especially for someone new to electronics. You can very easily and quickly kill yourself or someone else.

The proper way to measure mains voltage is to use a transformer to step it down to something compatible with your low-voltage circuitry.
 

Thread Starter

alobaolalekann

Joined Jan 31, 2017
21
It sounds like you are about to head down the road of connecting mains-level voltages to low-voltage circuits. This is highly discouraged here, especially for someone new to electronics. You can very easily and quickly kill yourself or someone else.

The proper way to measure mains voltage is to use a transformer to step it down to something compatible with your low-voltage circuitry.
Thank you for your response.

The reason for this measurement is to send the measured signal to the ADC of my microcontroller (3.3Vin) to implement the control of a converter. The use of the transformer method is not desired by my Boss because of cost and size.

"The proper way to measure mains voltage is to use a transformer to step it down to something compatible with your low-voltage circuitry"
Do you imply that the transformer method is the only way to go about this?
 
Last edited:

Irving

Joined Jan 30, 2016
5,045
I second @WBahn 's warning and do not recommend you go ahead with this approach without a lot more understanding.

Having said that, the approach here is to use a very large resistor divider to bring the voltage within range of an opamp. Each side of the resistor chain reduces the voltage by 22k/(2M +2.2k+22k) = 0.01, thus the differential voltage between the probe tips is reduced by a factor of 100 at the output of the opamp. All of that is explained quite clearly in the text. I suggest you read and re-read it carefully.

This isn't something I would expect a recent grad to be safe to do, though I would expect and EE grad to understand how this circuit works and be able to adapt it. Did you not cover differential amplifiers on your course?

You cannot use the MCP6002 in that circuit as-is, It is only able to use a 6v supply voltage and you will need to change several resistor values to work within the parameters of the MCP6002. I'm not going to tell you the values but once you understand how it works and have figured out some values yourself, I'm happy to review them with you.


Here's a couple of videos that might help too...


 

DickCappels

Joined Aug 21, 2008
10,661
I "third" WBhan's warning.

If you are working with more experienced engineers it might be ok to use the differential amplifier approach outlined in the article to which you linked because if laid out properly (and shielded from probing fingers) it will not be able to deliver dangerous currents to a person who touches the small signal part of the circuit, particularly if the circuit is properly grounded to earth.

Notice that in the article two pair of input resistors to the differential amplifier. Do not replace these with one resistor because with two resistors the input current is still limited by the other resistor so it probably won't damage the circuit or kill somebody who touches it.

Don't mess with dangerous voltages if sleepy, you have been drinking or using drugs that might make you sleepy or easily distracted. When working around dangerous voltage keep one hand behind your back and wear clean rubber soled shoes or stand on a rubber mat to reduce the chances of an electric shock going through your heart.
 

Ian0

Joined Aug 7, 2020
13,109
If you want to measure AC mains without a transformer, then your microprocessor may not connect to any low voltage system - no USB, no RS485, no touch switches, no pushbuttons with metal parts etc.etc. (and keep your fingers out of the way)
My suggestion would be this transformer:
https://www.micro-transformer.com/pcb-mounting-voltage-transformer-zmpt101l.html
1mA in, 1mA out.
Drive it from the mains with a 230k resistance.
On the output connect a 1k load and connect it to your microprocessor pins, bias it to half supply. You will get 1V rms output for 230V input. If you want to be posh, use a transimpedance amplifier.
You can sample that - square each sample, divide by the number of samples and then take the square root to get your RMS value.
 

Thread Starter

alobaolalekann

Joined Jan 31, 2017
21
[
I second @WBahn 's warning and do not recommend you go ahead with this approach without a lot more understanding.

Having said that, the approach here is to use a very large resistor divider to bring the voltage within range of an opamp. Each side of the resistor chain reduces the voltage by 22k/(2M +2.2k+22k) = 0.01, thus the differential voltage between the probe tips is reduced by a factor of 100 at the output of the opamp. All of that is explained quite clearly in the text. I suggest you read and re-read it carefully.

This isn't something I would expect a recent grad to be safe to do, though I would expect and EE grad to understand how this circuit works and be able to adapt it. Did you not cover differential amplifiers on your course?

You cannot use the MCP6002 in that circuit as-is, It is only able to use a 6v supply voltage and you will need to change several resistor values to work within the parameters of the MCP6002. I'm not going to tell you the values but once you understand how it works and have figured out some values yourself, I'm happy to review them with you.


Here's a couple of videos that might help too...


Thank you very much for providing insight to the voltage divider network.

It seem that was the clue I was missing. I had thought the mains fed directly into the input of the OP-AMP, and the resistors were only to limit the current.

Of course I have the basic understanding of how operational amplifier work. I will tailor my design to mcp6002 and share the calculated resistor values with you. Thank you. I really do appreciate.
 
Last edited:

Thread Starter

alobaolalekann

Joined Jan 31, 2017
21
I "third" WBhan's warning.

If you are working with more experienced engineers it might be ok to use the differential amplifier approach outlined in the article to which you linked because if laid out properly (and shielded from probing fingers) it will not be able to deliver dangerous currents to a person who touches the small signal part of the circuit, particularly if the circuit is properly grounded to earth.

Notice that in the article two pair of input resistors to the differential amplifier. Do not replace these with one resistor because with two resistors the input current is still limited by the other resistor so it probably won't damage the circuit or kill somebody who touches it.

Don't mess with dangerous voltages if sleepy, you have been drinking or using drugs that might make you sleepy or easily distracted. When working around dangerous voltage keep one hand behind your back and wear clean rubber soled shoes or stand on a rubber mat to reduce the chances of an electric shock going through your heart.
Thank you for the advice. Will always keep in mind.
 

Thread Starter

alobaolalekann

Joined Jan 31, 2017
21
I second @WBahn 's warning and do not recommend you go ahead with this approach without a lot more understanding.

Having said that, the approach here is to use a very large resistor divider to bring the voltage within range of an opamp. Each side of the resistor chain reduces the voltage by 22k/(2M +2.2k+22k) = 0.01, thus the differential voltage between the probe tips is reduced by a factor of 100 at the output of the opamp. All of that is explained quite clearly in the text. I suggest you read and re-read it carefully.

This isn't something I would expect a recent grad to be safe to do, though I would expect and EE grad to understand how this circuit works and be able to adapt it. Did you not cover differential amplifiers on your course?

You cannot use the MCP6002 in that circuit as-is, It is only able to use a 6v supply voltage and you will need to change several resistor values to work within the parameters of the MCP6002. I'm not going to tell you the values but once you understand how it works and have figured out some values yourself, I'm happy to review them with you.


Here's a couple of videos that might help too...


Found out the only MCP6002 available is not good so I'm using LM358N.
My circuit sketch is shown below.

The output of my design seem to be okay when the negative terminal of the Vin was not connected with the DC ground. As seen in the first oscilloscope image.

When I connected the negative terminal of the Vin to the other DC ground , I got the second oscilloscope image as the output. The negative cycle of the output is chopped.
The reason why this happened is what I don't understand yet.

P.S: I'm taking all necessary precautions, especially those suggested by @DickCappels
This design will not be going into any product as is but it's a good step in my learning experience to come up with something better.
 

Attachments

Papabravo

Joined Feb 24, 2006
22,061
Can you clarify why you are going on about multiple "DC ground" points. That is just not possible. There can be only one ground.
 

Thread Starter

alobaolalekann

Joined Jan 31, 2017
21
Can you clarify why you are going on about multiple "DC ground" points. That is just not possible. There can be only one ground.
First of all, I used two dc power supply for the offset voltage and the supply to the OP-AMP. And their grounds were connected together.

The Vin is the voltage from mains supply that was stepped down by the resistor network to suit the OP-AMP input range. Y'know the Vin has two terminals, the positive and negative. When only the positive was connected to the OP-AMP inverting input and the negative was dangling I got the perfect sine wave but when the negative was connected to the joint DC ground, I got the chopped sinusoidal waveform.
 

Papabravo

Joined Feb 24, 2006
22,061
First of all, I used two dc power supply for the offset voltage and the supply to the OP-AMP. And their grounds were connected together.

The Vin is the voltage from mains supply that was stepped down by the resistor network to suit the OP-AMP input range. Y'know the Vin has two terminals, the positive and negative. When only the positive was connected to the OP-AMP inverting input and the negative was dangling I got the perfect sine wave but when the negative was connected to the joint DC ground, I got the chopped sinusoidal waveform.
Your diagram says something different. It SHOWS three, count 'em three, identical ground signals. Evidence suggests your description and your diagram are at odds. It seems reasonably clear that you may be fooling around with things you don't quite have a handle on. Correct me if I am wrong but the opamp is being operated in single supply mode with one or both input signals that swing both positive and negative.

IMHO you should bias the opamp at Vcc/2 = +6 volts and capacitively couple the sinusoidal input form the mains to the inverting input.
 

Irving

Joined Jan 30, 2016
5,045
STOP!

Unless that 230v supply is via an isolation transformer which you didn't mention you are extremely lucky not have blown up your 'scope or yourself. You must never connect a live AC feed to a grounded circuit which is what your 'scope is unless its running purely on batteries. Thats the reason for using a differential probe with AC feeds. If L & N ('hot','live'and 'cold', 'neutral') are reversed (not uncommon outside UK where there is less legislation and often encountered on older installations here) grounding the 'live' side via your 'scope 'ground' will result in catastrophic damage to the 'scope and anything connected to it plus risk to the operator.

Even if that wasn't the case, there can be a significant potential difference between N and ground depending on how good the earth bonding is at the incoming feed to your installation. N should be bonded to E locally but often isn't very well, resulting in 10s of volts between N and 'ground' which can still do signifcant damage to equipment and people.

Power supplies are generally less of an issue as their outputs are usualy floating, but one should never assume that without checking.

I'll deal with your component choices in a separate post.
 

Ian0

Joined Aug 7, 2020
13,109
Yes stop now.
Otherwise someone will stop you the first time your product gets safety tested and they find a connection between live and earth and out a big “safety test failed” label on it.
Then what will you do?
 

DickCappels

Joined Aug 21, 2008
10,661
The whole point of the differential amplifier in the original circuit is to ground reference the AC line voltage signal without a direct connection between the power line and earth ground. I suggest that you go back to the original circuit.

The LM358 is ok for some things but it has significant input bias current. If things go well the offsets currents from the + and - inputs will mostly cancel. If things do not go well your the output will have an unwanted offset. There are some inexpensive dual op amps available with much lower input bias currents. (this almost funny) The nice thing about the LM358 is that it is in a standard package and you easily swap it out of a better dual op amp if needed.

You are getting suggestions to stop of a good reason -we want you to live and as Irving hinted, having your scope connected connecting your scope to Neutral can result in unwanted currents returning to earth through your probe lead. It could wreck your probe or your scope.

My opinion has not changed: The circuit you first showed to us should be fine if you do it as the author showed you. 2 megohms will not allow enough current to do any real damage, even if one of the 1 meg resistors in the string is shorted. Take care not to exceed the maximum allowable voltage for the resistors you use.
 

Ian0

Joined Aug 7, 2020
13,109
Never mind the current through the 2M resistors: Don’t forget the 2.5kV or 4kV flash test.
If the processor is earthed, it’s going to see the full 2.5kV across those resistors. It needs to be isolated.
 

Ian0

Joined Aug 7, 2020
13,109
It‘s in EN60335 (Domestic appliances), EN60950 (IT equipment) and EN60065 (Audio equipment), all of which are based on international standards. EN60065=IEC65 and I think the others follow suit. Those are the one I am familiar with - I suspect it crops up elsewhere.
There’s various different voltages. 4kV for double insulated, 2.5kV or 1.5kV for Class I.
I’m not sure about anywhere else other then Britain, and perhaps Germany, where it is also a part of the annual Portable Appliance Test or Prüfung ortsveränderlicher Elektrischer Betriebsmittel
 

Irving

Joined Jan 30, 2016
5,045
@Ian0 is right in that your equipment could fail a PAT test (UK/EU) of insulation resistance, line to earth - its also a timely reminder that designing the measurement aspect of the circuit is only part of the problem. Coping with power-line transients and spikes is another we haven't touched on yet. Mind you the former only applies to portable equipment with a plug; it doesn't apply to equipment permanently installed (but other regulations may apply).

Can you shed any light on the purpose of the equipment (and the need to measure actual AC volts)?
 
Top