Mains Resistor Divider - Page 1
Forum section: electronics / beginners

author: paul23
author_rank: Regular Contributor
timestamp: September 08, 2012, 09:54:11 pm
content: I´ve been looking through a few datasheets and app notes for energy meter IC´s. They all seem to recommend using a resistor divider for the voltage measurement. Now this works for me as I am limited for space and can´t really use a transformer. The part that has me worried is connecting the divider to GND. On the schematics it shows the dividers connected to the same GND as all the other components, which I am worried might cause problems if something goes wrong. Technically the GND is now connected to mains and that means all the components are too.I have included the schematic from an Atmel aplication note to demonstrate what I mean. I just want to be sure I am doing this right before connecting mains voltage, and also if there is any further safety I can add to this design. One thing I am doing different to this reference design is changing R1 to three resistors in series, in case there is a failure.Many ThanksPaul

author: David_AVD
author_rank: Super Contributor
timestamp: September 08, 2012, 10:14:52 pm
content: Is the circuit supposed to be isolated from the mains? Does it have user touchable areas, connectors, etc or is it completely stand-alone with no connections?

author: paul23
author_rank: Regular Contributor
timestamp: September 08, 2012, 10:53:21 pm
content: Sort of yes. Everything on the circuit is 5VDC apart from a couple of Relays. The energy IC will measure the power from the two relays (one for live, one for neutral). The microcontoller and this IC are 5V and there are LEDS and few other components that would get upset if I put 230V down them.There is a transformer used to step down the voltage to 18V, then a bridge rectifier and 7812 and 7805. But I need to sample the power after the relay. The 12V rail is so far only used for coils on the relays. Maybe if I just isolated the ground for 5V rail, that would do?

author: David_AVD
author_rank: Super Contributor
timestamp: September 08, 2012, 11:07:15 pm
content: You could do this a couple of ways:1) Isolated the low voltage sections from the mains. You've done this with the power supply part by the sound of it, but the direct connection (via the resistive divider) violates it. You'd need to isolate the sensing part of the circuit too.2) Make the whole circuit a "hot chassis" design. This means everything is at mains potential and potentially lethal if touched. This option is only viable if there are no direct connections to the outside and the circuit can't be touched whilst in operation. If you just need some contact outputs, using correctly rated relays and clearances can give you the isolation required.You can't just decide to reference the mains neutral (or active for that matter) to the circuit's ground for conveniences sake. It has real and potentially dangerous consequences.

