Quote:
|
Originally Posted by dez250
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);
Quote:
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).