How often can I poll an analoge input?

So I have a linear actuator with a 10k pot for feedback. I am trying to isolate the source of error, how much is mechanical, how much is electrical, and how much is the Arduino etc. Now to see how long it takes from me sending a stop command to the feedback settling, I wrote a simple piece of code that reads extends the arm and tells me its position reading, looping as fast as it can. It then sends a stop command (directly turns off a relay) and stops feeding serial data and just collects feedback data every 10mS and saves it. After taking 20 readings it spits them out over serial, reverses direction and starts giving me data again. The data has a strange behavior. it stops as expected, and is perfectly stable during the 20 readings. when the next reading comes about 300mS later, it has dropped significantly. the next reading after this is slightly higher than the stable reading, and then starts dropping off as expected with the actuator retreating. Is reading the analog intput every 10 mS too often? am I violoating some obvious rule of proper analoge readings? I am going to add a capacitor to the input as close to the board as possible.

Below is my sketch and I will attach a plot. The blue spike is where the Relay was switched off, you can see the points get closer together on the plot since the readings are coming faster now. Any feedback would be welcome.

int MIN_LAC_POS = 110;
int MAX_LAC_POS = 330;
int LAC_MIN_USEFUL = 570;
int pwrRelay = 23;      //pin: out for on
int dirRelay = 22;      //pin: out for direction
int feedbackPin = 0;    //pin: in for feedback //takes 100 micro seconds to read analog
int feedback;

void setup(){
  Serial.begin(9600);
  pinMode(pwrRelay, OUTPUT);
  pinMode(dirRelay, OUTPUT);
  digitalWrite(pwrRelay, HIGH);    //low is on
  digitalWrite(dirRelay, LOW);    //low is extend by making red +??  
}

void loop(){
  boolean extend=true;
  update();
  
  while (extend && feedback<MAX_LAC_POS)  {
    digitalWrite(dirRelay, HIGH);
    digitalWrite(pwrRelay, LOW);
    Serial.print(millis());
    Serial.print(" ");
    Serial.print(extend);
    Serial.print(" ");
    Serial.print(feedback);
    Serial.print(" ");
    Serial.println(millis());
    update();
  }
  int time[40];
  int pos[40];
  Serial.print("halt ");
  Serial.println(millis());
  
  digitalWrite(pwrRelay, HIGH);
  for (int i=0; i<40; i++)  {
    time[i]=millis();
    pos[i]=analogRead(feedbackPin);
    delay(10);
  }
  
  Serial.println("saved info");

  for (int i=0; i<40; i++)  {
    Serial.print(time[i]);
    Serial.print(" ");
    Serial.println(pos[i]);
  }
    
  while (feedback>MIN_LAC_POS)  {
    digitalWrite(dirRelay, LOW);
    digitalWrite(pwrRelay, LOW);
    Serial.print(millis());
    Serial.print(" ");
    Serial.print(extend);
    Serial.print(" ");
    Serial.print(feedback);
    Serial.print(" ");
    Serial.println(millis());
    update();
  }
}
 
int update(){
   feedback = analogRead(feedbackPin);
   return feedback;
}

plot.png

plotbig.png

The ADC will support readings about every 100uS for full 10 bit resolution.

Hi,

  1. Please post your code using the # button instead of as a quote, so that instances of things like [ii] don't dissappear as has happened in this case.

  2. Are you using a common ground wire for both the actuator and the pot? I recommend that you dedicate one of the Arduino ground pins as "analog ground". Connect the ground side of the pot and any other sensors to analog ground, and use different ground pins for power and the ground sides of any outputs. That avoids ground currents of switched devices interfering with the value read by the ADC. However, the effect you are looking at is larger than I would expect from this cause.

cross roads, that's kinda what I figured. I was looking in the datasheet and it sure seems capable of charging up no problem. Heck my pot just happens to be exactly what the ADC wants, as it's designed for a 10k or less ohm source.

I am going to tweak the sketch so it just reads every 10mS beginning to end, so I can see where those jumps come from. maybe it's noise, maybe its the motor coming back on. My wiring is very convoluted, they are very well seperated on the power side of things, opto-isolated relay triggers etc, but there is a common ground bus right outside of everything that goes back ot the battery with a 16 guage wire. but grounds are separate for as long as possible.