Author Topic: Problem reading multiple mains voltages with microcontroller.  (Read 4833 times)

0 Members and 1 Guest are viewing this topic.

Offline microherbTopic starter

  • Contributor
  • Posts: 28
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.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 7043
  • Country: nl
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #1 on: May 14, 2019, 01:47:22 am »
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.
 

Offline microherbTopic starter

  • Contributor
  • Posts: 28
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #2 on: May 14, 2019, 01:59:48 am »
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.
 

Offline Chriss

  • Frequent Contributor
  • **
  • Posts: 534
  • Country: 00
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #3 on: May 14, 2019, 05:40:56 am »
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 parts
2. The measurement lines
3. Separate galvanic the measurement lines

How 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

« Last Edit: May 14, 2019, 10:41:44 am by Chriss »
 

Offline ali_asadzadeh

  • Super Contributor
  • ***
  • Posts: 1967
  • Country: ca
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #4 on: May 14, 2019, 07:18:52 am »
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.
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4321
  • Country: us
  • KJ7YLK
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #5 on: May 14, 2019, 09:30:35 am »
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.

 
The following users thanked this post: Someone, Chriss

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #6 on: May 14, 2019, 10:57:07 am »
I realise there is no galvanic isolation through the bridge rectifier,...
I don't want to use transformer due to size and cost

I hope you know your GNDs and everything else are at a lethal -330V.
.  That took much longer than I thought it would.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 7043
  • Country: nl
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #7 on: May 14, 2019, 01:51:08 pm »
I need full wave rectified from the main 240VAC for the fly-back power supply.

Really? 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.
« Last Edit: May 14, 2019, 01:56:09 pm by Marco »
 
The following users thanked this post: microherb

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10385
  • Country: nz
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #8 on: May 14, 2019, 02:10:00 pm »
Yes, as others have said your project needing to have an isolated mains connection.
That's the first thing to fix

For 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 AC

An 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 MCU

You 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.



« Last Edit: May 14, 2019, 02:14:14 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 7043
  • Country: nl
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #9 on: May 14, 2019, 02:45:03 pm »
There's a time and place for circuits which float on the mains, not everything needs to be isolated. Just need to be careful.
 
The following users thanked this post: Kjelt

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10385
  • Country: nz
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #10 on: May 14, 2019, 02:49:26 pm »
There's a time and place for circuits which float on the mains, not everything needs to be isolated. Just need to be careful.

Everything should be isolated unless there is a valid reason to not isolate it.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6586
  • Country: nl
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #11 on: May 14, 2019, 02:55:50 pm »
There's a time and place for circuits which float on the mains, not everything needs to be isolated. Just need to be careful.
Exactly 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.
« Last Edit: May 14, 2019, 03:01:32 pm by Kjelt »
 
The following users thanked this post: microherb

Offline microherbTopic starter

  • Contributor
  • Posts: 28
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #12 on: May 14, 2019, 09:46:27 pm »
There's a time and place for circuits which float on the mains, not everything needs to be isolated. Just need to be careful.
Thanks 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.
 
 

Offline microherbTopic starter

  • Contributor
  • Posts: 28
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #13 on: May 14, 2019, 09:51:12 pm »
Yes, as others have said your project needing to have an isolated mains connection.
That's the first thing to fix

For 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 AC

An 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 MCU

You 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.
Thanks,
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).
 

Offline microherbTopic starter

  • Contributor
  • Posts: 28
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #14 on: May 14, 2019, 10:20:47 pm »
I need full wave rectified from the main 240VAC for the fly-back power supply.

Really? Can't you just use a larger input capacitor?
There is a requirement for high power factor and low THD so I can't really just half wave rectify.  Switcher is HVLED815.

Quote
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.

Interesting, 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.
 

Offline schmitt trigger

  • Super Contributor
  • ***
  • Posts: 2431
  • Country: mx
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #15 on: May 14, 2019, 10:40:23 pm »
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.
« Last Edit: May 14, 2019, 10:44:32 pm by schmitt trigger »
 

Offline microherbTopic starter

  • Contributor
  • Posts: 28
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #16 on: May 14, 2019, 10:48:08 pm »
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.



Thanks, 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.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 7043
  • Country: nl
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #17 on: May 15, 2019, 12:10:12 am »
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?

Sure, the direct connection to neutral is going to win over anything the capacitor can do.
 
The following users thanked this post: Someone

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4321
  • Country: us
  • KJ7YLK
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #18 on: May 15, 2019, 01:46:51 am »
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: 

 
The following users thanked this post: microherb

Offline microherbTopic starter

  • Contributor
  • Posts: 28
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #19 on: May 15, 2019, 03:38:09 am »
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: 



Thanks Richard, do you have a source for the device in that document?
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1472
  • Country: us
  • Very dangerous - may attack at any time
 
The following users thanked this post: DeanA

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4321
  • Country: us
  • KJ7YLK
 
The following users thanked this post: oPossum, DeanA

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #22 on: May 16, 2019, 01:17:55 pm »
The safest way to probe all the live bridge and other waveforms up to the ADC inputs is in a simulation. :)
.  That took much longer than I thought it would.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 7043
  • Country: nl
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #23 on: May 16, 2019, 03:10:02 pm »
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.
« Last Edit: May 16, 2019, 03:16:23 pm by Marco »
 

Offline jbb

  • Super Contributor
  • ***
  • Posts: 1265
  • Country: nz
Re: Problem reading multiple mains voltages with microcontroller.
« Reply #24 on: May 16, 2019, 07:27:04 pm »
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?
 
The following users thanked this post: microherb


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf