4

What is the difference between a decoder and a demultiplexer and why would you choose one over the other in a design?

Apart from the fact that they are constructed and operated differently, they both perform the same function.

I was of the opinion that demultiplexer split the data that has been multiplexed into one channel back out onto multiple channels.

However, upon testing the circuit model, it functioned very much like a decoder.

aLoHa
  • 587
  • 1
  • 6
  • 16
  • 3
    You can implement decoder with demux, but you can't implement demux with decoder. Hence demux has a more generic function and not the same as you claim. – Eugene Sh. Nov 04 '20 at 21:21
  • So, basically depending on how the demux is operated, it can and/or will perform other functions, is your take-home message? – aLoHa Nov 04 '20 at 21:24
  • What example of a verilog test-bench can one use to view the demux operate as a demux, as opposed to a decoder? I basically reverse my test-bench for a multiplexer to use for my demux model and the outcome is as stated previously. – aLoHa Nov 04 '20 at 21:30
  • 2
    Yes. If the function of decoder of `n` inputs is `F(s1, s2,..., sn)`, then it can be implemented by demux with function `G(d, s1, s2,..., sn)` by assigning constant `d=1` (or `0` - depending which polarity you are working). This is leaving out all of the other possible functionality where `d` is non constant. – Eugene Sh. Nov 04 '20 at 21:30
  • 2
    For your second comment - you need to have the data input vary and not be constant. – Eugene Sh. Nov 04 '20 at 21:31
  • Ok. Many thanks for the heads up. Much appreciated. – aLoHa Nov 04 '20 at 21:32
  • 2
    It is rare that a demultiplexer is needed. Typically a signal can be sent to multiple destinations in parallel and only the intended recipient will consume the data - usually selected by means of a decoder. – Kevin White Nov 04 '20 at 21:59
  • 1
    Added a bit more formal answer below – Eugene Sh. Nov 04 '20 at 22:17
  • 1
    As a general comment, it's good that you accept answers, OP, but don't be so fast to, you won't know how later ones read yet. – TonyM Nov 04 '20 at 22:27
  • Lol. I tried that before and I was likewise reminded that I should accept/settle on an answer as soon as there is one that helps. So, I try to take both case into acount nowadays! – aLoHa Nov 04 '20 at 22:34
  • Btw, do I get a score for my question? :) – aLoHa Nov 04 '20 at 22:39
  • You've got a score for your question – TonyM Nov 04 '20 at 23:02
  • Thanks. Although, it's not yet registered on my profile :) – aLoHa Nov 04 '20 at 23:15
  • 1
    It has: you have a score, everyone's given you 0. Are you not comprehending something in the same way as all of them, then? :-) – TonyM Nov 04 '20 at 23:43

4 Answers4

9

A demultiplexer (demux) can be an analogue circuit or a digital circuit. It has a select input value (usually binary), one signal input and multiple signal outputs. It routes the signal input to a specified signal output based on the select signal value. Depending on the part design, unselected demux outputs go high impedance (usually in an analogue demux) or to a null state, such as logic low or 0 V.

A decoder is a digital circuit. It has a select binary input value and multiple single outputs. It asserts a single output corresponding to the select input value and negates all other outputs. Output polarity depends on the part design.

So a demux has a signal to route whereas a decoder has no input to route, the designer is only interested in the select value.

TonyM
  • 21,742
  • 4
  • 39
  • 62
  • In essence, with the demux, we can choose the route where the input data is directed, by using the select input. Whereas, with the decoder, that route is determined by the inherent design of the decoder, if I understand you correctly? – aLoHa Nov 04 '20 at 22:22
  • @AloHa, read the final paragraph, it states it pretty clearly there :-) One's routing a signal, the other one isn't. – TonyM Nov 04 '20 at 22:29
  • Analog muxes (transmission-gate switches) are bidirectional in nature. They can be muxes or demuxes since they don’t care about direction. And, yes, they can be used with logic too. In contrast, Logic decoder/demultiplexers are unidirectional. So are data selector/multiplexers. – hacktastical Nov 05 '20 at 00:30
8

They're nearly the same thing. A decoder selects one of n outputs based on a set of select lines.