author: Psi
author_rank: Super Contributor
timestamp: September 09, 2012, 02:17:37 am
content: Maybe something like this?The ADC isn't really designed for such high impedance, but 50hz is pretty slow so i think it will work.I'm not sure how much accuracy you will get though.But it still relys on the fact that your device has no external metal parts which might be grounded.Otherwise the voltage will be higher and the zener will clip it.(i'm not 100% sure about this circuit, best not to try it unless you know what your doing or until a few others have had a look at it)LTSpice shows 4.46V at 230VAC and 2.13V at 110VAC

author: gxti
author_rank: Frequent Contributor
timestamp: September 09, 2012, 02:25:54 am
content: The original example looks pretty typical to me and is perfectly suitable. In my power meter, I used 2 220K resistors for the top half of the divider, and a 1K resistor for the bottom. The values were of course guided by the input requirements of the ADC, MCP3903, which has a +/-1V range. Be mindful of voltage ratings on your resistors though, because 0603 SMD parts have too small a working voltage to be used. 0805 has a typical working voltage of 150V which isn't quite enough for 120V operation (170V peak) but two in series handles it with a large margin. The overload rating of 300V also covers the case where one resistor fails short. For 240V operation you would want a higher-voltage part or more parts in series. Probably any through-hole part will be suitable but check the datasheet.With regards to safety, even just connecting to the neutral wire is enough to have that part of the circuit deemed unsafe to touch. You'll need isolation between there and anything "safe", but if the only interface to the outside world is relays then that could be adequate depending on the relay. Note that safety concerns and functional concerns are separate matters. Two resistors in series, TVS diodes, etc all protect your circuit from blowing up and putting 230V on your microcontroller but aren't good enough to protect the human touching the computer it's plugged into. You need transformers, relays, optoisolators, etc. to provide that safety isolation. But the safety isolation is just there for safety, so it need not be designed to save the "mains" side of circuit from self-destructing. For example, if your route to the outside world is a serial line, your optoisolator could just be on that serial line, simplifying the rest of the circuit considerably. That's what I did for the first revision of my power meter, but on the second revision I'm going to put the isolator between the ADC and the rest of the system to keep the "mains" part as small as possible.

author: Psi
author_rank: Super Contributor
timestamp: September 09, 2012, 02:59:35 am
content: I had another think about it.Trying to detect the entire 230V range with a 10bit adc gives (230*sqrt(2))/1024 = 0.31V per bit.Since the last two bits are really useless most of the time its really 8bitso (230*sqrt(2))/255 = 1.3V per bit.So the resolution is pretty awful at measuring the entire mains range.If instead, you offset the voltage a bit, so the adc internal reference is a little under the 230Vrms peak you should be able to use the ADC in differential mode where one side is the internal reference voltage and the other your signal. Then you set the programming adc gain to like 10.You're then only monitoring a narrow voltage range, say 200-250Vrms.This would improve the resolutionSomething like this, (resistor divider values will need tweaking)Note- The 200k and 50k in series are just so you can have 200K right where you connect to the mains and the 50k on your mcu board. It keeps high current mains away from your pcb, even if a plug is wrong (phase/neutral reversed)325V/200k = 1.6mA, enough to feel but not to kill or start fires.- Trying to do true RMS voltage measurement would be more complicated though, if you wanted that.You would have to extrapolate the missing data.

author: NiHaoMike
author_rank: Super Contributor
timestamp: September 09, 2012, 03:09:25 am
content: I used 3 1/4W, 330k resistors in series with each line for a power meter I designed once. It used a differential amplifier so it can get accurate readings regardless of whether the source is ground referenced or not.

author: paul23
author_rank: Regular Contributor
timestamp: September 09, 2012, 04:47:57 pm
content: Loads to comment on here, thanks.My initial thinking at the minute is to include the provisions for the energy meter as a separate daughter board. Therefore I wanted to include the voltage and current sense parts, then later work on the energy meter part. I have looked through various data sheets and application notes and I am not sure which way I will go, either a dedicated energy meter IC (like Microchip or Cirrus Logic ones) or the Atmel way of using an second AVR and external ADC´s. Whichever way I do it, I want it to be as reliable and safe (i.e. wont catch fire, kill the rest of the circuit, etc) while maintaining reasonable accuracy. I am swaying towards the Atmel way, as then I would learn more using analogue parts, rather than a single chip solution.For the current sense part I think I have settled on using the LEM minisense IC´s as they are non-invasive, which appeals to me.There no external connections, like USB or anything, the only thing is the relays. Although there are touch buttons, but they connect through the plastic casing and there are no external metal parts. So while the lid is on the case, it´s not possible for anybody to touch anything that could be live.Quote from: Psi on September 09, 2012, 02:59:35 amThat is pretty much what the data sheets say as well. Although different chips have slightly different offsets. The microchip ones I think are 500mV, while the Atmel ones are 2.5V. It is also in a Microchip app note on how to do the voltage readings of RMS, it uses some really complicated maths and a bit of educated guess work.I´ll post the link if you are interested.Thanks gxti for your contribution. I was already aware of the voltage ratings of the resistors. It seems 1206 is the smallest you can do really for 230V mains, I think they were 600V the ones I was looking at on DigiKey.

author: vk6zgo
author_rank: Super Contributor
timestamp: September 10, 2012, 04:13:15 am
content: Quote from: paul23 on September 08, 2012, 09:54:11 pmElectrically,it will probably be OK,but your Licencing Authority will probably "have your guts for garters!"if you connect the Neutral line to Earth,which is what your circuit implies.The only connection between Neutral & Earth normally allowed is the one the power inlet to your house,& they are very touchy about unauthorised additional connections.If the "earth" symbol is supposed to indicate "common" & not Mains Earth,that is a different thing,but the whole gadget will probably need to be double insulated, just to be on the safe side.Hanging 1206 surface mount resistors across the mains give me the shivers just to think about--even if theyarerated at 600V!Although OHL switchmode wall warts probably do it ,it is another thing which may well raise the ire of the Authorities.

author: Psi
author_rank: Super Contributor
timestamp: September 10, 2012, 04:39:18 am
content: If you want it truly safe you could use a simple 5V - 5V isolated dc module to power a few discrete components on the mains side and drive an optoisolator LED in relation to mains voltage.That way its completely isolated from the mains.You'd want a linear opto or you'd have to correct for the response in software.You could probably do it a bit cheaper without the 5v DCDC and discretes but you'd need a large wattage resistor as 230V @ 5mA = 1.2W and it would be burning off this energy all the time. (well, varying on each half cycle anyway)You could lower the power loss a bit if you can find a opto that can work at lower led current. After all, the transistor side only needs to provide 0.5mA for the ADC to be within its 10k impedance spec. (ATmegas actually work ok at 100K if you don't need full resolution)Quote from: paul23 on September 09, 2012, 04:47:57 pmJust fyi,I made the mistake once of thinking a LEM current sensor would do the RMS conversion itself and output an analog signal for the RMS AC current but it didn't, it output the raw current waveform.

