Go Down

Topic: Problems with the de-multiplexer 74HC4051  (Read 275 times) previous topic - next topic

josepramon

Hello friends,
I would like to ask you a question related to the de/multiplexer 74HC4051 and 74HC4067. My intention is to use a multiplexer to expand the number of analog inputs of Arduino. It seems easy, but I do not get it. In reality or simulating with Proteus software, the problem is always the same. I've tried my own codes and some codes that I found online.
The problem is that when I don't have anything connected in the inputs of the 74HC4051 (from 0 to 7) or 74HC4067 (from 0 to 15), I have values different of 0. And when I connect for example 5V in one of the entries, the result is the same. I don't understand why...
I think that when nothing is connected to 4051 or 4067 the values in all the pins should be 0 and if there are some pin connected to 5V the value in this pin should be 1023.
You will see that in my code there is the "pinMode (muxSIG, INPUT_PULLUP);", if you remove it, the values still different of 0.
Any idea?
Thank you


Code: [Select]
const int muxSIG = A0;
const int muxSC = 9;
const int muxSB = 10;
const int muxSA = 11;
float muxValue = 0;

int SetMuxChannel(byte channel)
{
  digitalWrite(muxSC, bitRead(channel, 0));
  digitalWrite(muxSB, bitRead(channel, 1));
  digitalWrite(muxSA, bitRead(channel, 2));
}

void setup()
{
  Serial.begin(9600);
  pinMode(muxSC, OUTPUT);
  pinMode(muxSB, OUTPUT);
  pinMode(muxSA, OUTPUT);
  //pinMode(muxSIG, INPUT_PULLUP);
}

void loop()
{
  for (byte i = 0; i <= 7; i++)
  {
    SetMuxChannel(i);

    muxValue = analogRead(muxSIG);
    Serial.print(muxValue);
    Serial.print("\t");
    Serial.print(" ,");
  }

  Serial.println();
  delay(1000);
}

Grumpy_Mike

#1
Apr 16, 2019, 12:50 pm Last Edit: Apr 16, 2019, 12:54 pm by Grumpy_Mike
Quote
The problem is that when I don't have anything connected in the inputs of the 74HC4051 (from 0 to 7) or 74HC4067 (from 0 to 15), I have values different of 0. And when I connect for example 5V in one of the entries, the result is the same.
Yes that is exactly how electronics works, there is nothing wrong with that. The technical term for this is floating and basically don't do it.

All inputs need to be connected to a voltage for things to work properly, even if this is high or low through a pull up or pull down resistor.

Note pin 3 of the 4051 is not the ground pin, so your circuit is wired wrong as well.

Jobi-Wan

#2
Apr 16, 2019, 05:27 pm Last Edit: Apr 16, 2019, 05:28 pm by Jobi-Wan
Note pin 3 of the 4051 is not the ground pin, so your circuit is wired wrong as well.
I believe OP has pins 3 and 6 swapped.
Pin 3 is the one that connects to one of the 8 multiplexed pins. Pin 6 is /enable, which is active low, so possibly pulled high internally. Hence the 1023 reading.
Maybe the confusion comes from the data sheet also referring to pin 3 as 'common' Z pin.

Grumpy_Mike

Quote
Maybe the confusion comes from the data sheet also referring to pin 3 as 'common' Z pin.
Since when has Z been any equivalent of ground?

josepramon

Hi!
Looking the datasheet you have reason:

  • E = PIN 6. Enable input (active LOW). Digital enable input (E). When E is HIGH, the switches are turned off. --> ¿In proteus is INH?
  • VEE = PIN 7. Supply voltage --> No exist this option in Proteus
  • GND = PIN 8 ground supply voltage --> No exist this option in Proteus
  • S0, S1, S2 = PIN's 11, 10, 9 select input --> Binarian combination using our code. Three digital select inputs
  • Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7  --> PIN's 13, 14, 15, 12, 1, 5, 2, 4 independent input or output
  • Z = PIN 3 common output or input. --> In Proteus, not exist "Z", exist "X". I undertand that is my analogic input A0.
  • VCC = PIN 16 supply voltage. --> No exist this option in Proteus.

I can understand that in the real world if I don't have anything connected, it could show me some values due to noise (for example). But in both cases, i.e, in "Proteus" and in reality, the values are always high. I tried to connect all the Inputs to some value, like 0V or 5V, and I got the same value.  Z or X is not GND, but I tried all possible combinations…
Thanks!

Jobi-Wan

#5
Apr 17, 2019, 01:29 pm Last Edit: Apr 22, 2019, 12:01 am by Jobi-Wan
I have built this circuit:



