HELP: analog input

I’m trying to get an analog input from my 10 Kohm but all i get is a series of numbers counting downwards and reseting the controller makes it go back from the number in which it stopped instead of the one in which it began…

Any suggestions?

If you could post the relevant portion of your source code here, we could offer you some insight.

Otherwise, the best we could offer up is a generic “look at Kevin’s code” here: response.

printf(“Pot %d\r”, Get_ADC_Result(1));

The counting occurs when nothing is connected.
Make sure that the Pot is plugged into the right pin.
In Kevin’s ADC, #1 is actually analog in #2 (#0 is pin #1).

we did what you said but it still counts.
can any body please send us a working code for the potentiometer using the analog inputs.

Without using Kevin’s code:

Potentiometervalue = Get_Analog_Value(rc_ana_in01);

I think Bharat is trying to tell you (and he’s right) that it’s overkill to use my code to read a potentiometer. Just use his example and it should work. If you really want to use my code, if I remember correctly, Get_ADC_Result() returns an unsigned int, which means you should use %u in your printf() format string, not %d.


We have tried both things, with Kevin’s code and it still did not work…
any further suggestions?

Is your potentiometer wired correctly? Red and black to the outer leads, white (signal) to the center? The problem you described only occurs when nothing is plugged in, so make sure you’re referencing the correct analog input in your code, that the pot is wired correctly, and that it’s not broken (which is kind of hard to do… test another one?).

We tested it with a voltmeter and it all good…

But is it wired up correctly? You can test it at a point on the potentiometer and get correct readings. However, if it is not wired up correctly, the processor will not be able to read it. There is also a slight chance the processor itself has corrupted analog pins. That happen to our 2006 controller at the end of the season.

the potentiometers are good like i said…
We have checked it with a voltmeter connecting between the where the white cable connects and where the red one connects and it shows the correct results.
We have also tried to change the ports, and neither of them worked…

If your idea of “good” does not match what the RC expects, it won’t work no matter how many times you check to see that it’s “good”. In order to help you, we need to know exactly how you have wired it. Answering “we wired it correctly” is not going to help. For example:

We have checked it with a voltmeter connecting between the where the white cable connects and where the red one connects and it shows the correct results.

But where did you connect the black wire? What measurement are you making, and what results are you getting? Answering “the correct results” does not help.

A potentiometer on the Robot Controller’s analog inputs needs three wires. Black (ground) goes to one end of the pot. Red (+5) goes to the other end of the pot. White (signal) goes to the wiper.

Like i said before…its connected CORRECTLY…
There is another problem…
Black goes to left side of potentiometer
Red goes to its right leg
and white goes to the middle one…
and they connect to the analog inputs correctly
We have measured voltages between red and white legs, and it shows inputs from 0 to 4.95V liniarically to the rotation i make…

Here’s our code:

does not work with %d or %u…

could you show me the code of Get_Analog_value…perhaps the problem we have has to with that function…

I don’t know this first hand, but does the analog port need to be setup as an input somewhere? Does the ADC need to be enabled?



Make sure you are calling the function

    Set_Number_of_Analog_Channels(SIXTEEN_ANALOG); /* DO NOT CHANGE! */

In User_Initialization(). Otherwise, I really don’t know what to tell you. Make sure it’s connected to the RC properly (wire ordering), there are no breaks in the PWM cable, that the wires are SECURELY (i.e. soldered) connected to the pot, and that you’ve tried it with all the analog inputs (well, 2-4 of them should probably suffice).

Good luck.

Okay, here is code from our robot this year. This is exactly how we have written it and it works.

We made variables on top of the file:

unsigned int BottomSonic = 0;

Then, inbetween Getdata and Putdata, we inserted these two lines:


TopSonic = Get_Analog_Value(rc_ana_in02);

printf("Top: %d
", TopSonic);


If you have it wired up correctly, then the code above will work.

Also, try it on a fresh piece of code with the absolute default code from IFI.

Make sure your init functions are correct.

and call the get_analog_value()

You left out important details here. Please replace the word “correctly” with a description of the actual connection to the Robot Controller.

I have been having the exact same issue. I tried IFI’s ADC, Kevin Watson’s integrated into my code, Kevin Watson’s from his website(unmodified), and whatever EasyC uses.

They all read 0.

I have tried both the 2006 and 2007 controllers.

I have the pot connected so the 5v+/gnd each connect to one side of the pot, and the signal is connected to the middle connector on the pot.

If I short the gnd/sig pins the reading does NOT change.

I have used Kevin Watson’s ADC without any issues before now. I have run it on VEX, EDU, and 2005 controllers.

I was at the Sussex mini-regional today and talked to 4-5 other programmers, and none of them had any ideas.

What am I missing?

Eric Haskins