|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Potentiometer Question, we need help!
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?" |
|
#2
|
||||
|
||||
|
Re: Potentiometer Question, we need help!
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.
|
|
#3
|
|||||
|
|||||
|
Re: Potentiometer Question, we need help!
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. . But I hope this gets you somewhere at this moment. |
|
#4
|
|||||
|
|||||
|
Re: Potentiometer Question, we need help!
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). |
|
#5
|
||||
|
||||
|
Re: Potentiometer Question, we need help!
Quote:
Quote:
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). Last edited by mtrawls : 24-02-2004 at 22:59. |
|
#6
|
|||||
|
|||||
|
Re: Potentiometer Question, we need help!
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:
Code:
ADCON2bits.ADFM = 1; //Right justify the 10 bits in all ADC |
|
#7
|
|||||
|
|||||
|
Re: Potentiometer Question, we need help!
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. |
|
#8
|
||||
|
||||
|
Re: Potentiometer Question, we need help!
Quote:
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; :^); |
|
#9
|
||||
|
||||
|
Re: Potentiometer Question, we need help!
Quote:
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... |
|
#10
|
|||
|
|||
|
Re: Potentiometer Question, we need help!
Quote:
Code:
unsigned char pot1; pot1 = (unsigned char) (Get_Analog_Value(rc_ana_01) >> 2); |
|
#11
|
|||
|
|||
|
Re: Potentiometer Question, we need help!
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 Code:
Get_Analog_Value(rc_ana_in01) Code:
printf("Label: %3d", (int)(Get_Analog_Value(rc_ana_in01) / 4))
|
|
#12
|
||||
|
||||
|
Re: Potentiometer Question, we need help!
I would like to point out that this is an electronics thread. Is programming moving in on our turf?
-Sparks |
|
#13
|
|||||
|
|||||
|
Re: Potentiometer Question, we need help!
The more the merrier!!
I think it's all right for a slip up here and there... ![]() |
|
#14
|
|||||
|
|||||
|
Re: Potentiometer Question, we need help!
The OI pots are only 8 bits; chars. The Analog inputs are 10 bits. so you do this:
Code:
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); 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] |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MIM's question of the day on programming. | Gene F | Programming | 3 | 24-02-2004 16:32 |
| A question about control system options | computhief263 | Control System | 7 | 04-02-2004 14:46 |
| MnM EASY Question of the Day Winners! | Mike Bonham | General Forum | 22 | 03-05-2002 21:21 |
| Chief Delphi Site Question | Mike Bonham | General Forum | 1 | 16-02-2002 22:18 |
| Rookie Programmer has question about the default code | DanL | Programming | 3 | 26-01-2002 19:59 |