Go Down

Topic: interfacing 10 turn precision potentiometers to analog In (Read 1 time) previous topic - next topic

Drc3p0

I am having trouble interfacing a precision potentiometer with my arduino, I am monitoring the output with this sketch:
Code: [Select]
/* Map an analog value to 8 bits (0 to 255) */
void setup() {
Serial.begin(9600);
}

void loop()
{
  int mapval = 0;
  int val = analogRead(3);
  mapval = map(val, 0, 1023, 0, 1023);
//  analogWrite(9, val);
 
  Serial.println(mapval);
}

/*
Parameters
value: the number to map
fromLow: the lower bound of the value's current range
fromHigh: the upper bound of the value's current range
toLow: the lower bound of the value's target range
toHigh: the upper bound of the value's target range
*/


This is the potentiometer i'm using:
http://www.bourns.com/data/global/pdfs/3590.pdf
It is a 100k potentiometer, and I checked the datasheet to make sure the wiring was correct.  Is the fact that it is 100k instead of 10k?  I used the 3.3v pinout on the arduino...I noticed that the 5v was sometimes pulling too much power, I was using the USB cable for the power source

Thanks in advance for your wisdom.

marco_c

Are you wired with Pot pin 1 and 3 to the power supply and pin 2 (the wiper) to the analog input?
Arduino libraries http://arduinocode.codeplex.com<br />Parola for Arduino http://parola.codeplex.com

Drc3p0


Are you wired with Pot pin 1 and 3 to the power supply and pin 2 (the wiper) to the analog input?


Yes I was, the serial.Println showed a constant high number output, and the value only dropped at the very end/beginning of the potentiometer rotation.

jackrae

Unlike a conventional pot, pin 2 (the wiper) is not the centre connection.

MarkT

Test the potentiometer with a multimeter if its not marked - my 10-turn pot has the connections clearly marked.  The wiper connection will probably be at the rear-end of the housing as it goes to the spindle.

