I2C Selector/Demux?

Thread Starter

johnyradio

Joined Oct 26, 2012
434
I'm pretty sure this is very basic stuff.
I want to use a binary number to control 4 switches. The binary number will control which one switch turns on.
What's a simple chip that will take a 4-bit number, and set one of 4 output pins high based on that number?

1699737603710.png

I'm sure my title is wrong. I was thinking of decade counters. Would this be a multiplexer? Wait, i think it's a demux.

1699738321174.png
https://datasheet.octopart.com/SN74LVC139ADBRE4-Texas-Instruments-datasheet-10256471.pdf
 
Last edited:

Thread Starter

johnyradio

Joined Oct 26, 2012
434
@Ian0 Thx!

Now i'm seeking I2C decoder.
Can you recommend a cheap part?
I found these, but they are only 2-position output. I need 4-position output. And i need dual, meaning two independent circuits like the one in my question.

https://datasheet.octopart.com/SN74LVC139ADBRE4-Texas-Instruments-datasheet-10256471.pdf
https://datasheet.octopart.com/FXWA9306L8X-ON-Semiconductor-datasheet-95952863.pdf
https://datasheet.octopart.com/PCA9540BD,112-NXP-Semiconductors-datasheet-10209809.pdf
https://datasheet.octopart.com/PCA9542APW,112-NXP-datasheet-8326126.pdf
https://datasheet.octopart.com/PCA9546AD,112-NXP-datasheet-8325340.pdf

i suspect this can be done cheapest with a uC.
 

Ian0

Joined Aug 7, 2020
9,842
MCP23016/23017
 

Thread Starter

johnyradio

Joined Oct 26, 2012
434
Last edited:

k1ng 1337

Joined Sep 11, 2020
960
But i see those MCP23016 expanders run about $2. I think i can get a cheap uC for under $0.50.

https://octopart.com/datasheet/r5f10y16dsp#50-renesas-57396391

Or, maybe discreet logic gates would be cheapest! @k1ng 1337 's circuit uses 2 inverters and 4 nands. Is there a way to achieve this with only one type of gate?
Tie the inputs of NAND or NOR gates together to make an inverter. Most logic gate ICs have 4 logic gates in the package.

I made a 3-8 decoder before with only logic gates. I even made a few decoders with transistors.

Will it be cheaper? Maybe. But they are fun to play with and you will learn more.
 

k1ng 1337

Joined Sep 11, 2020
960
I2C is referring to the I2C bus communication scheme. This is separate from your apparent goal of making a 2-4 Line Decoder. Since you mentioned you need two 2-4 Line Decoders, the chip below looks suitable. You can also make two versions of the circuit I suggested using 12 NAND gates with 3 quad ICs as the truth table is the same. You can make any truth table you want from NAND or NOR gates.

https://datasheet.octopart.com/SN74LVC139ADBRE4-Texas-Instruments-datasheet-10256471.pdf

CDx4HC02 Quadruple 2-Input NAND Gates datasheet (Rev. D) (ti.com)
 

Thread Starter

johnyradio

Joined Oct 26, 2012
434
I2C is referring to the I2C bus communication scheme. This is separate from your apparent goal of making a 2-4 Line Decoder. Since you mentioned you need two 2-4 Line Decoders, the chip below looks suitable. You can also make two versions of the circuit I suggested using 12 NAND gates with 3 quad ICs as the truth table is the same. You can make any truth table you want from NAND or NOR gates.

https://datasheet.octopart.com/SN74LVC139ADBRE4-Texas-Instruments-datasheet-10256471.pdf

CDx4HC02 Quadruple 2-Input NAND Gates datasheet (Rev. D) (ti.com)
Great info!

