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:
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.
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:
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
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
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.
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