If the device also has an enable, the decoder can be used to distribute a signal (the enable state) to a selected output. This is a demultiplexer. Internally, each decoder output is logical AND with the shared enable.

You'll often see decoders with enables referred to as 'decoder/demultiplexer'. Example: the 'HC138 https://www.ti.com/lit/ds/symlink/sn74hc138-q1.pdf

There’s another type of demultiplexer that uses a switch (transmission gate) element to pass a selected signal. Because they behave as switches, they can be used for digital or analog signals, and they work in both directions. This means they can be used as multiplexers too. Another benefit of transmission-gate switching is reduced delay.

hacktastical
  • 49,832
  • 2
  • 47
  • 138
  • True. Decoders with enable inputs did not cross my mind at all. However, I can see how one could function as a demultiplexer. So, thanks very much for that piece of insight!! But, the question still remains on which one to choose for a design and why or is it just all down to personal preference? – aLoHa Nov 04 '20 at 21:53
  • If you only need the select function, the decoder will do (or wire the demux enable always-on). If you need to qualify the output, or distribute a signal, use the demux. If your signal is analog, use a transmission-gate selector type. – hacktastical Nov 05 '20 at 15:21
2

The Demux is a more generic part than a decoder. This can be demonstrated by the simplest 1->2 decoder vs the "corresponding" demultiplexer. Let's take a look at their functions:

Demultiplexer:

D S |Y0 Y1
0 0 | 0  0  
0 1 | 0  0
1 0 | 1  0
1 1 | 0  1

Decoder:

S | Y0 Y1
0 | 1  0
1 | 0  1

(Here S is the selector input and D is the "data" input of demux. Y0 and Y1 are the outputs).

You can see that in the demux case Y0 = D & ~S and Y1 = D & S. Meaning we can implement a NOT gate (by setting D=1 and using Y0 as output) or an AND gate - by using Y1. That is we have a logically complete system - meaning we can implement any logical function using only such a demuxes (and constant 1).

On the other hand with decoder we can only implement a NOT gate by using Y0 output. Which is not a complete logical system - and no matter how many decoders you have - you won't be able to implement any logical function other than NOT gate.

Eugene Sh.
  • 9,986
  • 2
  • 26
  • 41
  • And that is indeed what you do see in the simulation for both circuits, which was the reason for posting the question, as the demux output waveforms looked like a decoder with a delayed response. Thanks for the added insight, also. – aLoHa Nov 04 '20 at 22:29
2

I've read through the answers and some of them are good and on point, but I feel that they don't give the full picture on the major differences between them and what their practical uses are for and when and where to use them in hardware design.

-Note- I'm 100% self taught and do not possess an engineering degree, nor have I physically built an electronic device or even soldered a circuit for that matter. However, I have independently studied all of the topics associated with electrical engineering as I have a high interest in the subject matter.


The main difference between the two is that a Decoder will set a particular Output to either High Voltage a Logical One or Low Voltage a Logical Zero depending on the Driving Logic that is used combined with the States of its Select Input Bits where a Demux contains a Decoder but will direct or allow the flow of any sized Bus line through it. A Decoder does not accept any input of data other than the select and enable control lines where a Demux does have data input lines...

Typically a Demux is used with a data bus line but not always. The data bus line does not pass through the Decoder portion of the Demux itself. The propagation of the decoded address line will direct which output data bus is currently active. The propagation and direction of data flow takes place after the signal propagates through the Demux's internal Decoder into a series of N-bit 2 Input And Gates. The signal from the internal Decoder's Output is usually tied together with a bit-extender to make all N-bit Lines to its respective And Gate's Input High to make it active or True while the N-bit data bus is connected to the other And Gate's Input. All other Data Buses' Lines' Output Will be OFF since their And Gates have all Zeros passing through their one Input since only 1 bus is active at a time while its internal decoder's enable line is asserted.


Here is a screen shot image of the basic design of a 3-8 Decoder and an 8-bit Way Demux both with an Enable from Basic Logic Gates. The screen shot was take from Logisim after building these circuits.

Decoder/Demux Implementation