Not all 8 multiplexed pins are connected. I was lazy and wired up only 5 of them, along a series of 4 x 1kΩ resistors from Vcc to GND.

I made 1 small change to your code:  In SetMuxChannel(), you write bits 0, 1, 2 to C, B, A respectively. I write them to A, B, C, so that the channel number corresponds with the i/o pin designations on the chip.

This is the output in the serial monitor:
Code: [Select]

1023.00 ,767.00 ,511.00 ,255.00 ,0.00 ,0.00 ,2.00 ,36.00 ,
1023.00 ,767.00 ,512.00 ,255.00 ,0.00 ,25.00 ,24.00 ,59.00 ,
1023.00 ,768.00 ,511.00 ,255.00 ,0.00 ,24.00 ,21.00 ,10.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,1.00 ,0.00 ,0.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,8.00 ,7.00 ,48.00 ,
1023.00 ,767.00 ,512.00 ,255.00 ,0.00 ,29.00 ,28.00 ,59.00 ,
1023.00 ,767.00 ,512.00 ,255.00 ,0.00 ,16.00 ,11.00 ,0.00 ,
1023.00 ,768.00 ,511.00 ,255.00 ,0.00 ,0.00 ,0.00 ,8.00 ,
1023.00 ,768.00 ,511.00 ,255.00 ,0.00 ,16.00 ,16.00 ,62.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,28.00 ,27.00 ,27.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,7.00 ,0.00 ,0.00 ,
1023.00 ,768.00 ,511.00 ,255.00 ,0.00 ,0.00 ,2.00 ,38.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,26.00 ,24.00 ,63.00 ,
1023.00 ,767.00 ,512.00 ,255.00 ,0.00 ,26.00 ,21.00 ,7.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,0.00 ,0.00 ,0.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,7.00 ,7.00 ,49.00 ,
1023.00 ,767.00 ,512.00 ,255.00 ,0.00 ,28.00 ,27.00 ,61.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,19.00 ,11.00 ,0.00 ,
1023.00 ,767.00 ,511.00 ,255.00 ,0.00 ,0.00 ,0.00 ,1.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,16.00 ,14.00 ,64.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,31.00 ,28.00 ,26.00 ,
1023.00 ,768.00 ,512.00 ,255.00 ,0.00 ,8.00 ,2.00 ,0.00 ,


As you can see, the first 5 pins read the expected values, the other 3 read garbage/noise.

(Late edit / afterthought: Actually, you can see the mains hum in the noise.)

Grumpy_Mike

If you think
Quote
but I tried all possible combinations…
Then you are deluded. There are more combinations of wiring of a chip like this than you could try in a lifetime.

Read the data sheet and wire it up correct.

PerryBebbington

  • E = PIN 6. Enable input (active LOW). Digital enable input (E). When E is HIGH, the switches are turned off. --> ¿In proteus is INH?
  • VEE = PIN 7. Supply voltage --> No exist this option in Proteus
  • GND = PIN 8 ground supply voltage --> No exist this option in Proteus
  • S0, S1, S2 = PIN's 11, 10, 9 select input --> Binarian combination using our code. Three digital select inputs
  • Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7  --> PIN's 13, 14, 15, 12, 1, 5, 2, 4 independent input or output
  • Z = PIN 3 common output or input. --> In Proteus, not exist "Z", exist "X". I undertand that is my analogic input A0.
  • VCC = PIN 16 supply voltage. --> No exist this option in Proteus.

I've used the old CMOS version of 4052 years ago and I thought Vee being supply voltage didn't look right. I looked in my ancient CMOS data book and Vee is either connected to 0V or to a negative voltage. Vee being negative is to allow for ground referenced AC to be switched. I've looked at  74HC4051 data sheet   and it's not at all clear what Vee should be connected to, and I think you could be led to believe it connects to your +ve supply.
If you have connected pin 7 Vee to your +ve supply voltage I believe you will have problems.
 


Grumpy_Mike

Quote
and it's not at all clear what Vee should be connected to,
It should be connected to a negative voltage power supply or failing that to ground. Yes it defines the lowest voltage you can switch with the multiplexer.

The sort of supply that has a positive - ground - negative output is called a split supply. You can make a split supply from two normal supplies by connecting the negative of one supply to the positive of the other and than becomes the ground point.

Jobi-Wan

"INH" stands for 'inhibit'. If you pull this input high, all switches are disabled / inhibited.

If you have connected pin 7 Vee to your +ve supply voltage I believe you will have problems.
The I/O pins have clamping diodes to Vcc and Vee. If you apply a voltage outside the Vee-to-Vcc range, current is going to run through these diodes.


Go Up