Problem reading multiple mains voltages with microcontroller. - Page 1
Forum section: electronics / projects

author: microherb
author_rank: Contributor
timestamp: May 13, 2019, 11:31:32 pm
content: Hi,I'm having some difficulties with a circuit to measure more than one mains voltage inputs.Attached is a simplified circuit diagram of what I am trying to achieve.There is a fly-back switch mode power supply to generate the 5V for the micro-controller and power other parts of the circuit (not shown).The incoming mains voltage is divided down with resistive divider and passed through RC filter, buffered and input to ADC of micro-controller to read an average AC mains voltage, this section of the circuitry works fine.The lower part of the circuit is to read a variable AC mains control voltage. The voltage is divided down and passed through RC filter, buffered and input to micro-controller as above. There is something going on that I can't get my head around just yet which I believe is related to the single ground point for the 2 rectified inputs. When observing output of the second bridge rectifier only one half cycle is varying as the the variac is turned, the other half cycle is always maximum (see scope screen shot attached).Any advice on how to correct problem with current circuit or alternative circuit much appreciated.Dean.

author: Marco
author_rank: Super Contributor
timestamp: May 14, 2019, 01:47:22 am
content: A bridge rectifier is not a galvanic isolation, you can't just connect circuit ground to the two neg outputs like that.Use halfwave rectification instead.

author: microherb
author_rank: Contributor
timestamp: May 14, 2019, 01:59:48 am
content: Thanks Marco,I realise there is no galvanic isolation through the bridge rectifier, I tried just half wave rectified on the 2nd read channel with similar result. I need full wave rectified from the main 240VAC for the fly-back power supply.I thought there would be a simple way to do this, I don't want to use transformer due to size and cost, similar for isolation amplifier. I'm tossing around ideas using differential amplifier or maybe current mirror.

author: Chriss
author_rank: Frequent Contributor
timestamp: May 14, 2019, 05:40:56 am
content: Hi!From several my projects where I dealed with mains I learned a really good stuff.Always separate galvanic the two circuits.I had so many problems before I decided to put a transformer,the worst case scenario was when I missed and used a ground where I shouldn't have.The magic smoke will be your best friend trust me.However, I would separate the two part completely from each other.1. The power source for the other parts2. The measurement lines3. Separate galvanic the measurement linesHow much current will use the other- not mentioned part?Maybe you can put a small size and low power transformer for the measuring line and to power the uC stuff.For the load you can use an smps in your design.Sent from my SM-J500F using Tapatalk

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: May 14, 2019, 07:18:52 am
content: There is no need for the bridge rectifier to make the signal DC!you can add some DC bias to the scaled signal to scale it to the 0-3.3V ADC range of the micro.

author: Richard Crowley
author_rank: Super Contributor
timestamp: May 14, 2019, 09:30:35 am
content: Nothing but a transformer will safely isolate you from the mains. Otherwise, you are playing with fire, quite literally. It doesn't have to be a very big transformer. I use the little transformers recycled out of old LINEAR wall-warts. This is when it pays to have a well-stocked junk box.

author: StillTrying
author_rank: Super Contributor
timestamp: May 14, 2019, 10:57:07 am
content: Quote from: microherb on May 14, 2019, 01:59:48 amI hope you know your GNDs and everything else are at a lethal -330V.

author: Marco
author_rank: Super Contributor
timestamp: May 14, 2019, 01:51:08 pm
content: Quote from: microherb on May 14, 2019, 01:59:48 amReally? Can't you just use a larger input capacitor?Any way, the flyback power supply is galvanically isolated ... so you can just use an extra halfwave rectifier for the measurement only. Use the bridge for the fly-back only, but connect the low side of the flyback secondary to "Neutral" (it will need a galvanically isolated feedback to the primary side, but flyback power supplies usually already have that). Use two halfwave rectifiers for the measurements. The circuit will be floating on one of the power connections of course and you should never trust Neutral to be neutral.

author: Psi
author_rank: Super Contributor
timestamp: May 14, 2019, 02:10:00 pm
content: Yes, as others have said your project needing to have an isolated mains connection.That's the first thing to fixFor taking the HV measurement on the MCU why not use a opto-isolator?I'm guessing you don't need to measure the mains voltage down to more than say +/- 1V ACAn optoisolator should be able to do that just fine and you get isolation which makes things super easy.Especially if you want to read multiple mains sources with a single MCUYou can correct for some of the non-linearity with a lookup table if needed.Or get an opto-isolatior designed to have a linear response.

author: Marco
author_rank: Super Contributor
timestamp: May 14, 2019, 02:45:03 pm
content: There's a time and place for circuits which float on the mains, not everything needs to be isolated. Just need to be careful.

author: Psi
author_rank: Super Contributor
timestamp: May 14, 2019, 02:49:26 pm
content: Quote from: Marco on May 14, 2019, 02:45:03 pmEverything should be isolated unless there is a valid reason to not isolate it.