In general in electronics it pays to check everything before applying power - don't assume what you can actually check (with the datasheet or a multimeter)
[ I won't respond to messages, use the forum please ]

Drc3p0

K, got the right output from it now, I soldered some leads to the potentiometer instead of using alligator clips and that seemed to help.  It reads pretty smoothly, except when it gets to the end of the turn, when the Serial.print output is high, it jumps from the 200's up to the 600's very rapidly.  should I add a resistor to it to prevent this number jump at the end of the turns?  I reversed the polarity and it does the same number jump as well. 

Drc3p0

#6
Aug 07, 2012, 03:06 am Last Edit: Aug 07, 2012, 03:10 am by Drc3p0 Reason: 1
The 10-turn potentiometer is B100k.  I tested the sketch with a standard single-turn B100k potentiometer, and the number output didn't jump at the end like how the 10 turn does, and had a very smooth and consistent output that didn't jump around at all.  here's an example of the serial output from the 10-turn potentiometer to show what I mean...
I am using the 5v on-board power source with an 18k resistor between 5v and pin 3.
Code: [Select]

sensor = 345 output = 85
sensor = 330 output = 82
sensor = 325 output = 81
sensor = 334 output = 83
sensor = 328 output = 81
sensor = 317 output = 79
sensor = 313 output = 78
sensor = 324 output = 80
sensor = 323 output = 80
sensor = 327 output = 81
sensor = 332 output = 82
sensor = 339 output = 84
sensor = 319 output = 79
sensor = 275 output = 68
sensor = 327 output = 81
sensor = 324 output = 80
sensor = 326 output = 81
sensor = 302 output = 75
sensor = 306 output = 76
sensor = 312 output = 77
sensor = 863 output = 215       //
sensor = 606 output = 151       // this is where the dramatic jump is happening.  this is at the very end of the wiper path, and
sensor = 240 output = 59        // occurs at about the last 20 degrees of the wiper path.
sensor = 234 output = 58       //
sensor = 980 output = 244      //
sensor = 979 output = 244     //
sensor = 978 output = 243     //
sensor = 978 output = 243
sensor = 975 output = 243
sensor = 972 output = 242
sensor = 973 output = 242
sensor = 971 output = 242
sensor = 976 output = 243
sensor = 975 output = 243
sensor = 976 output = 243
sensor = 978 output = 243
sensor = 943 output = 235
sensor = 949 output = 236
sensor = 943 output = 235
sensor = 943 output = 235



Drc3p0

Well, I was not sure what all the jitter was with the output from the 10-turn potentiometer, but I have solved the problem by utilizing smoothing, calibration, and mapping the incoming signal.  here is the code i've used:
Code: [Select]




// Define the number of samples to keep track of.  The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input.  Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
const int numReadings = 10;

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average
int inputPin = A3;

int outputValue = 0;        // value output to the PWM (analog out)
const int analogOutPin = 9; // Analog output pin that the LED is attached to

void setup()
{
  // initialize serial communication with computer:
  Serial.begin(9600);                   
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;         
}

void loop() {
  // subtract the last reading:
  total= total - readings[index];         
  // read from the sensor: 
  readings[index] = analogRead(inputPin);
  // add the reading to the total:
  total= total + readings[index];       
  // advance to the next position in the array: 
  index = index + 1;                   

  // if we're at the end of the array...
  if (index >= numReadings)             
    // ...wrap around to the beginning:
    index = 0;                           

  // calculate the average:
  average = total / numReadings;         
  // send it to the computer as ASCII digits
 
    // limits range of sensor values to between 0 and 500 
  average = constrain(average, 0, 500);
    // map it to the range of the analog out:
  outputValue = map(average, 0, 500, 0, 255);
   // change the analog out value:
  analogWrite(analogOutPin, outputValue);
 
  Serial.print("outputValue =");
  Serial.print(outputValue);
  Serial.print("\t average =");
  Serial.println(average); 
 
  delay(2);        // delay in between reads for stability           
}

MarkT

Given the relatively high impedance of the pot you could electrically smooth the output with say a 10n or 100nF cap between wiper and ground - any noise from poor contact of the wiper on the track should be reduced, and the noise-immunity of the signal improved too.  For best results place the cap near the Arduino analog input rather than at the pot's wiper.
[ I won't respond to messages, use the forum please ]

Drc3p0


Given the relatively high impedance of the pot you could electrically smooth the output with say a 10n or 100nF cap between wiper and ground - any noise from poor contact of the wiper on the track should be reduced, and the noise-immunity of the signal improved too.  For best results place the cap near the Arduino analog input rather than at the pot's wiper.


good point!  i will definitely utilize this...

Docedison

I am curious about "Mapping" 10000 (100,000 ohms /10 turns) discrete values into 10 bits of available resolution, one turn would have 10 discrete values. If you look at the portion of a "Turn" that can be reported successfully. It would appear that you have large sections of the Pot that are questionable given the granularity of the available precision at 10 bits of resolution and as far as I can see worthless at 8 bits of data.
I  would think that a 10000 ohm 10 turn pot would be more appropriate if still not overkill or just more data that available resolution... Given the restrictions imposed by floating point variables and the available resolution of the A/D converter.

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

michael_x

#11
Aug 07, 2012, 06:22 pm Last Edit: Aug 07, 2012, 07:46 pm by michael_x Reason: 1
Quote
10 bits of available resolution, one turn would have 10 discrete values


???

10 bits resulution is 0 .. 1023  -->   1 of 10 turns would cover about 100 values or ideally a different value every 4 degrees.

Mapping that down to 8 bit ( 0 .. 255 ) means a different value every 15 degrees.

Sure, 100 k is a bit high for 5 V , a total current of 50 µA is  not too robust against external noise.
The operation of the AD converter already affects it. That 100nF cap would nicely feed the ADC with some more stable voltage.
Quote
10000 ohm 10 turn pot would be more appropriate  
Yes.

Quote
restrictions imposed by floating point variables
Who needs floating point variables when there's a nice integer range 0 .. 1000 coming from an ADC ???


The 10-turn potentiometer is B100k.  ....
I am using the 5v on-board power source with an 18k resistor between 5v and pin 3.
Either I don't understand or this 18k resistor is nonsense, making your 100k pot very non-linear ...
A simple scheme,please,  Drc3p0 ? ...

Edit: reply to two different posts

Docedison

No, Possibly I misspoke from ignorance of the value returned by analog in and the issues involved in conversion and based on that mistake spouted that nonsense involved in the amount of data returned per degree of rotation/turn that I was trying to get to... I should Never sit here and read the mail before my first cup of Coffee. I do Apologize. And the 10 K pot would be the best way to go.

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Drc3p0




Either I don't understand or this 18k resistor is nonsense, making your 100k pot very non-linear ...
A simple scheme,please,  Drc3p0 ? ...



It's probably nonsense...I was just playing around with it when I was trying to restrict the value from jumping at the end of the wiper path...it's not necessary.

Docedison

That measured "Jump" at the end is the beginning of the eleventh turn old school knobs for them were Vernier counters and stops at exactly ten turns so the pot never goes there, It''s gear limited to that number of turns. real Old school now with digital pots... Much more predictable. easier to change quickly. They can be used for linear distance measurement but the gearing must never be allowed to exceed Ten Turns. Work Well too.

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Go Up