author: David_AVD
author_rank: Super Contributor
timestamp: September 10, 2012, 06:03:59 am
content: Quote from: vk6zgo on September 10, 2012, 04:13:15 amShorting Earth to Neutral in an appliance is a big no-no and will likely trip the RCD for that circuit.

author: Psi
author_rank: Super Contributor
timestamp: September 10, 2012, 07:31:43 am
content: Yeah, if you have neutral tied to your circuit, even though a resistor, you can't have an earth connection on your pcb. (eg case ground).The board needs to be isolated from the outside world.Not only for RCDs to work but also so that if your device is powered by a incorrectly wired extension cord (P/N reversed) it doesn't make case parts liveAnother solution to your problem is a tiny 230v mains transformer, 0.5-2VA.Just enough to get an isolated AC signal you can measure.

author: paul23
author_rank: Regular Contributor
timestamp: September 10, 2012, 08:03:43 am
content: For clarity, I don´t intend to connect anything to mains Earth. The drawing in my original post is taken straight from an Atmel data sheet, it´s not my drawing and I believe is not recommending connecting to Earth, rather the common ground. I was going to make the earth connecting isolated from everything else, like what you see on most appliance these days.I am going to look in to the transformer and see if it would fit on the PCB. The only thing with that is would it cause any phase error in measurements?

author: Psi
author_rank: Super Contributor
timestamp: September 10, 2012, 08:14:34 am
content: It's not uncommon for appliances to have a floating or high voltage internal ground but normally its done for a good reason.If all the connections from your circuit to the outside world are isolated then there isn't an issue using neutral as your pcb ground.However it's always best to use resistors to limit the current just in case.The reason people are bringing up mains earth is because any external metal object on your device that is part of the circuit must be mains earthed. Most devices need some sort of connection, usb port, serial port, audio jack etc. which is required to be earthed. Most of those connectors are case grounded to your pcb, so that's were you get earth->neutral issues if your circuit ground is neutral. If there are no external connections or they are isolated then there isn't an issue.

author: paul23
author_rank: Regular Contributor
timestamp: September 10, 2012, 04:37:35 pm
content: I think it´s time for a schematic.This is where I am up to. This is work in progress so it´s not the best drawing ever. I´ll tidy it up once I am done.The big connector at the top right (CONN1) connects to the main board that contains all the goodies. The 15v (which is just for reference for me) connects to 7812 first, then the 7805. The GND is common for everything on the other board. SCL and SDA are unused I2C lines. They are used on the other board to control an LED driver, but they are here just in case I need them later. 5V is straight off the 7805, 12V is straight off the 7812. RL1 and RL2 are obviously the relays, they come from the ULN2003A on the other board.CONN2 is the only connection to the outside world. Its fairly obvious really. Live and Neutral are the mains connections in. Load N and Load L are the connections to whatever the relays are controlling. This is what I need to monitor the power usage for. The 2 AUX connections are so far unused, if I have space at the end, then these will go to another small relay, but are not essential.PL1 which should be conn3 will be the connection to the daughter board which houses the energy meter part. All I need for now is 5V, GND, a current measurement and voltage measurement. I think it might be best to make that 2.5V at 250V, because that would work with the Atmels and I could also step it down again for op-amps or whatever later on the other board.The case is all plastic. Probably ABS and there are no metal parts at all, no external connection except the screw terminals for CONN2.Should I put a resistor between the bridge rectifier and the GND connection?Thanks for all the help so far.