Logic Gates BOM
3 x CDx4HC02 : $0.18
1 x I2C interface (i can't find a chip for this besides a uC) : $0.50
total about $0.70

Multiplexer BOM
1 x SN74LVC139A DECODER/DEMULTIPLEXER : $0.09
1 x I2C interface (uC) : $0.50
total about $0.60

uC BOM
uC : $0.50
total about $0.50
 
Last edited:

k1ng 1337

Joined Sep 11, 2020
960
Great info!

Logic Gates BOM
3 x CDx4HC02 : $0.18
1 x I2C interface (i can't find a chip for this besides a uC) : $0.50
total about $0.70

Multiplexer BOM
1 x SN74LVC139A DECODER/DEMULTIPLEXER : $0.09
1 x I2C interface (uC) : $0.50
total about $0.60

uC BOM
uC : $0.50
total about $0.50
A microcontroller is probably your best bet because most have your required 12 IO ports with I2C capability. What are you actually trying to decode?
 

Thread Starter

johnyradio

Joined Oct 26, 2012
434
What are you actually trying to decode?
I2C data is a series of 2-bit peripheral addresses (there are 4 peripherals). The data to each peripheral is two, 2-bit numbers. The peripheral will use the first 2-bit number to set 1-of-4 outputs. The second 2-bit number will be used the same way (for a different set of 4 outputs)

@k1ng 1337 , @dl324 , @Ian0 , thanks for the awesome answers! You definitely provided exactly the information i sought. If my application didn't need I2C, then one of your suggestions would be perfect.
 
Last edited:

k1ng 1337

Joined Sep 11, 2020
960
I2C data is a series of 2-bit peripheral addresses (there are 4 peripherals). The data to each peripheral is two, 2-bit numbers. The peripheral will use the first 2-bit number to set 1-of-4 outputs. The second 2-bit number will be used the same way (for a different set of 4 outputs)

@k1ng 1337 , @dl324 , @Ian0 , thanks for the awesome answers! You definitely provided exactly the information i sought. If my application didn't need I2C, then one of your suggestions would be perfect.
From what I understood, you want each of the 4 peripherals to be able to control either Port A or Port B by sending a two bit binary value to the device in the center twice (4 bits total). I think you intend the device in the center to be the master because it is the one directly connected to Port A and B. Since you are controlling 8 outputs on the IO bus, only 3 control bits would need to be sent at once (2x2x2=8). What do you think?


Untitled.png
 
Last edited:

Thread Starter

johnyradio

Joined Oct 26, 2012
434
i think i just decided to switch to UART, SPI, ... or my own protocol.
As you can see, the operations are very simple. Here's the entire language and only operation:

  1. controller: station 00, turn on 01, 10
    1. station 00: confirmed.
  2. controller: station 01, turn on 11, 01
    1. station 01: confirmed.
  3. controller: station 10, turn on 01, 10
    1. station 10: confirmed.
  4. controller: station 11, turn on 01, 11
    1. station 11: confirmed.

The controller doesn't need to say "station", because station address is always the first number sent.
"turn on" is the only command right now, but I'll allow up to 4 total commands. "turn on" is command #00.
Stations will have 4 possible responses. "confirmed" is #00.
So i get:

Code:
controller: 00, 00, 01, 10
station 00: 00.
controller: 01, 00, 11, 01
station 01: 00.
controller: 10, 00, 01, 10
station 10: 00.
controller: 11, 00, 01, 11
station 11: 00
The command syntax appears to be
address, command-number, data 1, data 2
 
Last edited:

k1ng 1337

Joined Sep 11, 2020
960
i think i just decided to switch to UART, SPI, ... or my own protocol.
As you can see, the operations are very simple.
I2C is the easiest of those. As long as each peripheral has I2C and 8 outputs this can work. The decoding in done in software. All you need to do is code the peripheral like a 3-8 Line Decoder truth table. Think of it like this:

1) The I2C controller sends a 3 bit number to 1 of the 4 peripherals. The bits decodes to 8 possible states.

2) Th I2C peripheral compares the 3 bit number to a 3-8 Line Decoder truth table and turns on the appropriate output.

Another way to do this is by sending 5 bits to all peripherals at the same time. 5 bits decodes to 32 possible states which is how many you have total. This forms the basis of encoding information in binary.

A 3 to 8 Line Decoder has twice as many output states as a 2 to 4 Line Decoder. A 4 to 16 Line Decoder follows the same pattern according to 2^n bits.
 
Last edited:

k1ng 1337

Joined Sep 11, 2020
960
I made a mistake. A 3 to 8 Line Decoder truth table will only allow 1 of the 8 outputs to be on at once. Your last diagram shows two outputs on at once. To make this happen add an additional step:

1) The I2C controller sends a 3 bit number to 1 of the 4 peripherals.

2) The I2C peripheral compares the first bit to a 1-2 Line Decoder truth table which sets the port to either A or B for the next step.

3) The I2C peripheral compares the last two bits to a 2-4 Line Decoder truth table and turns on the appropriate output of either Port A or B.

This way the the microcontroller knows which output port is being selected by looking at the first bit when 3 bits are sent in a single command.

You can get creative with what you want each bit to represent. No need to send separate commands. You can also encode in text since I2C supports alphanumeric code. By sending "apple", you can turn on 2 of the 8 outputs for a given peripheral just as easily.
 
Last edited:

Thread Starter

johnyradio

Joined Oct 26, 2012
434
Tho' i think my method (above) may use fewer bits.

Your method:
controller: 01, 00, 001, 110
(node address 01, command 00, first port 01, second port 10)

Or maybe you mean:
controller: 01, 001
controller: 01, 110
(node address 01, first port 01)
(node address 01, second port 10)

My method is positional. Also, it makes more sense for my application to combine them into one command.
controller: 01, 00, 01, 10
(node address 01, command 00, first port 01, second port 10)
 
Last edited:
Top