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

Thread: Strange behaviour on potentiometers

  1. #1
    Senior Member
    Join Date
    Nov 2016
    Posts
    182

    Strange behaviour on potentiometers

    Hi

    I have wired some 10k potentiometers and slide-potentiometers (faders) to my mux-board. Now both, the pots and the faders make some "noise" (?) .. the SerialMonitor goes like:
    faderTrackVolume1 - 9
    faderTrackVolume1 - 14
    faderTrackVolume1 - 9
    faderTrackVolume1 - 14
    faderTrackVolume1 - 9
    faderTrackVolume1 - 15
    faderTrackVolume1 - 10
    faderTrackVolume1 - 15
    faderTrackVolume1 - 9
    faderTrackVolume1 - 14
    faderTrackVolume1 - 9
    faderTrackVolume1 - 14
    faderTrackVolume1 - 9
    faderTrackVolume1 - 15
    faderTrackVolume1 - 9
    faderTrackVolume1 - 15
    faderTrackVolume1 - 10
    faderTrackVolume1 - 15
    faderTrackVolume1 - 10
    faderTrackVolume1 - 15
    beside that noise, every pot has a different starting point.. oO .. I mean, when I turn all to where 0 should be, on one pot it is 12, on other something else..

    this can't be normal, can it?


    These are my mux functions:

    Code:
    void pollCtrl() {
      for (int i = 0; i <= 15; i++) {
        // count through MUX
        digitalWrite(cfg.muxPinInh, HIGH);
        cfg.MuxBit1 = bitRead(i, 0);
        cfg.MuxBit2 = bitRead(i, 1);
        cfg.MuxBit3 = bitRead(i, 2);
        digitalWrite(cfg.muxPin1, cfg.MuxBit1);
        digitalWrite(cfg.muxPin2, cfg.MuxBit2);
        digitalWrite(cfg.muxPin3, cfg.MuxBit3); 
        digitalWrite(cfg.muxPinInh, LOW); 
        delayMicroseconds(40);
        
        // 4051 pins 0-7 btnTrackSelect
        if(i >= 0 && i <= 7) {
          pollMuxDigital(i, "btnTrackSelect", cfg.btnTrackSelectPin);  
        } 
        // 4051 pins 8-15 faderTrackVolume
        if(i >= 8 && i <= 15) { 
          pollMuxAnalog(i-8, "faderTrackVolume", cfg.faderTrackVolumePin);   // these are my pots right now for debug, so don't be irritated by name "fader.."
        }   
         
      }
    }
    
    
      /*
       Polls 4051 with digital Input-Sources
      */
      void pollMuxDigital(int i, String element, int digitalPin) {   
        btnTrackSelect[i].btnStatus = digitalRead(cfg.btnTrackSelectPin);  
        if (btnTrackSelect[i].btnStatus == HIGH && btnTrackSelect[i].btnStatusOld != btnTrackSelect[i].btnStatus) {    
            if(cfg.shiftStatus == true) {   
              // trackSelect() 
              Serial.print("-> TrackSelect(): "); Serial.print(i); Serial.println();
            } else {
              // muteTrack()
              Serial.print("# MuteTrack(): "); Serial.print(i); Serial.println();
            }
        }
        btnTrackSelect[i].btnStatusOld = btnTrackSelect[i].btnStatus;  
      }
    
    
    
       /*
       Polls 4051 with analog Input-Sources
      */
      void pollMuxAnalog(int i, String elementName, int analogPin) {
        // int h = analogRead(analogPin);      
        // faderTrackVolume[i].faderValue = 0.6 * faderTrackVolume[i].faderValue + 0.4 * map(h,0,1023,0,127); // smoothing
        // faderTrackVolume[i].faderValue = map(analogRead(cfg.faderTrackVolumePin),0,1023,0,127);
        faderTrackVolume[i].faderValue = analogRead(analogPin);
        if( abs(faderTrackVolume[i].faderValue - faderTrackVolume[i].faderValueOld) > 4) {    
           Serial.print(elementName); Serial.print(i);         
           Serial.print(" - ");
           Serial.print(faderTrackVolume[i].faderValue);         
           Serial.println("");  
           faderTrackVolume[i].faderValueOld = faderTrackVolume[i].faderValue;
          }     
      }

    Click image for larger version. 