When would you want to use one in favor of the other? This depends on your particular needs for your intended use along with any constraints you may have.

  • Constraints:
    • Board or Circuit Size
    • Timing issues or concerns with propagation delay
    • Cost of parts
    • Desired use
    • Other unlisted factors

If you are constrained by a small area such as in a micro controller, then it would more than likely be preferable to use a Decoder as it is smaller, easier and requires less transistors, wires, and area to make. It also has a smaller propagation delay for timing constraints within some circuits compared to a Demux since Demuxes have an extra layer of Logic to perform.

So when would you want to use a Demux instead of a Decoder? As others have stated, if you need to perform additional logic, or to route Data Lines to different Buses then it might be more appropriate.

Consider a CPU or a Micro-controller that has a very small area which contains many sub sections such as its Registers, Cache, ALU, and Control Units. When a specific task or instruction has been performed by the CPU's ALU it normally sets different bits within a Flags register. The output of the Flags Register will normally be connected to the Control Unit.

The Control Unit will also have specific bits coming in from the Instruction Register as well as lines from the Instruction Counter and the Stage Counter where the Stage Counter would be the cycle stage that the current instruction is on, such as Fetch, Decode, Execute, Write, etc... This is where you would want to use a Decoder and not a Demux within your Control Unit. Other parts of the CPU and its Data Path such as the routing lines for the Registers or Register File to select which register, or the Cache-Line - Cache-Blocks, etc. where you want to designate address lines to be active, you would probably want to use a Decoder instead of a Demux.

Now, within the ALU itself for controlling which function is to be performed based on the signals that are sent from the Control Unit you then may use either depending on the design of your ALU. Here, you may want to use a Demux to direct the output of the operation of the ALU to a specific region within the CPU for example, you might want to send it to the Data-Bus that goes to the Register-File to be written, or to the Output-Bus to be written back to the Cache or Main-Memory, etc.

Typically, when you are working with Instructions to be decoded, flags to be processed, or address and control lines to become active, this is when you would prefer to use a Decoder.

When you are working with Data-Lines or Data-Buses and you want to direct the flow of Data from one place to another such as the various buses on a mother board... Then you would probably prefer to use a Demux over a Decoder as it would also allow you to perform additional Logic directly to the Data that is being passed through.

Sometimes it may not always be practical to use a Demux in some situations. For example, if you have data coming across a bus that is connected to some device, and this device has a very specific and narrow timing range that is specified in its documentation and data sheets for read and write operations... Adding a Demux before this device might cause the device to not work as you would intend it to. Here you would probably have to use a Decoder with Tri-State Buffers such as a Bus-Transceiver to make sure that the signal of the *Data is reaching the Device within the appropriate time limits.

Demuxes are still used in some remote situations, but are seldom used compare to their inverse device Multiplexer or Mux as there are better alternatives that are used in practices such as using Tri-State Buffers.

Now, depending on the type of system that is being used for its internal memory structure such as synchronous clock timings, read or write on the rising or falling edge... as opposed to asynchronous memory read and writes by asserting control bits to automatically read a write agnostic of any clock can also be a determining factor of whether to use either a Demux, a Decoder with other logic wrapped around it, a Bus-Transceiver also known as Tri-State Buffers with direction flow and enabling logic, or some other custom built device to perform such similar tasks.

Think of a Bus Controller that is built into a given computer's Mother or Main Board... Some are built in hardware, other's have programmable ROMs, while others may have flash ram that allows a given CPU to set it's logic as opposed to the Control Unit of a CPU or even a GPU...

I hope that this clears things up, not so much for the person who asked this question as they have already accepted an answer, but to illustrate the main differences between these devices for future readers and novices who may be interested in going down this path pursuing this field...

  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/120522/discussion-on-answer-by-francis-cugler-what-is-the-main-difference-between-a-dec). – Voltage Spike Mar 07 '21 at 06:59
  • @Francis_Cugler Thank you for your elaborative answer. It certainly explains a whole lot without leaving many, if any, gaps for questions :) and I will surely be referencing it, as I go along!! Btw, is it ok to change my preferred answer or is that frowned upon? – aLoHa Mar 24 '21 at 16:14