Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: krich on November 15, 2007, 06:44:34 PM

Title: ADC values inconsistent
Post by: krich on November 15, 2007, 06:44:34 PM
Man oh man.  I have a new found respect for those that can solder together their own boards and have stuff work as designed.

I've finally got my servos working flawlessly.   ;D

Now I've got issues with my photocell sensors.  The way I understand the code, it reads the pin voltage and then uses the analog to digital converter to return a scaled value.  My problem is that this value is all over the map.

To test, I added in some code to make the LED blink out what the value of the left sensor is.  It seems to be fluxuating between the 180s and down in the teens.  It was then that I noticed that the value changes EVEN WITH THE SENSORS DISCONNECTED.   ???

I guess it will probably all come down to my lack of soldering skills, but is there any advice you guys could offer to help me isolate the issue?  Could I be getting crosstalk (or whatever you call it) between pins because my solder points are too close?

I've checked voltages across Vcc/AVcc/Aref and GND and they all measure 4.99V.

Title: Re: ADC values inconsistent
Post by: bens on November 15, 2007, 06:57:53 PM
1) Are you confident in your ADC code?  Can you apply it to the input from another ADC pin and check to see if it returns the right values when you tie that pin to a predetermined voltage (e.g. 0, Vcc, maybe the output of a voltage divider).

2) Use a multimeter or oscilloscope to look at the output of your sensor.  Is that steady?  Does it make sense?

3) If the connection to your ADC is floating, you can reasonably expect the reading to be all over the place (the voltage will be weakly affected by all of the EM fields created by the nearby traces).  I recommend doing a continuity check between your sensor connection and the ADC pin on your microcontroller.  If that's not the source of your problem, check for shorts between that line and any neighboring lines.

4) Consider using the UART for debugging if possible (blinking LEDs can't convey as much information as your UART).
Title: Re: ADC values inconsistent
Post by: krich on November 15, 2007, 07:11:26 PM
Thanks for the tips bens.  I can definitely check a few of your suggestions.

I have a MAX233CPP chip sitting in my cabinet just waiting to get installed, but I figured that if I've got issues with my sensors, what's the likelihood that I'll be able to pull off adding UART functionality.

To clarify, lest all of you think I'm driving myself insane counting hundreds of blinks at a time, the LED blinks each digit in the number, so I usually don't get more than 10-15 blinks to count each time around.   ;)  It does make for a very sllllooooowww photovore though.   :P
Title: Re: ADC values inconsistent
Post by: krich on November 15, 2007, 07:45:20 PM
Alright, there's no continuity test on my meter, so I checked the resistance between the header and the pin socket for pins 23-28.  They all came out to be 0.4 Ohms.  That's confirmed good.

Taking it a step further...

I checked resistance between the Vcc bus and the individual pins.  The results were:

I checked resistance between the GND bus and the individual pins.  The results were:

I checked resistance between each pin and its neighbor.  The results were:

Out of the three sets of data, pin 23 to 24 in the 3rd set bothers me.  Looks like a good point to start resoldering, no?
Title: Re: ADC values inconsistent
Post by: Admin on November 15, 2007, 07:56:41 PM
Did you measure the resistance on the sensor wiring? Did you plug the sensor into the correct port?

It could also be something more mundane, like your code to flash the LED wasn't done right . . . an int overflowing, something not being carried over, etc . . .
Title: Re: ADC values inconsistent
Post by: krich on November 16, 2007, 10:22:53 PM
I checked the sensor wiring and it appears to be good.  I also checked the voltage between the proper input pin and ground and found it to be fluctuating between Vcc (4.99V) and about 2.1V while the ATmega8 was running the program, but without the sensor plugged in.

Also, all of the above resistance measurements in the previous post were made without the batteries connected and without the ATmega8 in the socket.

I've checked and double checked the pin assignment in the program with the pin diagram in the ATmega8 data sheet.  I also ran a couple simple tests to be sure my LED blinker code is working properly.

I wonder if there's a slight short to ground somewhere that is making the ground float all over the place.  I thought I read somewhere in the forums that the ground needs to be steady for the ADC to function reliably.

Also, I'm not really sure if measuring voltage between the Analog Input pin and Ground is a valid measurement point, given that it's an input pin.

Geez...maybe I need to get my hands on a oscilloscope.  I had hopes that I could do it with my sound card, but it seems those oscilloscopes can't reliably measure DC circuits.  Ebay, here I come!  :P
Title: Re: ADC values inconsistent
Post by: Admin on November 17, 2007, 08:56:22 AM
Plug in the sensor and turn the board on with the program running. Measure the input pin to see if it is working properly when you change light on the sensor.

If the pin gives the right voltage, then its your program that is wrong. Otherwise, it is your wiring . . .
Title: Re: ADC values inconsistent
Post by: paulstreats on November 17, 2007, 06:25:50 PM
Are you using the code from the $50 robot?

Are you using a 10 bit a2d conversion and only reading the low bytes?

Are you trying to put the 10 bit reading directly into an 8 bit char and overflowing it maybe?