Demultiplexer

Hi,

I'm trying out this DEMUX (SN74IS139AN)
But I can't figure out how it works.

This is how I have connected it:

and this is my code:

//FIRST THE NIPUT PINS FOR 1 AND 2
int dmux_1_G = 0;
int dmux_1_A = 1;
int dmux_1_B = 2;

int dmux_2_G = 11;
int dmux_2_A = 12;
int dmux_2_B = 13;

//INPUT / OUTPUT PINS 
int dmux_in[] =  {3, 4, 5, 6};
int dmux_out[] = {7, 8, 9, 10};


 
void setup() {  
  pinMode(dmux_1_G, OUTPUT);
  pinMode(dmux_1_A, OUTPUT);
  pinMode(dmux_1_B, OUTPUT);  
  
  pinMode(dmux_2_G, OUTPUT);
  pinMode(dmux_2_A, OUTPUT);
  pinMode(dmux_2_B, OUTPUT); 
  
  Serial.begin(9600); 
  }


 
void loop() {
  

  
  for(int i = 0; i <=3; i++) {
    //ENABLE FIRST INPUT
    digitalWrite(dmux_1_G, LOW);
    digitalWrite(dmux_1_A, LOW);
    digitalWrite(dmux_1_B, LOW);

    //ENABLE FIRST OUTPUT
    digitalWrite(dmux_2_G, LOW);
    digitalWrite(dmux_2_A, LOW);
    digitalWrite(dmux_2_B, LOW);

    // SEND SOME DATA TO ALL INPUTS
    digitalWrite(dmux_in[0], 12);
    digitalWrite(dmux_in[1], 1);
    digitalWrite(dmux_in[2], 1);
    digitalWrite(dmux_in[3], 1);
    
// READ ALL OUTPUTS
     Serial.print(digitalRead(dmux_in[i])); 
     Serial.print(" - "); 
  }
  
  Serial.println();
  
}

I know the code is messy, but it is just to undertstand/test the behaviour of this DEMUX..

soooo, shouldn't the output be
"12 - 0 - 0 - 0 -" ???

Whatever I do I always get a
"0 - 0 - 0 - 0 -"

Pin 0 and 1 are already used for serial comms.
Running out of pins?
The analogue pins are just digital pins with the added functionality of analogue in.
A0 = 14, A1 = 15, etc.

Why are you doing this?
There might be an easier I2C or SPI solution.
Leo..

This will not do what you want:

digitalWrite(dmux_in[0], 12);

I'm not sure the device functions as your code would imply.
It is a package of 2 separate identical parts.
Each has 2 input bits, A and B.
Each has 4 output bits, y0, y1, y2 and y3.
Putting a binary value across A and B will select one of the 4 output pins according to the truth table in the data sheet.
Eg if both A and B are high, y3 is taken low.

Hi.
OPs image.... :o

Sorry this is not very clear.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

This method is better as you can LABEL you connections.

Thanks.. Tom.. :slight_smile:

At first glance, that multiplexer works similar to the good old 4051. Look at the picture on this website. It might give you a better idea of how the device is working.
Also, yes, your Serial communication will mess with the pins you connected to 0 and 1. Move that to the analog pins and use them as digital pins.

Hi,
This may help.


I have changed some pin allocations to make the schematic readable.
The IC is a DIGITAL MUX, so you can only transfer HIGHs and LOWs, not values like 12.

Tom... :slight_smile:

ElCaron:
At first glance, that multiplexer works similar to the good old 4051. Look at the picture on this website. It might give you a better idea of how the device is working.
Also, yes, your Serial communication will mess with the pins you connected to 0 and 1. Move that to the analog pins and use them as digital pins.

It is not the same as far as I see. The 4051 is an analog switch. You give it, through setting address pins, the address of the desired target pin and you can route an analog signal between the common and the selected target pin.

The SN74IS139AN appears to be used purely to select a single output pin depending on the state of two input pins. It looks like it is used for selecting memory banks.

6v6gt:
This will not do what you want:

digitalWrite(dmux_in[0], 12);

I'm not sure the device functions as your code would imply.
It is a package of 2 separate identical parts.
Each has 2 input bits, A and B.
Each has 4 output bits, y0, y1, y2 and y3.
Putting a binary value across A and B will select one of the 4 output pins according to the truth table in the data sheet.
Eg if both A and B are high, y3 is taken low.

...

The SN74IS139AN appears to be used purely to select a single output pin depending on the state of two input pins. It looks like it is used for selecting memory banks

oh, so you mean like something I would connect before a shift register?

do you have a advice what would be a good demux for analog-signals?

It is difficult to make a recommendation without knowing what you are trying to achieve.
For example, I use a 4051 (MUX/DEMUX analog switch) for powering 8 infra red leds, in round robin series, and fed with a 38 kHz signal. That saves me 4 pins on the ATMEGA328P but of course there are other ways of achieving the same thing.
Maybe explain what you are doing and someone will offer another solution.

6v6gt:
It is difficult to make a recommendation without knowing what you are trying to achieve.

I do not have a explicit target, I am just messing around and trying to understand, how that works.

6v6gt:
For example, I use a 4051 (MUX/DEMUX analog switch)

I have tried the 4051 yesterday, and that works really great :slight_smile: .. maybe one question on this. The 4051 is a ANALOG multiplexer.. is there also a digital MUX ? I would like to check if one of my Push-Buttons was pressed.

I guess you can still use a 4051. A digital signal is only a special case of an analog signal. You'd have to scan S1,S2,S3 using 000,001,101,011,... etc and check the common Z to see the status of the corresponding switch on Y0 to Y7 (high or low).

However, you may simply need only something like say an 8 to 3 line encoder eg SN74HC148 if only one of the switches will be depressed at at any one time.