Arduino Forum

Using Arduino => General Electronics => Topic started by: adrian_h on Apr 02, 2013, 10:21 pm

Title: ADC values not zero when plugged into ground and turning on LEDs
Post by: adrian_h on Apr 02, 2013, 10:21 pm
I've been trying to figure out why, when I turn on a lot of LEDs, that the ADC was getting noise.  So I moved the wire from the sensor to ground and saw that the noise was still there.  Just leaving the LEDs on (instead of turning them on and off) I get a constant reading above zero.

So I'm assuming that the problem is with the draw of the current on the system is causing the ADC to fail?  I am using an external analog reference and that seems to help lower this problem, but it would be a great help if I can get rid of this problem all together.

Any ideas?  The LEDs are collectively drawing about 80mA.

Thanks,


Adrian
Title: Re: DAC values not zero when plugged into ground and turning on LEDs
Post by: dc42 on Apr 02, 2013, 10:33 pm
I presume you mean the ADC, not the DAC. You need to separate your ground wiring. Dedicate one of the ground pins on the Arduino to be analog ground, and use it to connect only the ground side of the sensors and any associated filtering capacitors. Use a different ground pin to connect the ground sides of the LEDs or other output devices, and power (if not powering from USB or the barrel jack).
Title: Re: DAC values not zero when plugged into ground and turning on LEDs
Post by: normanc on Apr 02, 2013, 10:43 pm
Try using a pull-down resistor on the ADC input... something like 10k should be able to filter out ambient voltage.  But this may introduce a bit of distortion, can someone fact-check me on this?
Title: Re: DAC values not zero when plugged into ground and turning on LEDs
Post by: Grumpy_Mike on Apr 02, 2013, 10:51 pm
Quote
Try using a pull-down resistor on the ADC input

???
But he said that he already connected the input to ground so a pull down resistor across a dead short is not going to do much is it?
DC42 has the answer.
If you can't sort it then post a photograph of your setup.
Title: Re: DAC values not zero when plugged into ground and turning on LEDs
Post by: adrian_h on Apr 02, 2013, 10:54 pm

I presume you mean the ADC, not the DAC. You need to separate your ground wiring. Dedicate one of the ground pins on the Arduino to be analog ground, and use it to connect only the ground side of the sensors and any associated filtering capacitors. Use a different ground pin to connect the ground sides of the LEDs or other output devices, and power (if not powering from USB or the barrel jack).

Yeah, I meant the ADC brain fart.   :~  Changed the name of the thread and all DAC refs.

I thought that all grounds were the same.  This isn't so?
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: Grumpy_Mike on Apr 02, 2013, 11:06 pm
It is a universal untruth that all grounds are created equal.

If a wire has a return current running through it then it is lifted in voltage. If that same wire is used to ground an input from the far end then instead of seeing ground the input sees the voltage created by the return current on that wire.
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: adrian_h on Apr 03, 2013, 12:47 am
Ok, well all good to know, but plugging in the ADC into ground was just a test.  Moving it to a different ground solved the problem.  Now I have another problem.  When I plug it into the detection circuit I was using it for, and switching that circuit to a different ground didn't do anything.  I'm assuming that the +5 line is being disrupted the same way as the ground was.

These are my two circuits:
Code: [Select]
Circuit 1:

                       D00  D01   R0
       +5 -----------+-|>|--|>|--'\/\,--+
                     | D10  D11   R1    |
                     +-|>|--|>|--'\/\,--+
                     | D20  D21   R2    |
                     +-|>|--|>|--'\/\,--+
                                        |
     GND1 ---E\ /C----------------------+
             T0|B
               |    RB
               +---'\/,-- pin 12

Dxy = IR LEDs where x is which sub-circuit and y is which diode
R0  = 27 resistor
R1  = 27 resistor
R2  = 27 resistor
T0  = transistor PN2222A
RB  = 100 resistor

