Let's Make Robots!

ADC and strange readings

Hello guys,

I ran this sketch that would simply read an ADC port and print it out to my pc. It went just fine and results were pretty consistent, something like: 300 300 300 300 300 299 300 300 299 300 300 and so on....

But when I use Serial.print(analogRead(whatever_pin)); in a larger sketch, results are very different, something like: 300 290 305 288  310 315 306 296 and so on. This "larger" sketch has 3 interrupt service routines, and the hardware setup has 3 different chips and a loudspeaker.

I am not really sure why that happens. Is it software related (interrupt service routines ---> make the analogread lag?) or is it hardware related (lots of noise coming from chips ---> intereferes with readings)? Oh btw, i don't know if this really matter, but i am using pull up resistors on those pins (pinMode = input, digitalwrite = high) and i'm connecting "thing that gives the reading" between the ADC pin an GND.

 

Thank you!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Damn, don't have those :=( I mean i have 100uF and 10uF caps but they are polarized. I'll see if i scavange them from something.

Go with the polarized ones. No worries mate.

Cool! Thanks :=)

The amplifiier doesn't like DC ditto. But again, I don't know if this is the cause for this problem.

Oh, so you're saying that all this noise generated by speaker/amp is not normal? I thought it was just ok and was searching for a way to shield the adc pins. Ok then, i'll see if i can fix the amp somehow, and i'll try to follow the above schematic strictly to see if it gets better. Thanks!

It is slightly possible that you are getting noise from your unused analog pins. You can use the internal pullups for the Arduino by setting the unused analog pins high.

digitalWrite(A0, HIGH);  // set pullup on analog pin 0

Most people don't have a problem leaving the unused pins floating, but it is something you can try if your problem is not eliminated by the other steps that have been suggested. It only costs you a few lines of code to set them high. I have also read that setting your unused lines high can reduce your power consumption. See link below.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1243213127/all

 

 

 

It is possible that the interrupts are affecting your readings but more likely it is electrical noise. Try temporarily disabling the interrupts.

If the problem persist then try disconnecting different sensors / output devices one at a time to try and pinpoint any one trouble maker.

Is your Aref disconnected? Try adding a 100nF capacitor between it and Gnd and do the same for your AVCC placing the capacitors as close as possible to the Arduino pins and Gnd. A 100uF capacitor directly on the AVCC and GND pins might also help.

Check that any electric motors have caps between their power pins and the casing.

If all else fails then use your software to average the readings.

 

I am using the arduino duemilanove board so those pins are already decoupled. Also the other chips are. I'll try adding random .1uF caps around to see if anything changes, i was hoping for a way to  decouple the ADC pins directly (adding some sort of noise protection directly on those pins).

...and, i can't really disable interrupts :=(

Thanks for the answers, i'll do some research this afternoon and see what i can come up with

 

PS: i guess resistors with long legs are also a problem, right? (the resistors are actually what's placed between the ADC and ground, by changing (physically) the resistor i get different readings)

Like Robofreak and his Sharps, you could use a scope to confirm any fluctuations in the voltage levels. Or exclude that as a possibilty.

I have had mixed experiences with soundcard/software scopes lately. But a ripple in an otherwise steady voltage should be pretty easy to find.

My first suspect would be the speaker. Easy enough to eliminate, I suppose.