Weird multiplexer behaviour

hansjjprins

New member
Hello everyone,

I've been trying to get a Sparkfun CD74HC4067 multiplexer to work with 1 potentiometer (for now, later I'll hook up the total of 16). The used parts are:

  • Teensy 4.1
  • Sparkfun CD74HC4067
  • A 10kOhm potentiometer
  • a 100uF decoupling capacitor over the teensy powersupply
  • a 100nF decoupling capacitor over the power and ground pins of the CD74HC4067

breadboard.jpg

breadboard2.jpg

Without the multiplexer the pots behave fine. But s soon as I hook one up to the multiplexer, I get strange behaviour. With the measurements in the following image I turn a pot connected to C0.

memasurements.jpg

C0 increases in value from 0 to 1022 (as expected). However, all the other channels also give off changes while I turn that pot on C0. So I started digging around and came across a few potential problems. The first states that not dealing with sudden voltage drops could present problems. So I put in a few decoupling capacitors. This seems to have made it a little better but not good enough. Then I read somewhere on the forum that the Teensy 4.1 executes so fast, the CD74HC4067 can't keep up. So I added in a delay between selecting the channel and reading the SIG pin. Unfortunately to no avail...

My sketch looks as follows:

Code:
const int SIG = A0;
const int S0 = 33;
const int S1 = 34;
const int S2 = 35;
const int S3 = 36;

int SetMuxChannel(byte channel)
{
   digitalWrite(S0, bitRead(channel, 0));
   digitalWrite(S1, bitRead(channel, 1));
   digitalWrite(S2, bitRead(channel, 2));
   digitalWrite(S3, bitRead(channel, 3));
}

void setup()
{
  pinMode(SIG, INPUT);
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  Serial.begin(9600);
  // Print the header:
  Serial.println("C0\tC1\tC2\tC3\tC4\tC5\tC6\tC7\tC8\tC9\tC10\tC11\tC12\tC13\tC14\tC15");
  Serial.println("---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---");
}

void loop()
{
  for (uint8_t i=0; i<16; i++) {
    SetMuxChannel(i);
    delayMicroseconds(50);
    int val = analogRead(SIG);
    Serial.print(String(val) + "\t");
    delayMicroseconds(50);
  }
  Serial.println();
  delay(500);
}

Hopefully someone can shed a light on this as I have been pulling my hair for the last week or so. Any help will be appreciated :)

Kind regards,

Johannes
 
Hopefully someone can shed a light on this as I have been pulling my hair for the last week or so. Any help will be appreciated :)

Kind regards,

Johannes

Johannes: Your method of utilizing the CD74HC4067 is sound (setting the address bits, delaying 50 usecs before taking a reading, etc.). What you are observing is that the analog input to the Teensy (pin A0) is only actually driven (by the pot) when you are addressing C0...all of the other inputs are effectively "floating". so the values that you are reading are unreliable. To test/verify this, put a resistor divider network (e.g. 2.2K between 3.3VDC & C1, plus 1.0K between C1 & ground). For this specific use of resistors, you would expect to read approximately 2/3 of the range (a count of approximately 780), which should be relatively constant (varying only within a couple of counts, if at all) as you vary the setting of the pot on C0.

Hope this helps !!

Mark J Culross
KD5RXT
 
Hello Mark,

Thanks for your reply! It has been most helpful! I now hooked up 3 pots in total and got acceptable readings from them (I will try smooth them out with a low pass filter). I placed the 3 pots on C0, C1 & C2. So I put your suggested resistor divider on C3. This got me a stable reading of around 320 and verifies your suggestion :). This has made me a teensy bit wiser today... (hopefully this pun hasn't been made too many times yet).

Kind regards,

Johannes
 
Last edited:
Thanks for your reply! It has been most helpful!

Johannes

You're very welcome & glad that I could be of some help !!

Good luck, have fun, & come back to ask any other questions that may come up . . .

Mark J Culross
KD5RXT

P.S. I realize now that the ratio of resistors that I described (which should result in a measurement of 1/3 of the voltage range expected) does not result in the count that I quoted (a measurement at 2/3 of the range) !! It seems that you realized that & it appears that you got what should be the expected results. Hopefully, anybody who stumbles across my previous post in the future continues to read on through the thread until they see this correction !! MJC
 
Last edited:
Back
Top