author: Kjelt
author_rank: Super Contributor
timestamp: May 14, 2019, 02:55:50 pm
content: Quote from: Marco on May 14, 2019, 02:45:03 pmExactly it all depends on the requirements.Many devices are operated at non isolated mains even with non isolated power supplies since there are now many AC-DC converters like ST Viper+ or the sort that convert mains rectified voltage directly to low DC voltage, it does not require any transformer. No transformer saves space and money.If for instance the only requirement is that a single serial or differential communication line to the outside has to be isolated than it might be cheaper to isolate that single communication channel than to isolate the mains.But again it all depends on the requirements.

author: microherb
author_rank: Contributor
timestamp: May 14, 2019, 09:46:27 pm
content: Quote from: Marco on May 14, 2019, 02:45:03 pmThanks Marco,The product is a LED lantern, everything is enclosed in a double insulated enclosure so there is no real safety requirement for isolation that I know of. I am aware of the dangers of working on non-isolated circuits.

author: microherb
author_rank: Contributor
timestamp: May 14, 2019, 09:51:12 pm
content: Quote from: Psi on May 14, 2019, 02:10:00 pmThanks,So I had a look at some linear optoisolators, something like the HCNR201. My concern is there is a +/- 5% variation in transfer gain? (About $6AUD in 100 quantities too but at least it's smaller than a transformer).

author: microherb
author_rank: Contributor
timestamp: May 14, 2019, 10:20:47 pm
content: Quote from: Marco on May 14, 2019, 01:51:08 pmThere is a requirement for high power factor and low THD so I can't really just half wave rectify. Switcher is HVLED815.QuoteInteresting, just to confirm, is the attached simplified circuit diagram as you have described above?Traditionally, there is a capacitor across the low side of the flyback transformer to the switcher ground (Bridge neg) for EMC. I take it that is still OK with the low side of the output now tied to neutral?Thanks again.

author: schmitt trigger
author_rank: Super Contributor
timestamp: May 14, 2019, 10:40:23 pm
content: I second what Richard Crowley mentions in his previous post.A small transformer is your best friend.Edit; In your schematic above this post, the NEUTRAL line will see 330 Vpk from the bridge rectifier’s negative terminal GND.

author: microherb
author_rank: Contributor
timestamp: May 14, 2019, 10:48:08 pm
content: Quote from: Richard Crowley on May 14, 2019, 09:30:35 amThanks, yes transformer is good for isolation, smallest one seems to be about 1VA, footprint is a bit large for the application, it's a production design not a one off so I would need to find something available for purchase at a reasonable price.

author: Marco
author_rank: Super Contributor
timestamp: May 15, 2019, 12:10:12 am
content: Quote from: microherb on May 14, 2019, 10:20:47 pmSure, the direct connection to neutral is going to win over anything the capacitor can do.

author: Richard Crowley
author_rank: Super Contributor
timestamp: May 15, 2019, 01:46:51 am
content: There are opto-isolators used for voltage feedback on SMPS circuits.With that kind of device, surely you could devise a circuit that would sample a calibrated fraction of the mains voltage.For example:

author: microherb
author_rank: Contributor
timestamp: May 15, 2019, 03:38:09 am
content: Quote from: Richard Crowley on May 15, 2019, 01:46:51 amThanks Richard, do you have a source for the device in that document?

author: oPossum
author_rank: Super Contributor
timestamp: May 15, 2019, 03:48:32 am
content: https://www.broadcom.com/products/optocouplers/industrial-plastic/specific-function/high-linearity-analog/hcnr201

author: Richard Crowley
author_rank: Super Contributor
timestamp: May 15, 2019, 05:41:39 am
content: https://www.digikey.com/en/articles/techzone/2012/dec/linear-optical-isolation-for-safe-sensor-operation

author: StillTrying
author_rank: Super Contributor
timestamp: May 16, 2019, 01:17:55 pm
content: The safest way to probe all the live bridge and other waveforms up to the ADC inputs is in a simulation.

author: Marco
author_rank: Super Contributor
timestamp: May 16, 2019, 03:10:02 pm
content: I should add that the halfbridge approach only works when the "variac" is connected as shown, if it's actually a triac dimmer but you have no idea which connection it is cutting it won't.

author: jbb
author_rank: Super Contributor
timestamp: May 16, 2019, 07:27:04 pm
content: I think a differential amplifier might be the way to go here.A linear optocoupler requires special measures to handle AC (and may then be prone to DC offsets) and requires isolated power.A 50 (60?) Hz transformer is quite bulky and my have a distorted output. It may also add unwanted loading to whatever you’re measuring.Please be careful when developing this circuit, it’s so easy to forget and stick your fingers on something dangerous. Also have a very thorough look at the enclosure for the final item - if someone damaged it (eg drops it or drops something on it) could some part break and allow a person to touch an electrical connection?

author: Zero999
author_rank: Super Contributor
timestamp: May 17, 2019, 12:48:16 pm
content: If size is an issue, then how about a differential amplifier and AC couple the mains signal, with Y rated capacitors?