Log in

View Full Version : Potentiometer Question, we need help!


dez250
24-02-2004, 18:34
The programming group of my team wanted me to post the following question to see if anyone might recognize the problem.

"My programmers and I have been having a bit of a time trying to get the potentiometers on our robot to work. the two joystick drives are working properly, but a third analog input on p3_y (using pins 1 and 6) and a pot on the robot itself (assigned using pot = Get_Analog_Value(rc_ana_in01); ) are both giving me values ranging from -3000 to 20000. Unless I'm horribly misinformed, this can't be right. I imagine there's a function or two I'm missing that would format the input properly, but I can't find what it is. Any ideas?"

FotoPlasma
24-02-2004, 20:17
You don't use the function Get_Analog_Value() to get the analog values from the OI. They are received by the control system by the GetData() function (or whatever it is), and are already available to the programmers. The Get_Analog_Value() function is used to read analog values from the RC's analog input pins.

Bharat Nain
24-02-2004, 20:22
You're right using Get_Analog_Value(rc_ana_in01); . Now I dont really remember how this is done, but we had the same problem. I can help you with this much, it should not be declared as a 10 digit number or whatever, you just want a 2-3 digit number. I'll try a rough example, it might click in some of your brains.

int analog1; /*This is declared up in the program)


analog1 = Get_Analog_Value(rc_ana_in01) << 2);

/*end*/

Something like that. Somebody correct me or explain better. Sorry I'm out of my brains right now. :ahh:. But I hope this gets you somewhere at this moment.

mightywombat
24-02-2004, 21:36
Here's what you do.
If the pot is hooked up on port3 on the y-axis try this.

int pot;
pot = p3_y;

You only use the GetAnalogValue() func when you are reading values from the controller (as previously mentioned).

mtrawls
24-02-2004, 21:58
The programming group of my team wanted me to post the following question to see if anyone might recognize the problem.

"My programmers and I have been having a bit of a time trying to get the potentiometers on our robot to work. the two joystick drives are working properly, but a third analog input on p3_y (using pins 1 and 6) and a pot on the robot itself (assigned using pot = Get_Analog_Value(rc_ana_in01); ) are both giving me values ranging from -3000 to 20000. Unless I'm horribly misinformed, this can't be right. I imagine there's a function or two I'm missing that would format the input properly, but I can't find what it is. Any ideas?"

Are you printing these values to see that range? Did you cast your variable -- e.g., printf ("Pot values is: %d\n", (int) pot_value);


it should not be declared as a 10 digit number or whatever, you just want a 2-3 digit number. I'll try a rough example, it might click in some of your brains.

int analog1; /*This is declared up in the program)
...
analog1 = Get_Analog_Value(rc_ana_in01) << 2);

Something like that. Somebody correct me or explain better. Sorry I'm out of my brains right now. . But I hope this gets you somewhere at this moment.


It should be (on the RC) a 10 *bit* number (0-2^10-1). You may want to convert this to an 8 bit number for some reason (compatible with pwm outputs), in which case you can shift it. However, it should still be a positive 10 bit value lacking such a conversion.

It seems most likely that the problem is a lack of casting -- I assume the variables are declared as unsigned integers, in which case it can't be a negative number (though it might print out as such without proper casting).

The Lucas
09-03-2004, 04:23
Your 10 bit ADC value may be left justified in the 16 bit integer (in the most significant bits). To right justify the ADC value, add this statement to your initailization:

ADCON2bits.ADFM = 1; //Right justify the 10 bits in all ADC

More info on this register is availiable on page 215 of 380 of the PIC 18 datasheet (Lit #39609b) on the Microchip website. Hope it helps you Mike.

Al Skierkiewicz
09-03-2004, 07:15
Dez,
I am no help in programming but I did want to make sure that you have the pot connected correctly. The RC wires the pot between +5 and ground with the wiper going to the analog input. The OI does not use the ground return, just simply a series varying resistance.

KenWittlief
09-03-2004, 08:55
analog1 = Get_Analog_Value(rc_ana_in01) << 2);

/


I think your 'shift' is the wrong way - that is a shift left, which will push the 10 bit ADC input up to a 12 bit number;

usually you want to knock the Analog inputs down to 8 bits from 10, a shift right (arrows to the right) >>2;

:^);

pryoplasm
09-03-2004, 13:03
Dez,
I am no help in programming but I did want to make sure that you have the pot connected correctly. The RC wires the pot between +5 and ground with the wiper going to the analog input. The OI does not use the ground return, just simply a series varying resistance.


i agree, sounds like a problem with the mounting. also, this is a 10 trun potentiaometer, right? if it is bigger, that could explains some of the funky values...

TomJoseph
29-03-2004, 11:14
I think your 'shift' is the wrong way - that is a shift left, which will push the 10 bit ADC input up to a 12 bit number;

usually you want to knock the Analog inputs down to 8 bits from 10, a shift right (arrows to the right) >>2;

:^);

You'll also want to typecast it into an unsigned char, just for safe keeping:

unsigned char pot1;
pot1 = (unsigned char) (Get_Analog_Value(rc_ana_01) >> 2);

Neal Turett
18-04-2004, 23:03
If you want to read a value from a potentiometer wired into where the p3_y would normally be, you can just access p3_y. The OI handles the analog-to-digital conversion and returns an 8bit value, in the form on an unsigned char.

If you are reading a value from your inputs Get_Analog_Value(rc_ana_in01) is the correct function. This will return a 10-bit number. To scale this to 8 bits, only read the bits 2-9. The simplest way to do this is divide by 4. The syntax to output this is printf("Label: %3d", (int)(Get_Analog_Value(rc_ana_in01) / 4))

Hope this helps.

Sparks333
25-08-2004, 13:53
I would like to point out that this is an electronics thread. Is programming moving in on our turf?

-Sparks

Matt Attallah
25-08-2004, 14:32
The more the merrier!!

I think it's all right for a slip up here and there...:D

Astronouth7303
25-08-2004, 14:50
The OI pots are only 8 bits; chars. The Analog inputs are 10 bits. so you do this:

unsigned char JoyPot;
unsigned int BotPot;
unsigned char BotPot2; //For comparison with the joystick

JoyPot = p3_y;
BotPot = Get_Analog_Value(rc_ana_in01);
BotPot2 = (unsigned char)(BotPot >> 2);


BotPot2 is now 8 bits; it can be used to compare with JoyPot.

By the sound of it, they're using signed long, which is 2-4 times larger than necessary (not to mention signing, which is a little weird).

[And I agree that this thread is a little misplaced]