Name:	20180502_140232.jpg 
Views:	58 
Size:	108.5 KB 
ID:	13713

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,379
    have you tried a higher resolution? analogReadResolution(12); ? (0-> 4095)

  3. #3
    Senior Member
    Join Date
    Nov 2016
    Posts
    182
    Quote Originally Posted by tonton81 View Post
    have you tried a higher resolution? analogReadResolution(12); ? (0-> 4095)
    Hi, I just tried that.. still the same.. the pots are very noisy.

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,910
    Have you tried a longer delay? - 40 us might be too less. Perhaps try 10ms (delay(10)) ;

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,583
    Are you really using unshielded wires for the potentiometers in a digital environment???

  6. #6
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,583
    Some bedtime lecture about considering source impedance and noise when working with ADCs: https://cache.nxp.com/docs/en/applic...ote/AN5250.pdf

  7. #7
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,348
    Quote Originally Posted by Frank B View Post
    Have you tried a longer delay? - 40 us might be too less. Perhaps try 10ms (delay(10)) ;
    The apparent oscillation between about 10 and about 14 makes me wonder if your getting some interference from the mux... OR you are actually reading two different pins because of a mux control error.

    To eliminate the latter (which I hope is unlikely) set the pot your are monitoring to one extreme value and all other to the other. If the pins are getting mixed up the signal would oscillate over a the full range (or near it).

    ...failing to hit edges (extrema) could be poor wiring but MUX interference between readings is also a possible cause.. (if it diminishes/vanishes when all pots are in the same extrema then it's almost certainly mux crosstalk)

    That said 40 uS would be plenty for the mux I've played with.

    ...higher resolution will only show the noise/signal more accurately.


    And after all that, some noise on a pot is just how it is and all that wire will make even the eighth bit unstable.

    This topic has been beaten to death but it's never going away. My take is... a 270 degree pot is a low-rez, low-frequency control. Noise anywhere but in sub 100 Hz range is easily filtered out digitally. Expecting 10 bits, let alone more, is unrealistic. You might be able to use 8 or 9.

    If you have some multi-turn, high-end pot then you can shield and maybe filter in the analog domain but for user interface such things are complete overkill. (@Thiery... nice reference!)

    For MIDI projects (which is where a good many of the 'my pot won't play nice' threads start) and other human-interface uses the library ResponsiveAnalogRead() is more than adequate to handle this issue for you unless you are really keen on writing one yourself (search 'deadband' for some examples).

  8. #8
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    621
    With pots for volume control I had good experience with a software exponential averager:

    Volume = old_Volume * alpha + (1-alpha) * new_Volume_from_ADC;

    old_Volume = Volume;

    but you probably know about that.

    My alpha was < 0.9, but that depends on how fast you read your pots.

    All the best,

    Frank

  9. #9
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,348
    The alpha on a simple low-pass can be very large fraction (approaching unity) when the effective sample 'rate' is very, very high compared to the motion of human fingers and it will work even if there is a lot of jitter (from the code not polling at stable intervals).

    But I've only used this kind of filter with floating point values and I'm not sure how well it works with fixed point values. (https://www.mathworks.com/help/dsp/e...r-filters.html)

    With fixed-point values windowed averages and dead-band hysteresis can achieve a similar end.

  10. #10
    Senior Member
    Join Date
    Nov 2016
    Posts
    182
    Quote Originally Posted by Theremingenieur View Post
    Are you really using unshielded wires for the potentiometers in a digital environment???
    yes :/
    I had asked in a other forum before I wired it this way and some folks told me that wired do not matter :/

    I wired some test-pots on a breadboard and wired them to the first 4 inputs of the mux.. still some noise but not that much as with the long wires..
    can you suggest a good thickness/type for wires?

  11. #11
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,379
    hmm averaging or lowest, or perhaps getting the variance of the output, you’ll get more meaningful steady value based on your wiring, you might consider that if needed, and if so, it already exists on teensy

  12. #12
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,348
    It only dawns on me now this is a fragment from an audio project.

    Then the low-pass IIR filter (DD4WH's post) is likely the way to go once you're sure you're not getting cross-talk or errors from the MUX. If it's just HF noise you should be able to filter it out digitally.

    You should be able to have a very aggressive filter without making feel like it lags.

  13. #13
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,583
    I still tend to insist on the idea that it is the better practice to design noise immune circuitry instead of accepting for example that wild wiring without impedance matching and shielding captures lots of noise which had then to be filtered away again. Why not solder pots and faders onto a dual layer PCB with huge ground planes?
    Multiplexing is another source of problems because an external multiplexer is always in series with the Teensy’s internal pin MUX. Thus, unity gain op amps, optionally in a Sallen-Key low pass configuration as buffer for each external MUX output are a must in my eyes.
    Simpler solutions might sometimes work for hobby or one shot products, but the noise immunity would not be guaranteed in a rough environment, for example on stage with dimmed light spots creating important stray fields.

  14. #14
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,348
    I don't disagree with anything you're saying and audio requires a lot more diligence than mere MIDI controllers.

    Mains hum can't be easily filtered since it's very low frequency too.

    But the oscilation noted in the signal is (implicitly) at a very high frequency that can be easily filtered IF that's the only problem.

    edit - I'm out of my depth... ignore me!
    Last edited by oddson; 05-03-2018 at 12:58 AM.

  15. #15
    Senior Member
    Join Date
    Nov 2016
    Posts
    182
    Quote Originally Posted by Theremingenieur View Post
    I still tend to insist on the idea that it is the better practice to design noise immune circuitry instead of accepting for example that wild wiring without impedance matching and shielding captures lots of noise which had then to be filtered away again. Why not solder pots and faders onto a dual layer PCB with huge ground planes?
    hi

    yes that is definetly what I want, and I already startet deigning a PCB with KiCad.. but as this is my second project, I would like to have a functionable Protootype first..
    but maybe some questions:

    - when I design a PCB, is it a good idea to generally put some huge GND-/Vcc-lanes? Or can it be too much at some pont?
    - how would I make my noob-circiut immune ? what kind of wires should I use? is there more I can do except using more shielded wires?

  16. #16
    Hi.
    I'm no ee but as a mad hobbyist I've played with a few things like this. Analog can be tricky. A couple of ideas - the fact you cannot get to zero suggest voltage drop on the pot supply leads. how are you returning your grounds?

    If your pots share power with other devices like the mux they will pick up noise on the supply lines. Ensure the ground return leads from the pots are nice and heavy and go directly to teensy ground (and use that as a point source earth, as close to the teensy as you can get). Do something similar for positive power to the pots.

    If the pots are low value, check your power supply is beefy enough. If your pots are high value, remember to earth the metal bodies of the pots too (with their own ground).

    You will get noise. Real-life systems always have some. We can deal with it and perhaps not need shielding. Small value capacitors (10 - 100 nF thereabouts, ceramic are fine) between signal and ground on each of the inputs to your mux will deal with some of the radiated noise pickup and software like the low-pass IIR filter mentioned can do the rest.

    Keep the adc sample rate high so even heavy filters can provide the result in a timely fashion and one does not seem to notice the lag.

    This is just my hobby so I cant assure you that any of these things will work, this is only what I might try next myself.

    Cheers!
    Prickle

  17. #17
    Senior Member
    Join Date
    Nov 2016
    Posts
    182
    Quote Originally Posted by prickle View Post
    Hi.
    I'm no ee but as a mad hobbyist I've played with a few things like this. Analog can be tricky. A couple of ideas - the fact you cannot get to zero suggest voltage drop on the pot supply leads. how are you returning your grounds?
    Hi, what do you mean by "return" ? I don't understand that :/

    Quote Originally Posted by prickle View Post
    If your pots share power with other devices like the mux they will pick up noise on the supply lines. Ensure the ground return leads from the pots are nice and heavy and go directly to teensy ground (and use that as a point source earth, as close to the teensy as you can get). Do something similar for positive power to the pots.
    At the moment the Teensy sticks in a breadboard, two wires(Vcc/GND) lead to my prototyping-mux-board where both supply a thick lead. From this leads every component (mux, pots, switches) take their supply.

    Quote Originally Posted by prickle View Post
    If the pots are low value, check your power supply is beefy enough. If your pots are high value, remember to earth the metal bodies of the pots too (with their own ground).
    that is a good idea.. I will measure the both lanes Vcc/GND

  18. #18
    Senior Member
    Join Date
    Nov 2016
    Posts
    182
    Ok I have now re-factored the mux-board step by step, using a bit thicker wires.

    Click image for larger version. 

Name:	20180504_213543.jpg 
Views:	39 
Size:	65.9 KB 
ID:	13742
    Click image for larger version. 

Name:	20180504_213610.jpg 
Views:	46 
Size:	102.8 KB 
ID:	13743

    .. first one mux.. test with switchbuttons (digitalRead)... runs perfectly
    .. then attached potentiometers insteas of buttons (analogRead).. runs like a charm

    I thought all my problems solved... but ..

    .. I attached the second mux and connected the buttons to the second mux
    .. now I test the second mux and something very strange happens.. when press button-0 it is recognized on IN0 and IN4 of the mux ..oO .. the button-1 is recognized on IN1/IN5, .. button-2 and button-3 seem not to be recognized at all .. button-4 is on IN0/IN4 .. button5 on IN1/IN5 .. button6 is recognized on IN2/IN6 .. and button7 on IN3/IN7

    what the hell? oO .. I checked multiple times if I connected it correctly.. all seems fine..

    this is my code:

    Code:
    void loop() {
      pollShift();
      pollCtrl();  
    
    }
    
    void pollCtrl() {
    
      for (int i = 0; i <= 15; i++) {
        // count through MUX
        digitalWrite(cfg.muxPinInh, HIGH);
        cfg.MuxBit1 = bitRead(i, 0);
        cfg.MuxBit2 = bitRead(i, 1);
        cfg.MuxBit3 = bitRead(i, 2);
        digitalWrite(cfg.muxPin1, cfg.MuxBit1);
        digitalWrite(cfg.muxPin2, cfg.MuxBit2);
        digitalWrite(cfg.muxPin3, cfg.MuxBit3); 
        digitalWrite(cfg.muxPinInh, LOW); 
        delayMicroseconds(60);
        
        // 4051 pins 0-7 potis
        if(i >= 0 && i <= 7) { 
          pollMuxAnalog(i, "faderTrackVolume", cfg.faderTrackVolumePin);   
        }   
        // 4051 pins 8-15 buttons
        if(i >= 8 && i <= 17) {
          pollMuxDigital(i-8, "btnTrackSelect", cfg.btnTrackSelectPin);  
        } 
       
      }
    }
    
    
    
      /*
       Polls 4051 with digital Input-Sources
      */
      void pollMuxDigital(int i, String element, int digitalPin) {   
        btnTrackSelect[i].btnStatus = digitalRead(cfg.btnTrackSelectPin);  
        if (btnTrackSelect[i].btnStatus == HIGH && btnTrackSelect[i].btnStatusOld != btnTrackSelect[i].btnStatus) {    
            if(cfg.shiftStatus == true) {   
              // trackSelect() 
              Serial.print("-> TrackSelect(): "); Serial.print(i); Serial.println();
            } else {
              // muteTrack()
              Serial.print("# MuteTrack(): "); Serial.print(i); Serial.println();
            }
        }
        btnTrackSelect[i].btnStatusOld = btnTrackSelect[i].btnStatus;  
      }
    
    
       /*
       Polls 4051 with analog Input-Sources
      */
      void pollMuxAnalog(int i, String elementName, int analogPin) { 
       
        if(elementName == "faderTrackVolume") {
          analog_faderTrackVolume.update();
          faderTrackVolume[i].faderValue = analog_faderTrackVolume.getValue();      
          if(abs(faderTrackVolume[i].faderValue - faderTrackVolume[i].faderValueOld) > 3) {    
            Serial.print(elementName); Serial.print("["); Serial.print(i); Serial.print("]");        
            Serial.print(" = ");
            Serial.print(faderTrackVolume[i].faderValue);         
            Serial.println("");  
            faderTrackVolume[i].faderValueOld = faderTrackVolume[i].faderValue;
            }
        }  
       
      }
    Is someone able to make a diagnosis remotly?

Posting Permissions

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