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

Thread: Teensy 4.0 Audio Project Multiplexer Wiring Help

  1. #1

    Teensy 4.0 Audio Project Multiplexer Wiring Help

    Hey guys, not specifically related to the Audio stuff with the Teensy, but everyone here has been super helpful in the past so I was wondering if anyone could help with my multiplexer wiring:

    Click image for larger version. 

Name:	V0Q6i4e.jpg 
Views:	45 
Size:	70.7 KB 
ID:	21681

    I can't really explain the behaviour I'm seeing, but the values being read from the multiplexer are not right. Sometimes clicking a button will set off other multiplexer inputs. If I only have one input wired it seems to work fine, but I'll get pretty crazy random readings from the other input pins (even with nothing connected to them) as soon as I add multiple buttons. I don't think theres any problem with the code or my inputs because when I directly wire inputs into the A2 pin it reads normal. I grabbed some resistors at a store today, in wirings I've seen online it looks like they sometimes use resistors but I'm not sure if that's a problem or how I would even determine what value resistor to use.

    It is a CD74HC067, and the T4 in the diagram refers to the teensy

    Any help would be much much appreciated!! Thanks

  2. #2
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    642
    If I had to hazard a guess without seeing the code you probably don't have a sufficient enough delay between switching the address pins and reading the input pins.

  3. #3
    Quote Originally Posted by vjmuzik View Post
    If I had to hazard a guess without seeing the code you probably don't have a sufficient enough delay between switching the address pins and reading the input pins.
    thanks for the quick reply, i'm using a delay of 5000 microseconds, does that sound too fast?

  4. #4
    heres my code:

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Bounce.h>
    
    //MUX
    int signalPin = A2;
    int s0 = 1;
    int s1 = 2;
    int s2 = 3;
    int s3 = 4;
    
    float vals[16] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
    
    int muxChannel[16][4]={
      {0,0,0,0},
      {0,0,0,1},
      {0,0,1,0},
      {0,0,1,1},
      {0,1,0,0},
      {0,1,0,1},
      {0,1,1,0},
      {0,1,1,1},
      {1,0,0,0},
      {1,0,0,1},
      {1,0,1,0},
      {1,0,1,1},
      {1,1,0,0},
      {1,1,0,1},
      {1,1,1,0},
      {1,1,1,1}
    };
    
    void setup() {
      
      //MUX
      pinMode(s0, OUTPUT); 
      pinMode(s1, OUTPUT);
      pinMode(s2, OUTPUT);
      pinMode(s3, OUTPUT);
      pinMode(signalPin, INPUT);
      pinMode(otherSig, INPUT);
    
      digitalWrite(s0, LOW); 
      digitalWrite(s1, LOW);
      digitalWrite(s2, LOW);
      digitalWrite(s3, LOW);
    }
    
    void loop() {
      
      for (int i=0; i<16; i++) {
        digitalWrite(s0,muxChannel[i][0]);
        digitalWrite(s1,muxChannel[i][1]);
        digitalWrite(s2,muxChannel[i][2]);
        digitalWrite(s3,muxChannel[i][3]);
        delayMicroseconds(5000);
        int readVal = analogRead(signalPin);
    
        if (readVal > vals[i] + 150 || readVal < vals[i] - 150) {
          Serial.print("Channel ");
          Serial.print(i);
          Serial.print(": ");
          Serial.println(readVal);
          Serial.print("Old val: ");
          Serial.println(vals[i]);
          vals[i]=readVal;
        }
    }

  5. #5
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    642
    That should be more than enough actually, based on the data sheet that chip at the most should only take 450 nanoseconds, my second guess would be that your enable pin appears to be tied to 5v per your schematic. You also have it being powered from 5v, a Teensy 4.x is not 5v tolerant so you should really move that to 3.3v before anything happens. The enable line is active low so if you don't plan on adding any more multiplexer chips you should have it connected to ground, as far as resistors go I don't remember if you specifically have to add them to the buttons or if you can just INPUT_PULLUP the signalPin.

  6. #6
    Senior Member
    Join Date
    Apr 2020
    Location
    Tucson
    Posts
    128
    Your input lines are floating, of course you get random garbage from them. So long as you're just reading buttons it would be way more efficient as well as practical to read the pin as a binary value and make that port have a pin mode INPUT_PULLUP. This will give your input a reasonably controlled impedance so things are not floating everywhere (except your mux).

  7. #7
    Senior Member
    Join Date
    Apr 2020
    Location
    Tucson
    Posts
    128
    Edit: Oh, and because your mux is powered by 5v, the inputs can float to 5v or more and present that to your teensy. Not good. Power your mux from 3.3V.

  8. #8
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    Quote Originally Posted by bigtony View Post
    Hey guys, not specifically related to the Audio stuff with the Teensy, but everyone here has been super helpful in the past so I was wondering if anyone could help with my multiplexer wiring:
    As poeple have said, you don't have pullup(s) for the buttons. A single pullup resistor to 3.3V on the output of the
    multiplexer might be all you need?

    CMOS logic inputs shouldn't be left floating as they have undefined state. Think of CMOS inputs as sniffing the
    surroundings for voltage !

  9. #9
    Quote Originally Posted by vjmuzik View Post
    That should be more than enough actually, based on the data sheet that chip at the most should only take 450 nanoseconds, my second guess would be that your enable pin appears to be tied to 5v per your schematic. You also have it being powered from 5v, a Teensy 4.x is not 5v tolerant so you should really move that to 3.3v before anything happens. The enable line is active low so if you don't plan on adding any more multiplexer chips you should have it connected to ground, as far as resistors go I don't remember if you specifically have to add them to the buttons or if you can just INPUT_PULLUP the signalPin.
    oops! sorry i've tied the EN pin to gnd, a mistake on my part in the diagram. i'll swap to the 3.3v pin from the 5v. I have multiple multiplexers, is it a problem if they're connected to the same ground line?

  10. #10
    Quote Originally Posted by boxxofrobots View Post
    Your input lines are floating, of course you get random garbage from them. So long as you're just reading buttons it would be way more efficient as well as practical to read the pin as a binary value and make that port have a pin mode INPUT_PULLUP. This will give your input a reasonably controlled impedance so things are not floating everywhere (except your mux).
    i had thought floating meant that something wasn't connected to ground. Am I misunderstanding this term? This project uses 4 multiplexers, 2 for buttons and 2 for potentiometer knobs. i'll switch to the INPUT_PULLUP for this example

    Going to switch to the 3.3v as well and give it a try

  11. #11
    Quote Originally Posted by MarkT View Post
    As poeple have said, you don't have pullup(s) for the buttons. A single pullup resistor to 3.3V on the output of the
    multiplexer might be all you need?

    CMOS logic inputs shouldn't be left floating as they have undefined state. Think of CMOS inputs as sniffing the
    surroundings for voltage !
    sniffing the surroundings for voltage is a great way to put the behaviour i'm seeing hahahaha. how do i know what value resistor to use? do i need to do a bunch of circuit math because that was my worst subject in uni

  12. #12

    Click image for larger version. 

Name:	fHY67xl.jpg 
Views:	17 
Size:	83.7 KB 
ID:	21691

    It looks like I'm getting pretty similar behaviour whether or not I add the resistor to this wiring. Sometimes the readings go crazy, sometimes the readings are 0 on all channels but when my hands go near the circuit the readings start going crazy.

    do i not need a resistor setup like the following on the buttons?:

    Click image for larger version. 

Name:	dAuz4.jpg 
Views:	19 
Size:	112.3 KB 
ID:	21692

  13. #13
    Junior Member
    Join Date
    Jun 2019
    Posts
    15
    Have a look at the SparkFun hookup guide for the 74HC4051 - it's the same thing except only 8 lines (and hence only 3 address pins).

    https://learn.sparkfun.com/tutorials...okup-guide/all

    In your first circuit you seemed to have EN tied high (and to 5V - don't use 5V with the T4), and in the second you have it tied to GND. Do you understand how it works? Better to put EN on a teensy pin and switch it from your code - turn it on to read and off when not needed. Use a pulldown 5-10K resistor to be consistent with the Sparkfun tutorial. Also put a small ceramic cap across the supply terminals to help filter noise - 0.1uF.

    Do you actually have a through hole 4067? I've never seen one though I suppose they exist.

  14. #14
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    Quote Originally Posted by kallikak View Post
    Also put a small ceramic cap across the supply terminals to help filter noise - 0.1uF.
    I should add that every logic chip needs this, always. Its purpose is to decouple the supply at high speed, when the
    power supply traces are seen as mainly inductive and unable to keep a stiff voltage source (this is all on a timescale
    of nanoseconds). Lack of decoupling can cause all sorts of wierd and inexplicable failure modes with clocked circuits,
    or not, can lead to a lot of headscratching!
    Do you actually have a through hole 4067? I've never seen one though I suppose they exist.
    Its an early CMOS logic chip, so will be available in through-hole for legacy support. Its the newer logic
    families like 74LVC that you'd expect to be SMT only. Basically most new chip designs will be SMT only,
    but CD4000 series is 1970's tech.

  15. #15
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    Quote Originally Posted by bigtony View Post
    sniffing the surroundings for voltage is a great way to put the behaviour i'm seeing hahahaha. how do i know what value resistor to use? do i need to do a bunch of circuit math because that was my worst subject in uni
    The value is not critical, it needs to be high enough not to overload the output driving that line, and small enough to prevent noise pickup,
    something in the range 10k to 100k is commonly used for pullups or pulldowns on the same PCB, or somewhat lower for an external signal
    coming in on a long cable.

  16. #16
    Senior Member
    Join Date
    Apr 2020
    Location
    Tucson
    Posts
    128
    I'm a cap-per-chip kinda guy as well, but Dave Jones did a great video where he took a ttl logic computer that displays video and cut every bypass cap on the 8x10" board and it still ran just fine.

  17. #17
    Quote Originally Posted by boxxofrobots View Post
    I'm a cap-per-chip kinda guy as well, but Dave Jones did a great video where he took a ttl logic computer that displays video and cut every bypass cap on the 8x10" board and it still ran just fine.
    Quote Originally Posted by MarkT View Post
    The value is not critical, it needs to be high enough not to overload the output driving that line, and small enough to prevent noise pickup,
    something in the range 10k to 100k is commonly used for pullups or pulldowns on the same PCB, or somewhat lower for an external signal
    coming in on a long cable.
    Quote Originally Posted by kallikak View Post
    Have a look at the SparkFun hookup guide for the 74HC4051 - it's the same thing except only 8 lines (and hence only 3 address pins).

    https://learn.sparkfun.com/tutorials...okup-guide/all

    In your first circuit you seemed to have EN tied high (and to 5V - don't use 5V with the T4), and in the second you have it tied to GND. Do you understand how it works? Better to put EN on a teensy pin and switch it from your code - turn it on to read and off when not needed. Use a pulldown 5-10K resistor to be consistent with the Sparkfun tutorial. Also put a small ceramic cap across the supply terminals to help filter noise - 0.1uF.

    Do you actually have a through hole 4067? I've never seen one though I suppose they exist.
    @kallikak: i made a mistake in the diagram, i had kept the EN pin on GND because i saw that in a lot of wiring diagrams online and tutorials for this multiplexer

    thanks guys for all the replies! with the pull down resistors it works for buttons. not sure about this ceramic cap stuff but it seems good as it is. this doesnt work however with my potentiometer knobs. still getting crazy readings on those

    i have a ton of inputs for this thing, does it matter if i use the same value resistor on each input's connection to GND? i used 10k resistors and everything worked fine

  18. #18
    Attachment 21718

    here's my wiring for potentiometers, both 20k and 100k currently not working. if i wire the second pin of the potentiometer into A2 instead of the mux signal pin, it works normally. i dont think its a problem with the code, as im using the same code for the working buttons mux you guys just helped me out with. any ideas?

  19. #19
    ok, so it seems to kind of work now. every two channels are tied together though (1+2, 3+4, 4+5...) and giving the same reading. and every other potentiometer doesnt effect any of the readings. so every other potentiometer is working but the channels are tied together in pairs for some reason. i dont see anything about this on the datasheet or in any tutorials. any ideas?

  20. #20
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    130
    hi @bigtony - your attachment in #18 above doesn't work, could you re-post it. also could you post the code you're using to read the pots

    cheers Paul

  21. #21
    Quote Originally Posted by houtson View Post
    hi @bigtony - your attachment in #18 above doesn't work, could you re-post it. also could you post the code you're using to read the pots

    cheers Paul
    hey paul, i believe i may have pinpointed the problem. running the following code:

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Bounce.h>
    
    //MUX
    int mux1 = A0;
    
    int s0 = 1;
    int s1 = 2;
    int s2 = 3;
    int s3 = 4;
    
    float vals[16] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
    
    int muxChannel[16][4]={
      {0,0,0,0},
      {0,0,0,1},
      {0,0,1,0},
      {0,0,1,1},
      {0,1,0,0},
      {0,1,0,1},
      {0,1,1,0},
      {0,1,1,1},
      {1,0,0,0},
      {1,0,0,1},
      {1,0,1,0},
      {1,0,1,1},
      {1,1,0,0},
      {1,1,0,1},
      {1,1,1,0},
      {1,1,1,1}
    };
    
    void setup() { 
      pinMode(s0, OUTPUT);
      pinMode(s1, OUTPUT);
      pinMode(s2, OUTPUT);
      pinMode(s3, OUTPUT);
      pinMode(mux1, INPUT);
    
      digitalWrite(s0, LOW); 
      digitalWrite(s1, LOW);
      digitalWrite(s2, LOW);
      digitalWrite(s3, LOW);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      for (int i=0; i<16; i++) {
        digitalWrite(s0,muxChannel[i][0]);
        digitalWrite(s1,muxChannel[i][1]);
        digitalWrite(s2,muxChannel[i][2]);
        digitalWrite(s3,muxChannel[i][3]);
        delayMicroseconds(4000);
        int readVal = analogRead(mux1);
    
        Serial.print("Mux CH ");
        Serial.print(i);
        Serial.print(" pin value:  ");
        Serial.println(readVal);
      }
    }
    i tried reading the signals from the Teensy, and found that both s0 and s3 were correct, with s0 alternating between 1023 and 0 with each channel and s3 reading 8 0s followed by 8 1023s. however, reading the output from s1 and s2, i see that sometimes a value of around 500-650 is present when the pin should be high or low. heres a sample of the readings from s3. is this a problem with my code or the teensy pins? how can these digital pins be outputting a signal of 600? im directly wiring the digital pins to A0 to read these.

    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	2v4v5Lz.png 
Views:	4 
Size:	25.8 KB 
ID:	22019  
    Last edited by bigtony; 10-07-2020 at 10:46 PM.

  22. #22
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    130
    hi @bigtony,

    I'd try moving the pins, try
    s0 - 10
    s1 -11
    s2 -12
    s3 - 16

    If that doesn't work can you take a picture of your actual wiring and post that cheers, Paul

Posting Permissions

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