![]() |
Potentiometer with ADC
I've searched chiefdelphi and didn't come up with anything. But, how would I go about coding a potentiometer with the ADC. I am quite new to using both the potentiometer and the encoder. Help is much appreciated.
|
Re: Potentiometer with ADC
It's pretty simple. Wire the potentiometer to a PWM cable (I forget how to do this since I didn't do it), and plug it into one of the appropriate RC inputs. I'm fairly sure that the white cable of the PWM cable is the signal line, while the red and black ones are positive and ground. Once it is set up, it should simply be the potentiometer with the PWM cable hanging off it. There is no need for additional wires or power.
Once you've done that, you can access whatever values it is reading with the function Get_Analog_Value(int whichInput). For example, our potentiometer in the 2006 robot, we did: Code:
curPotentReading = Get_Analog_Value(rc_ana_in03) |
Re: Potentiometer with ADC
Thanks for the reply but I am not sure that that would work because you have to comment out Set_Number_of_Analog_Channels(SIXTEEN_ANALOG); in order to get the adc to work correctly
|
Re: Potentiometer with ADC
Quote:
Here's our whole User_Init. Aside from the commented-out line for the shooter switch, I think it is unmodified from the given code. Code:
void User_Initialization (void) |
Re: Potentiometer with ADC
DustinB_3 you must be using Kevin's code. If you are you just follow the instructions to integrate his code into yours, or use his complete project.
Then to get the value you call Get_ADC_Result(unsigned char port#). The following code would get the value from analog input 1. Code:
int position = Get_ADC_Result(1); |
Re: Potentiometer with ADC
Thanks for the help. That was exactly what I was looking for.
|
Re: Potentiometer with ADC
Does anyone know what resistance potentiometer to use?
|
Re: Potentiometer with ADC
Anything from 2k to 100k ought to work. Higher resistances will be slightly more susceptible to noise. We've used 10k with good results.
|
Re: Potentiometer with ADC
Quote:
-Danny |
Re: Potentiometer with ADC
I have a dumb question - I Just hooked up a 100K pot to analog input 01, but Get_Analog_Value(rc_ana_in01) is only returning values from 0-9, and it definitely is not linear. This is the (very simple) code we're using just to test:
Code:
printf("%u\n", Get_Analog_Value(rc_ana_in01));Thanks |
Re: Potentiometer with ADC
Quote:
Code:
int Get_Robot_Pot(void) { |
Re: Potentiometer with ADC
How is that a problem when analog inputs return an unsigned int (16-bits on the PIC18, more than enough for the 10-bit ADC conversion)? I'm assuming %d is expecting an int, so it should be fine. Even if the compiler was lopping of the 2 MSbs of the result, it should still return a value from 0-255.
Thanks for the help, though. We're going to try some new linear taper 10k/50k pots tomorrow. We really weren't sure exactly what kind of pots the old ones were, only that they were 100k ohm. |
Re: Potentiometer with ADC
Quote:
Use a voltmeter to look at the signal (white) wire. It should vary from 0 volts to 5 volts as you turn the pot. If it only gets up to a few millivolts, it's possible that you have the ground and wiper connections swapped. |
Re: Potentiometer with ADC
I'll definitely check that, thank you. We currently have the pot wired so that the signal wire is in the center, which I assumed to be the wiper based on a previous topic here. Do all pots use the center connection for the wiper?
|
Re: Potentiometer with ADC
Quote:
|
| All times are GMT -5. The time now is 01:20. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi