Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: analogRead potentiometer jitter help

  1. #1

    analogRead potentiometer jitter help

    Hello. I'm trying to analogRead a 10K potentiometer. The results are not steady. The last value is jittering, for example between 3459 and 3460. I'm using the 3.3V at the bottom of the Teensy 3.1 and the AGND near the upper right. The pots center wiper is going into pin 18. I also have a 100nF ceramic cap from pin 18 to AGND. This Teensy has its 5V pads cut apart and is externally powered with this 5.25V psu:

    https://www.adafruit.com/products/50...FQ8OOgod9F4AJQ

    Windows 7, Arduino 1.6.11, Teensyduino 1.30

    Is there anything I can do to stabilize these readings? Is it possible to get steady values from this setup and resolution or am I asking too much? Any ideas or tips would be greatly appreciated. Thanks!

    Click image for larger version. 

Name:	circuit.jpg 
Views:	361 
Size:	82.0 KB 
ID:	8782


    PHP Code:
    const int SpeedPotPin 18;
    int SpeedPot 0;

    void setup(){

      
    Serial.begin(9600);
      while(!
    Serial);
      
      
    pinMode(SpeedPotPinINPUT);

      
    analogReadResolution(12);
      
    analogReadAveraging(32);

    }

    void loop(){
      
      
    SpeedPot analogRead(SpeedPotPin);
      
    Serial.print("Speed Pot:");Serial.println(SpeedPot);
      
    delay(100);
                                                


  2. #2
    Senior Member Jp3141's Avatar
    Join Date
    Nov 2012
    Posts
    461
    You are asking too much.

    1) The ADC can always have a jitter of +/- 1 count -- imagine the input voltage is just on the border between two conversion codes -- depending on noise etc, it might return one or the other value.

    2) The pot isn't that stable (or repeatable) -- why does the jitter in your results affect your system ?

    3) How long are your wires ? Are you actually picking up 50/60 Hz noise that the ADC is correctly converting ?

    4) The cap might or might not help. In your code, the ADC's reference is the 3.3 V supply. If there is noise on it (0.25 mV would cause the issue you are seeing), then the ADC will have noise on its reference, but the wiper input (pin 18) has the filtered signal -- therefore the conversion will be noisy because the noise in the reference (3.3 V) isn't reflected in the pot voltage. in theory you'd be better off removing that cap. However the ADC does need some capacitance at the conversion input pin -- you might find a smaller capacitance is better.

  3. #3
    Quote Originally Posted by Jp3141 View Post
    You are asking too much.

    1) The ADC can always have a jitter of +/- 1 count -- imagine the input voltage is just on the border between two conversion codes -- depending on noise etc, it might return one or the other value.

    2) The pot isn't that stable (or repeatable) -- why does the jitter in your results affect your system ?

    3) How long are your wires ? Are you actually picking up 50/60 Hz noise that the ADC is correctly converting ?

    4) The cap might or might not help. In your code, the ADC's reference is the 3.3 V supply. If there is noise on it (0.25 mV would cause the issue you are seeing), then the ADC will have noise on its reference, but the wiper input (pin 18) has the filtered signal -- therefore the conversion will be noisy because the noise in the reference (3.3 V) isn't reflected in the pot voltage. in theory you'd be better off removing that cap. However the ADC does need some capacitance at the conversion input pin -- you might find a smaller capacitance is better.
    Hi, Jp. Thanks for answering!

    1) I see, this makes sense. There will always be some tiny threshold that will cross over and round to a different value and jitter the last place. Is there a way to program this out? Maybe raise the bit resolution read at the pin and then scale back in code and somehow remove that last place number jitter?

    2) My setup is controlling a motor's speed. A PWM duty cycle output from the Teensy controls the speed. This spins a capstan that passes audio tape. Jittering motor speed could possibly be audible in pitch changes with the audio tape. It would be ideal if the pot would change the speed smoothly and sit stable when not being turned. From researching audio, when tape speed doubles the pitch goes up one octave. Humans' smallest hearing JND (just noticeable difference) is around 0.5% at the 2000 Hz range.

    3) Right now my wires are about 12" long 22 AWG stranded. After testing and then final assembly they could be shortened to 6" or so.

    4) Yes, I see now. Thank you. I'll try a smaller cap here. Any size recommendation?

    Thanks for your time. Happy Holidays!

  4. #4
    Senior Member Jp3141's Avatar
    Join Date
    Nov 2012
    Posts
    461
    1) jitter: you can't easily remove this. If you 'just' remove the last bit, you'll still have errors when the result crosses the next-to-last. For instance, say the numbers were 1..1000, and you had 567/568 -- you could remove the last digit and have just 560 steadily. but, say the code was 599/600 -- you'd still jitter between 590 and 600. You could low-pass filter the data. That would reduce, but not eliminate the jitter. It would also slow down the reaction time to a change in the position. You could add hysteresis -- if you detect a value different from the last, only change the output if it differs by more than a certain amount (say 5 counts). That may make fine adjustments difficult, so you could try dynamically adjusting the hysteresis -- set the delta to be 5, but if a change occurs, set it to 1 or 0 for a few seconds etc.

    2) A low-cost pot is probably not stable enough to maintain that level of accuracy. You can get 10-turn potentiometers.

    4) 0.1 uF is good when you are guessing !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •