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

Thread: Multiplexing Issue

  1. #1

    Multiplexing Issue

    Hey Hey!
    I started to experiment with a multiplexer (4051) to add more analog ins to my teensy project. I use the Analog-Digital Multiplexer Library and it works in a way. I just figured out that some pots are slighty changing values that they shouldn´t change. I am using teensy 4.1 here. The only thing is I just have 100k pots atm. Could this be an issue? Here is the code with just the multiplexer thing. I first thought it was an issue of my main programm which just has more stuff but it also happens in this stripped down code.

    Code:
      #include <Mux.h>
    
    using namespace admux;
    
    int PotA = 0;
    
    Mux mux(Pin(A13, INPUT, PinType::Analog), Pinset(1, 2, 3));
    
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop () {
      int data;
      for (byte i = 0; i < mux.channelCount(); i++) {
        data = mux.read(i);
        Serial.print(data);
        Serial.print("  ");
      }
      sendTest();
      Serial.println();
    
    }
    
    void sendTest() {
      Serial.print("PotA = ");
      Serial.print(mux.read(0));
      
    }
    in void sendTest() I just tested if I can read the pot values in different voids. Strangely (or maybe not strangely) the value of potA in this sendTest() is different from the one out of the for loop. It seems to be more accurate...
    Last edited by Krischomat; 08-12-2021 at 05:39 PM.

  2. #2
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    822
    A Teensy 4.x and 3.x are much too fast for that library to be used without adding a delay between switching address pins and reading the signal pin. The usbMIDI reference page recommends starting with a delay of 50 microseconds. This is more than enough for most multiplexers, so after making sure everything is working you can experiment with shorter delays.
    Code:
      for (byte i = 0; i < mux.channelCount(); i++) {
        mux.channel(i);
        // allow 50 us for signals to stablize
        delayMicroseconds(50);
        data = mux.read();
        Serial.print(data);
        Serial.print("  ");
      }

  3. #3
    Great! That already helped! Thx! =) Somehow I needed to add another delay function in a void where a pot is controlling a parameter since this one knob still has an influence on another parameter... Now it is much more stable. There is still the thing, which I already had before I used a multiplexer, that when a pot is turned completly open there was a drop/ change in lots of different parameters. When I move the pot away from beeing fully open it goes back. Could it also be an issue with to big pot sizes (100k)? Also I read that putting a small capacitor from the analog in to ground helps. Is that true for a multiplexer input? Or does it not work since the voltage changes are so fast?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,081
    Pot values from 1K to 10K are best.

    Do not add the capacitor at Teensy's analog pin if you're multiplexing! Adding it at the mux output or Teensy input will make the problem even worse.

    You can add capacitors, and they might even help, but you need a separate capacitor for each pot. They need to be located either at the mux inputs or at the pots.

  5. #5
    Thanks! Yes makes sense to not put a capacitor to the teensys analog pin while multiplexing! Will try what happens when I use them at the 4051s Inputs. =)

Posting Permissions

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