Mains earth and MCUs ?! - Page 1
Forum section: electronics / beginners

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 13, 2012, 02:43:29 pm
content: Hi guysI'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.. ( 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 aboutI'm still a beginner in electronicsI 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

author: tinhead
author_rank: Super Contributor
timestamp: February 13, 2012, 02:58:49 pm
content: C7 is too small

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 13, 2012, 03:15:47 pm
content: Hmm, C7 ?Sorry

author: Bored@Work
author_rank: Super Contributor
timestamp: February 13, 2012, 03:49:58 pm
content: Based on the enormous, detailed information your provided I would say your power supply is junk.

author: Simon
author_rank: Unknown
timestamp: February 13, 2012, 04:09:06 pm
content: I think people are trying to say: POST A SCHEMATIC !!!

author: ejeffrey
author_rank: Super Contributor
timestamp: February 13, 2012, 04:23:27 pm
content: You forgot to connect both wires properly, and are allowing return current to flow through the mains earth.

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 13, 2012, 06:07:38 pm
content: Here is the schematic..I don't think my supply is junk, the output is nice and clean at least..Hmm, I did connect all wiresI'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..

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 13, 2012, 06:10:56 pm
content: 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..

author: Short Circuit
author_rank: Frequent Contributor
timestamp: February 13, 2012, 06:17:29 pm
content: 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.

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 13, 2012, 06:52:24 pm
content: 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 U1the decoupling caps, are just from + to gnd, right next to the device ? Just to make sure I got it right

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 13, 2012, 08:38:40 pm
content: @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..

author: DrGeoff
author_rank: Frequent Contributor
timestamp: February 13, 2012, 09:54:18 pm
content: 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.

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 13, 2012, 10:17:50 pm
content: @DrGeoff, thanks for the tipsI 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..

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 14, 2012, 08:22:43 am
content: 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 loaderedit: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.

author: amyk
author_rank: Super Contributor
timestamp: February 14, 2012, 12:09:49 pm
content: Quote from: Madsaaby on February 13, 2012, 02:43:29 pmHow 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.

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 14, 2012, 12:30:33 pm
content: Quote from: Mechatrommer on February 14, 2012, 08:22:43 amIf 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'tBrownout might be enabled. As I mentioned I'm still a beginnerDidn't knew about the brownout, but googled itCould be an issueI'll check that..

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 14, 2012, 12:33:22 pm
content: Quote from: amyk on February 14, 2012, 12:09:49 pmI used the same wires, about 30 cm..

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: February 14, 2012, 09:34:35 pm
content: Quote from: Mechatrommer on February 14, 2012, 08:22:43 amHow are you calculating the values of Vsense? Particularly, at 0A through RL your diagram has Vsense = 2.98v at Vs=12v. How?

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 15, 2012, 02:25:58 am
content: Quote from: Sal Ammoniac on February 14, 2012, 09:34:35 pmFWIW, 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 is2.98errr... 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.

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 15, 2012, 02:40:42 pm
content: Thanks a lot for the help guysFinally 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

author: Mint.
author_rank: Frequent Contributor
timestamp: February 17, 2012, 09:23:18 am
content: Quote from: Madsaaby on February 15, 2012, 02:40:42 pmPlease 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.

author: Madsaaby
author_rank: Regular Contributor
timestamp: February 17, 2012, 01:33:32 pm
content: Quote from: Mint. on February 17, 2012, 09:23:18 amYou are absolutely rightI 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 clockThere might be more appropriate chips out there, but I just remember the 16F1507The only limitations for this project was the 10 bit ADC, so there are many many suitable chips out there..Edit: Just realizing it says PIC16F887 on the layout img.. Did actually use the 16F877a, doesn't make it any cheaper though

author: Mint.
author_rank: Frequent Contributor
timestamp: February 18, 2012, 12:39:46 am
content: Quote from: Madsaaby on February 17, 2012, 01:33:32 pmFair 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