author: paul23
author_rank: Regular Contributor
timestamp: September 12, 2012, 11:01:18 pm
content: I´ve been playing with the second circuit that PSI did on LTSPICE. Please note, I am not very good with LTSPICE so I might have done something wrong. When I simulate exactly what was drawn, then I get 2.506V at the second divider (R6, R7), when looks pretty good to me. However, is the idea to get the perfect input voltage, (i.e. 230V in this case) to equal 2.5V or the worse case voltage to 2.5V? What I mean is, the mains will never, or rarely be 230V exactly, it could be higher or lower, in which case it is possible to have a voltage higher the 230V, so the 2.5V would be higher as well. Should I adjust the divider (R6, R7) to get 2,5V at a higher voltage limit, say 250V or is it right the way it is now?I also tried in LTSPICE to swap the Live and Neutral round to see what would happen and nothing does, the circuit works exactly the same. I don´t understand why as there is only a 200K resistor between Live and Ground, so why does the voltage divider still work? I always thought that electricity will follow the path of least resistance? In which case it should flow from live, through the 200K resistor and then to ground, its least resistance than going through another 300K through to the neutral. That might be a really dumb question, but I don´t want to do anything without fully understanding what I am doing.Thanks to anyone who could explain these two things to me.

author: IanB
author_rank: Super Contributor
timestamp: September 13, 2012, 02:11:43 am
content: Quote from: paul23 on September 12, 2012, 11:01:18 pmOf course it does: in AC circuits there is no difference between one conductor or the other. They are completely symmetrical. The voltage difference alternates, first +/-, then -/+. If you swap conductors nothing different should happen.Remember that "ground" does not really exist as a current sink; it is a fiction to simplify circuit diagrams in electronics and a safety device in mains circuits.In earlier posts it was mentioned that "ground" in your low voltage energy monitoring circuit is simply the common reference point. It is not the same as the protective safety ground in the mains supply. If things are organized properly, there should be no current path at all between mains protective ground and the common reference point in your low voltage circuit, therefore no reason at all why current should flow from one to the other.I hope I have understood your question correctly?

author: Psi
author_rank: Super Contributor
timestamp: September 13, 2012, 04:39:47 am
content: Quote from: paul23 on September 12, 2012, 11:01:18 pmThe idea i had with that circuit was to make the worst case 2.5V, so like 250V (this does happen in 240v countries if you live right outside the main 11kV->240V transformer).This way you get a 10bit ADC output from 0-1024 that corresponds to the clipped top of the mains waveform between say..(210*sqrt(2)) and (250*sqrt(2))From there you can work out the peak or (averaged peak), lets say you get a peak of 512 out of 1024 on the ADC.That would mean (512/1024) * (354-297) = 28.5V add on the 297V (210Vrms) that's missing and you get 325V which is 230V (halfway between 210 and 250).Note: This method does have its problems. You're not doing a true RMS voltage measurement so its only 100% accurate on a pure sinewave.You maybe better to sample the entire waveform and do a true RMS calculation then do a running average over say 5 seconds or so. Even taking into account that you get much lower resolution.As IanB pointed out, "Ground" doesn't really exist, it's just a concept. LTSpice just needs a ground so it knows where to take all the measurements from."Earth" however does exist and is connected to Neutral in the fusebox (the fuse box is allowed to make this connection, you're not)Note: There maybe some differences between countries with regard to fuse box wiring of earthIf you think about any electronic device that has external metal parts that are part of the circuit, those by law are earthed.The designer who built the control circuit/PCB inside the appliance chose to make mains earth his 'ground' because it makes his life easy when mounting connectors on the outer case. If it was an audio amp and he used 230V for his ground the metal case of the audio socket would be at 230v.He couldn't do that because the metal parts need to be earthed. So he would have to use an audio isolating transformer for the output signal so he could earth the connector.

author: David_AVD
author_rank: Super Contributor
timestamp: September 13, 2012, 09:27:43 am
content: Quote from: Psi on September 13, 2012, 04:39:47 amThe exception to this are "double insulated" devices. The outer metal on these is not earthed. In fact, there's no earth pin on the mains plug.

author: paul23
author_rank: Regular Contributor
timestamp: September 13, 2012, 09:27:31 pm
content: Thanks for the explanation. I understand fully that Earth and ground are not the same thing, although they can be as you say (Hot chassis). What I meant was that my understanding is the GND, common or whatever else you want to call it is a reference point at a lesser potential then the supply voltage and it is the difference between the two that create the voltage. So in a 5V system there is a difference of 5V between common, GND, whatever and the supply rail. Obviously that changes the other way in a -5V system.The part I couldn´t understand is, assuming that what I wrote above is correct, then in the divider circuit there are effectively 2 voltage sources. There is a 230VAC and a 5VDC. The neutral and common should have the same potential, because the common derives from the neutral via the bridge rectifier. So If I built that circuit up and put a multimeter between neutral and common then it should read 0V? If I measured between live and ground, then I would have 230V, or is this not the case? If its not then that is where I am confused and just don´t get it. If I am right, then I am even more confused, because then the current should flow through the common or GND or whatever as there is less resistance.

author: Psi
author_rank: Super Contributor
timestamp: September 13, 2012, 10:28:02 pm
content: Quote from: paul23 on September 13, 2012, 09:27:31 pmDo you mean the bridge rectifier that might have been outside of my picture and providing the 5V?Perhaps i should have specified, the 5V needs to be an isolated supply.Anytime you start connecting your circuit directly to phase/neutral you need to have all other connections isolated or you get those kind of issues.You either isolate yourself from the mains or you isolate yourself from everything else.Most people opt for the first option because its easier.Since you want to monitor the mains you have to decide which way to go.The easiest would be the first option using a transformer with two separate windings, one to power your circuit and one to measure the voltage which you then multiply up by the transformer ratio. Then you have no direct connection to phase/neutralVery simply, like this (resistor values are probably wrong now)

author: TriodeTiger
author_rank: Regular Contributor
timestamp: September 14, 2012, 01:49:54 am
content: Quote from: paul23 on September 12, 2012, 11:01:18 pmIt does flow through the path of least resistance. But wait, there's more: It also flows through the path of most resistance, and also everything in between (YCMV, Your Current May Vary.)Would strapping a 1kohm 20W resistor between live and earth make you immune to harm touching live?

author: Nirios
author_rank: Regular Contributor
timestamp: September 14, 2012, 04:58:31 am
content: I came across this App note yesterday and though it might be helpful. It is weird that I was looking into the same issue--mains voltage sensing.Its App Note 106 by Jim Williams at Linear Technology. Page 2, figure 3.LINKI think it is the method I am going to use. It makes me feel safer about connecting my circuit to mains.

author: paul23
author_rank: Regular Contributor
timestamp: September 14, 2012, 12:48:16 pm
content: Thanks for the app note, I will take a look through it.Quote from: Psi on September 13, 2012, 10:28:02 pmMy circuit doesn´t look like the one you´ve drawn. See attached image to how I have it set up right now. There is no Earth connection on the PCB. I know the relays are drawn to run all the time, there is a ULN2003a that switches them, I just omitted from the drawing as it is not relevant. I have also missed off the diodes across the coils. I also realise I have missed the Zener off too, I have that exactly like you do on your circuit.Is this wrong?

author: David_AVD
author_rank: Super Contributor
timestamp: September 14, 2012, 09:15:01 pm
content: What's the ultimate goal of the circuit?Are you just measuring the voltage across the switched load?

author: paul23
author_rank: Regular Contributor
timestamp: September 14, 2012, 09:54:12 pm
content: For this circuit yes just voltage across the switch load. However, the the ultimate goal (there´s a schematic previously in this thread) is to get the consumed power from the switched load. All I want at the minute is provisions in place to be able to do it on a separate board later. I know how to do the current measurement. I just don´t understand the voltage measurement.

author: David_AVD
author_rank: Super Contributor
timestamp: September 15, 2012, 01:17:24 am
content: The voltage measurement can most likely be done using the existing power transformer. Current measurement is the tricky one for isolation.

author: IanB
author_rank: Super Contributor
timestamp: September 15, 2012, 02:35:07 am
content: Quote from: David_AVD on September 15, 2012, 01:17:24 amCurrent transformer?

author: David_AVD
author_rank: Super Contributor
timestamp: September 15, 2012, 03:24:21 am
content: Quote from: IanB on September 15, 2012, 02:35:07 amYeah, but I thought he didn't want another transformer?I reckon a rethink of the project's aims and constraints is in order.

author: paul23
author_rank: Regular Contributor
timestamp: September 15, 2012, 07:47:33 am
content: Current is OK I know how to do it. The only thing I am stuck with is why the voltage divider works and why there is not mains potential between R3/R4 and R6 on my last schematic.The divider works great in LTSpice, I just don´t know why.

author: IanB
author_rank: Super Contributor
timestamp: September 15, 2012, 01:28:14 pm
content: Quote from: paul23 on September 15, 2012, 07:47:33 amWhat is it you are stuck on?In your circuit the full mains voltage (230 V ?) appears across the load, and therefore across the R1/R2/R3/R4 divider chain. So the voltage across R3 is:V(R3) = R3 / (R1 + R2 + R3 + R4) x 230This AC voltage is transferred through C1 and is impressed across R6.R6 already has a DC voltage across it equal to:V(R6) = R6 / (R5 + R6) x 5This DC voltage acts like a bias. Hence the total voltage across R6 is a DC offset voltage with an AC voltage varying around the DC bias point. As long as the magnitude of the AC part is less than the DC bias part the total voltage will remain in range and everything should be OK. This depends on the actual resistor values used.

author: paul23
author_rank: Regular Contributor
timestamp: September 15, 2012, 03:24:04 pm
content: The bit I don´t understand is if the mains wires are switched, so Live is where Neutral is now, then what happens at R3/R4 and R6? In LTspice it shows it doesn´t make any difference no matter which way you put live and neutral.I get that ac votage is is fluctuating + and -, I get that neutral is effectively 0V in reference to Earth. I can´t get my head around why there isn´t high voltage at R6 and why all the components don´t fry, because the common should now be at mains potential.Quote from: IanB on September 15, 2012, 01:28:14 pmDo you mean that (assuming the DC is 5V) as long as the AC is between 0-5V peak to peak, then everything is fine, but if it exceeds that, then there are issues? I think it is set at the minute to 1.25 - 2.5V for the full range.

author: IanB
author_rank: Super Contributor
timestamp: September 15, 2012, 05:30:54 pm
content: Quote from: paul23 on September 15, 2012, 03:24:04 pmBut you have to think about current paths. Your low voltage ground at the foot of R6 is isolated from the mains on the other side of TR1. There is no way for current from the mains supply to flow to or from that point. Unless you (unwisely) were to connect your low voltage ground to the mains protective earth (don't do that), there is no circuit.Try a thought experiment. If you were to stand on an insulated platform and measure the mains "live" and mains "neutral" with a meter you would find there is no difference between them. You could swap them round and they would look just the same (not entirely true, but close enough). In your circuit, transformer TR1 is that insulated platform. The low voltage circuit can see no difference between live and neutral. Both wires look the same.QuoteYes, that is what I mean.

author: paul23
author_rank: Regular Contributor
timestamp: September 15, 2012, 06:12:08 pm
content: The penny has dropped, many thanks I totally get it now.