Circuit 2:
              PD           R0
          +---|>|-----+---'\/\,-------+
          |           |               |
          |         T0|B              |
          |         E/ \C             |
          |         |   +-+           |
          |       T1|B    |           |
          |       E/ \C   |    R1     |
          +-------+   +---+---'\/\,---+--- AREF
          |               |           |
          +--- GND2       +--- A1     +--- +5


PD  = IR PhotoDiode
T0  = transistor BC183
T1  = transistor BC183
R0  = 1M resistor
R1  = 47k resistor

EDIT: Fixed photo diode's direction.

Circuit 2 is a modified version of Sneak Thief from Grumpy Mike (http://www.thebox.myzen.co.uk/Hardware/Sneak_Thief.html) where I switched the PD with the R0.  This was done intentionally since it appears to give me better sensitivity.  And as I am only looking for differences in voltage when I turn on and off pin 12, a small (what I thought was constant) voltage is not a problem.  However the fluctuating voltage is disrupting the signal, causing me problems.

I had thought that plugging into the external analog reference would resolve this, but it only helped, not remove the problem.

So I see only one alternative at the moment, and that is to have a some other load go on when the LEDs are off while I'm measuring.  Is there a better way?
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: Grumpy_Mike on Apr 03, 2013, 12:58 am
In that circuit you have drawn you have the photo diode the wrong way round.

No need to use an external referance especially if all you are going to do is connect it up to 5V. Put a large capacitor about 47uF across the supply to the detector circuit.
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: adrian_h on Apr 03, 2013, 01:10 am

In that circuit you have drawn you have the photo diode the wrong way round.

Oops, finger slip.  Thanks.


No need to use an external referance especially if all you are going to do is connect it up to 5V. Put a large capacitor about 47uF across the supply to the detector circuit.

That's it?  Cool!  Will try that! :D
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: afremont on Apr 03, 2013, 01:22 am

In that circuit you have drawn you have the photo diode the wrong way round.



Are you sure?  They are usually reverse biased in circuits that I've seen.

EDIT:  Now that I put have my glasses on, I can see that the OP's circuit shows the photo-diodes forward biased as Grumpy Mike pointed out.  Photo-diodes are normally reverse biased.
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: adrian_h on Apr 04, 2013, 10:32 am

No need to use an external referance especially if all you are going to do is connect it up to 5V. Put a large capacitor about 47uF across the supply to the detector circuit.


Ok, that didn't work quite right.  It caused lagging in the signal which is not what I wanted, but by putting several in parallel around the IR LED emitter circuit it did reduce the problem.  I think it stopped the LEDs from stressing the ADC circuit so much.

I'm going to try with a big ass cap tomorrow.  I used 5 47uF in parallel, which is the equivalent to 235uF, so I'll try for something 2 - 4 times as big.

I also ditched the amplifier.  I got better results by just using a simple voltage divider with a 2-3M resistor on the GND leg and the IR photo diode on the +5.

Thanks for all the help! :D  When I have this just the way I want it, I'll post all schematics and code.  Is there a place for that here?
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: fungus on Apr 04, 2013, 11:15 am

I'm going to try with a big ass cap tomorrow.  I used 5 47uF in parallel, which is the equivalent to 235uF, so I'll try for something 2 - 4 times as big.

I also ditched the amplifier.  I got better results by just using a simple voltage divider with a 2-3M resistor on the GND leg and the IR photo diode on the +5.


I doubt size is the problem, but speed might be. Small ceramics are much faster than "big ass". Try some ceramics across the terminals of the "big ass" so you combine speed+capacity.
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: adrian_h on Apr 04, 2013, 12:21 pm


I'm going to try with a big ass cap tomorrow.  I used 5 47uF in parallel, which is the equivalent to 235uF, so I'll try for something 2 - 4 times as big.

I also ditched the amplifier.  I got better results by just using a simple voltage divider with a 2-3M resistor on the GND leg and the IR photo diode on the +5.


I doubt size is the problem, but speed might be. Small ceramics are much faster than "big ass". Try some ceramics across the terminals of the "big ass" so you combine speed+capacity.


Thanks for the suggestion.  I was using electrolytic can types.  They were red with a black strip down the negative terminal.  I've never seen a red one before.  Wonder if they are different from the black ones I normally see.
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: Grumpy_Mike on Apr 04, 2013, 05:00 pm
Quote
It caused lagging in the signal which is not what I wanted,

That suggests you did not put it in the right place. There is no way a capacitor on the supply can delay the signal.
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: adrian_h on Apr 04, 2013, 07:20 pm

Quote
It caused lagging in the signal which is not what I wanted,

That suggests you did not put it in the right place. There is no way a capacitor on the supply can delay the signal.


Well, I only have two power buses and one is dedicated to the IR LED circuit and the other is dedicated to the detection circuit.  And the only difference between them is that each uses a different ground.  I don't know what to say. :?  I would have to reqire the circuit and rewrite the code to check the data again.  I just remember that it interfered with the detection.  IIRC, I actually started to get an off signal higer than an on signal.


I doubt size is the problem, but speed might be. Small ceramics are much faster than "big ass". Try some ceramics across the terminals of the "big ass" so you combine speed+capacity.


I was thinking about this and I don't remember reading anything that stated that different types of capacitors had different charge/discharge rates.  Could you give me some place where I could find such information?
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: fungus on Apr 04, 2013, 07:23 pm

I was thinking about this and I don't remember reading anything that stated that different types of capacitors had different charge/discharge rates.  Could you give me some place where I could find such information?


Straight from the horse's mouth: http://www.atmel.com/Images/DOC0484.PDF
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: Grumpy_Mike on Apr 04, 2013, 08:58 pm
Quote
Well, I only have two power buses and one is dedicated to the IR LED circuit and the other is dedicated to the detection circuit.  And the only difference between them is that each uses a different ground.

Are the two grounds electrically the same?
Not sure about the two power buses, are they from a different source?
Either way, as I said, that simply can't happen if it is wired as described. Think about it, all that you are doing is adding a capacitor across the supply, this can't affect the signal. What were you seeing that made you think there was a delay.

Quote
different types of capacitors had different charge/discharge rates.

Well I would not say they are different  charge/discharge rates but the capacitive reactance and effective series resistance are different with different types of capacitors.
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: adrian_h on Apr 04, 2013, 11:47 pm

Are the two grounds electrically the same?

No, different GND pins.


Not sure about the two power buses, are they from a different source?

No, same source.  What I mean by power bus is that I've got a breadboard with two buses going down each side.  I'm connecting the LEDs to one and the sensor to the other.  Each connected to a separate ground pin.


Either way, as I said, that simply can't happen if it is wired as described. Think about it, all that you are doing is adding a capacitor across the supply, this can't affect the signal. What were you seeing that made you think there was a delay.


Ok, here's my data.  Numbers on right of graph are values I've received from ADC, the graph is a representation of those numbers.  ON represents when the LEDs are switched on, OFF when they are off:

With no caps:
(http://i.imgur.com/jCPYcc4.png)

With 235uF on LED circuit:
(http://i.imgur.com/jfdspdS.png)

With cap on sensor circuit:
(http://i.imgur.com/JDEJoya.png)

It sure does look like the signal is being delayed.  That or its being inverted.  Oh, BTW, the values were taken when the sensor was partially blocked from the IR LEDs.


Straight from the horse's mouth: http://www.atmel.com/Images/DOC0484.PDF

Thanks for this. I'll have to read it later.
Title: Re: ADC values not zero when plugged into ground and turning on LEDs
Post by: adrian_h on Apr 05, 2013, 12:28 am
Looks like I don't need more caps.  Just 3 or 4 of these 47uF were enough.  I actually was getting signals from the ceiling when I had all 6 IR LEDs on. :D  I may only need 1 or 2 IR LEDs on for this project.