Author Topic: Mains earth and MCUs ?!  (Read 8913 times)

0 Members and 1 Guest are viewing this topic.

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Mains earth and MCUs ?!
« on: February 13, 2012, 02:43:29 pm »
Hi guys

I've designed and build an adjustable dummy load, kind of what Dave showed in one of the blogs..
I use some other components, and included a PIC16F877a and a 16x2 lcd, for measurement.

I found that when the circuit is powered form a non-earthed power supply, the digital part doesn't work, and sometimes erases the microcontroller (all the voltages looks fine?!). But when powered from a 9v battery, or an earthed supply, it works fine.
I have no idea why!

I've tried both a standard 9v adapter, and my adjustable power supply, neither works.
We don't have earthed wall outlets! But I tried burying a pipe in the garden, with a wire going to the negative terminal on my power supply, and it worked fine :o .. ( yea, i actually did that, was desperate  ;) )

I'm not sure how the DC relates to the mains earth, when it's been through a transformer, and been rectified ? 

Can anyone explain why this is happening ? And how to avoid the problem, so I CAN use a non-earthed power source ? :)
I'm sure it's just a basic thing I don't know about :P I'm still a beginner in electronics :)
I did add caps at the Vdd/Vss of the micro, at the power input, and after the 5v regulator.

I get the same problem with almost any MCUprojects, I tried breadboarding a few afterwards.

Do anybody have the same problem ?
More info available, if needed ;)
 
-Mads

 


Offline tinhead

  • Super Contributor
  • ***
  • Posts: 1918
  • Country: 00
    • If you like my hacks, send me a donation
Re: Mains earth and MCUs ?!
« Reply #1 on: February 13, 2012, 02:58:49 pm »
C7 is too small
I don't want to be human! I want to see gamma rays, I want to hear X-rays, and I want to smell dark matter ...
I want to reach out with something other than these prehensile paws and feel the solar wind of a supernova flowing over me.
 

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #2 on: February 13, 2012, 03:15:47 pm »
Hmm, C7 ?
Sorry ;)

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: Mains earth and MCUs ?!
« Reply #3 on: February 13, 2012, 03:49:58 pm »
Based on the enormous, detailed information your provided I would say your power supply is junk.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Mains earth and MCUs ?!
« Reply #4 on: February 13, 2012, 04:09:06 pm »
I think people are trying to say: POST A SCHEMATIC !!!
 

Online ejeffrey

  • Super Contributor
  • ***
  • Posts: 3713
  • Country: us
Re: Mains earth and MCUs ?!
« Reply #5 on: February 13, 2012, 04:23:27 pm »
You forgot to connect both wires properly, and are allowing return current to flow through the mains earth.
 

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #6 on: February 13, 2012, 06:07:38 pm »
Here is the schematic..

I don't think my supply is junk, the output is nice and clean at least.. :P

Hmm, I did connect all wires :)

I'm connecting my PSU + to "9v" (on schematic) and gnd to "gnd", and i'm connecting the positive of the PSU i want to test to "test psu" and connect both gnd together ?!

it makes no difference if I connect the test PSU or not..

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #7 on: February 13, 2012, 06:10:56 pm »
Vdd and Vss on the PIC are connected ofc ;) (Doesn't show up on the schematic)
with one of the 10u caps next to it..
And there is a 4mhz Crystal on as well..
« Last Edit: February 13, 2012, 06:14:16 pm by Madsaaby »
 

Offline Short Circuit

  • Frequent Contributor
  • **
  • Posts: 439
  • Country: nl
Re: Mains earth and MCUs ?!
« Reply #8 on: February 13, 2012, 06:17:29 pm »
Add 10-100nF decoupling caps to the semiconductors.
And maybe the MCLR needs a small cap to ground? (not familiar with PIC, but since that pin says 'Vpp' and you mention the thing being erased...)
Where does the power ground connect to? You'd want this close to C3/U1.
 

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #9 on: February 13, 2012, 06:52:24 pm »
Here is the layout as well, gnd is highlighted.. You can't see the caps, I soldered them directly to the pins of the devices :/
The opamp, fet and lcd is the only devices that doesn't have caps..
The power gnd is connected in the bottom left.. not that close to U1 :(

the decoupling caps, are just from + to gnd, right next to the device ? Just to make sure I got it right ;)
« Last Edit: February 13, 2012, 06:57:44 pm by Madsaaby »
 

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #10 on: February 13, 2012, 08:38:40 pm »
@BoredAtWork, i think you are right actually.. I checked the supply again on my old crappy scope, it seems like there is ac spikes of several hundred mV at 500khz, and slightly larger at 50khz. But I wasn't able to see it below 300mA load. since they get wider as the load increases..

My bad :S Should have checked that the first time -.-

I don't have any other supply laying around unfortunately.. Hopefully I can try it with another supply tomorrow..

But it still doesn't work with any cheap AC - DC adaptors I have laying around either. Hmmm..
   

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 794
  • Country: au
    • AXT Systems
Re: Mains earth and MCUs ?!
« Reply #11 on: February 13, 2012, 09:54:18 pm »
Increase the size of C3 to about 100uF or so. Add protection diodes arounf the regulator. Just use a 10K pullup on pin 1, instead of the diode/resistor combination you have there.
What Vref are you using? The 5V supply rail? It won't be good enough for measuring the voltage across the sense resistor with any degree of accuracy.
Was it really supposed to do that?
 

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #12 on: February 13, 2012, 10:17:50 pm »
@DrGeoff, thanks for the tips :D I was afraid the 13v when programming could do bad things. But ofc the current would be used, and the voltage wouldn't rise, didn't think of that ;) .
I am just using the 7805 as Vref, I know its not accurate at all. :(
Didn't have anything better around..

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: Mains earth and MCUs ?!
« Reply #13 on: February 14, 2012, 08:22:43 am »
what does C2 on the dummy load's driver (tlv271) can help? try to remove the lcd completely and see if the mcu is working, if not then... your psu is a crap.
or try (maybe you missed?) disabling brownout in mcu, disable mclr functionality check fuses and registers etc in software.

edit: why you have C1 and C4 (both same 10uF) in parallel, to get 20uF effective cap?

below is also my recently built constant current loader as well, using 741 (non rail2rail like your tlv271), hence i needed to work on biasing to make it work at 0-3A. unregulated 12V A23 type battery as Vref and biasing. i analyzed the effect of unstable Vsupply at several value (10V 8V etc), all bias and setting seems to follow in harmony (ie setting to load at 1A at 12V supply will also give the same 1A if battery degraded to 10V), so not quite an issue at least for my "not so miu/micro" constant loader ;)

edit: sorry i just noticed, led is not to "sense" but directly upstream of RL, hence not through the 12Kohm. gotta ammend this afterward. ammended, both in software and hardware.
« Last Edit: February 15, 2012, 02:31:57 am by Mechatrommer »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8264
Re: Mains earth and MCUs ?!
« Reply #14 on: February 14, 2012, 12:09:49 pm »
But I tried burying a pipe in the garden, with a wire going to the negative terminal on my power supply, and it worked fine :o .. ( yea, i actually did that, was desperate  ;) )
How long were the wires on the power supplies you used, that didn't work, and how long were the wires to the 9V battery that did work? The fact that grounding the circuit makes it work suggests they might be acting as antennae and picking up EMI.
 

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #15 on: February 14, 2012, 12:30:33 pm »
what does C2 on the dummy load's driver (tlv271) can help? try to remove the lcd completely and see if the mcu is working, if not then... your psu is a crap.
or try (maybe you missed?) disabling brownout in mcu, disable mclr functionality check fuses and registers etc in software.

edit: why you have C1 and C4 (both same 10uF) in parallel, to get 20uF effective cap?

below is also my recently built constant current loader as well, using 741 (non rail2rail like your tlv271), hence i needed to work on biasing to make it work at 0-3A. unregulated 12V A23 type battery as Vref and biasing. i analyzed the effect of unstable Vsupply at several value (10V 8V etc), all bias and setting seems to follow in harmony (ie setting to load at 1A at 12V supply will also give the same 1A if battery degraded to 10V), so not quite an issue at least for my "not so miu/micro" constant loader ;)

edit: sorry i just noticed, led is not to "sense" but directly upstream of RL, hence not through the 12Kohm. gotta ammend this afterward. ammended, both in software and hardware.


If i remove C2, I am getting a nice sinewave at the sense-point going from 0v to 2x the set voltage :/ Adding C2 averages it out, and makes it completely clean..

I did add C4 later on, directly at the mcu Vdd/Vss.. (don't know if its needed).

The load is working fine all the time, no matter what input source I use. It's just the mcu that doesn't :)

Brownout might be enabled. As I mentioned I'm still a beginner ;) Didn't knew about the brownout, but googled it :P Could be an issue :D

I'll check that.. :)

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #16 on: February 14, 2012, 12:33:22 pm »
But I tried burying a pipe in the garden, with a wire going to the negative terminal on my power supply, and it worked fine :o .. ( yea, i actually did that, was desperate  ;) )
How long were the wires on the power supplies you used, that didn't work, and how long were the wires to the 9V battery that did work? The fact that grounding the circuit makes it work suggests they might be acting as antennae and picking up EMI.

I used the same wires, about 30 cm..

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1668
  • Country: us
Re: Mains earth and MCUs ?!
« Reply #17 on: February 14, 2012, 09:34:35 pm »
below is also my recently built constant current loader as well, using 741 (non rail2rail like your tlv271), hence i needed to work on biasing to make it work at 0-3A. unregulated 12V A23 type battery as Vref and biasing. i analyzed the effect of unstable Vsupply at several value (10V 8V etc), all bias and setting seems to follow in harmony (ie setting to load at 1A at 12V supply will also give the same 1A if battery degraded to 10V), so not quite an issue at least for my "not so miu/micro" constant loader ;)

How are you calculating the values of Vsense? Particularly, at 0A through RL your diagram has Vsense = 2.98v at Vs=12v. How?
Complexity is the number-one enemy of high-quality code.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: Mains earth and MCUs ?!
« Reply #18 on: February 15, 2012, 02:25:58 am »
How are you calculating the values of Vsense? Particularly, at 0A through RL your diagram has Vsense = 2.98v at Vs=12v. How?
FWIW, at 0A, Vrl = gnd = 0V, using Ra = 33Kohm and Rb = 12Kohm as voltage divider between Vs and Vrl, using simple algebra...
(Vs - Vsense) / Ra = (Vsense - Vrl) / Rb ... (meaning Ia = Ib) you can work out that Vsense is 2.98 errr... 3.2V. sorry i havent noticed that footnote was calculated using different resistors divider value tested earlier, thanks for highlighting (drawing/attachment updated). but thats the idea... FWIW attached is my excel spreadsheet used to see the swinging Vs effect. mainly to solve the 2V min (non rail2rail) 741 output, which resulted in "always ON" fet and minimum 2A limit! using the bias solved that, accurate/usable to some degree. i only noticed max amperage limit will get lowered as battery Vs degraded, but dont care too much as high amperage will blow the fet or shunt resistor anyway in this simple one-off. YMMV.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #19 on: February 15, 2012, 02:40:42 pm »
Thanks a lot for the help guys :)

Finally got it working.. First of all my PSU was garbage, like many of you mentioned..
By disabling the Brown-out reset bit, and adding the 100 uF cap I got it to work with the standard 9v adaptor.
I did a Rev B of the board with all the changes you posted, and it works pretty good.. :)

Cheers!

-Mads

Offline Mint.

  • Frequent Contributor
  • **
  • Posts: 523
  • Country: au
  • Account is inactive now. Thanks everybody!
    • Personal Blog, Mint Electronics.
Re: Mains earth and MCUs ?!
« Reply #20 on: February 17, 2012, 09:23:18 am »
Thanks a lot for the help guys :)

Finally got it working.. First of all my PSU was garbage, like many of you mentioned..
By disabling the Brown-out reset bit, and adding the 100 uF cap I got it to work with the standard 9v adaptor.
I did a Rev B of the board with all the changes you posted, and it works pretty good.. :)

Cheers!

-Mads

Please forgive me for asking such a stupid question, but since this is in beginners section and I am one myself, I would like to ask you a question. Don't you think it's wasteful not only money wise, but space wise using that PIC16 chip and only taking advantage of 5 pins and leaving the rest not used. I am only a beginner and have no yet gotten up to such complex chips, so correct me if I am wrong.
Personal Blog (Not Active Anymore), Mint Electronics:
http://mintelectronics.wordpress.com/
 

Offline MadsaabyTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: dk
  • Beware ! MCUs will take over the world!
    • Ec-Projects
Re: Mains earth and MCUs ?!
« Reply #21 on: February 17, 2012, 01:33:32 pm »

Please forgive me for asking such a stupid question, but since this is in beginners section and I am one myself, I would like to ask you a question. Don't you think it's wasteful not only money wise, but space wise using that PIC16 chip and only taking advantage of 5 pins and leaving the rest not used. I am only a beginner and have no yet gotten up to such complex chips, so correct me if I am wrong.

You are absolutely right ;)
I used the 16F877a because I have a whole bunch of them just laying there, and I didn't really care about space efficiency, since its only for my personal use :) .. In case buying a chip for this purpose, I would of course go with something cheaper like the PIC16F1507, which furthermore has an internal clock :)
There might be more appropriate chips out there, but I just remember the 16F1507 :D
The only limitations for this project was the 10 bit ADC, so there are many many suitable chips out there.. :D 

Edit: Just realizing it says PIC16F887 on the layout img.. Did actually use the 16F877a, doesn't make it any cheaper though ;)
« Last Edit: February 17, 2012, 01:42:14 pm by Madsaaby »
 

Offline Mint.

  • Frequent Contributor
  • **
  • Posts: 523
  • Country: au
  • Account is inactive now. Thanks everybody!
    • Personal Blog, Mint Electronics.
Re: Mains earth and MCUs ?!
« Reply #22 on: February 18, 2012, 12:39:46 am »

Please forgive me for asking such a stupid question, but since this is in beginners section and I am one myself, I would like to ask you a question. Don't you think it's wasteful not only money wise, but space wise using that PIC16 chip and only taking advantage of 5 pins and leaving the rest not used. I am only a beginner and have no yet gotten up to such complex chips, so correct me if I am wrong.

You are absolutely right ;)
I used the 16F877a because I have a whole bunch of them just laying there, and I didn't really care about space efficiency, since its only for my personal use :) .. In case buying a chip for this purpose, I would of course go with something cheaper like the PIC16F1507, which furthermore has an internal clock :)
There might be more appropriate chips out there, but I just remember the 16F1507 :D
The only limitations for this project was the 10 bit ADC, so there are many many suitable chips out there.. :D 

Edit: Just realizing it says PIC16F887 on the layout img.. Did actually use the 16F877a, doesn't make it any cheaper though ;)

Fair enough. Its a good feeling when you use something that has just been lying around taking up space in your projects, you know that it won't be useless anymore :)
Personal Blog (Not Active Anymore), Mint Electronics:
http://mintelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf