Salta al contenuto
Note per Studenti Decoders, Encoders and Multiplexers Report

Decoders, Encoders and Multiplexers

In questa pagina 7

These combinational blocks change encoding (decoder: binary to one-hot; encoder: one-hot to binary) or select data (multiplexer). They underlie address decoders of memories, datapaths and control units.

One-hot encoding

A one-hot configuration of mm bits has exactly one 1, in the position that identifies the value. With n=3n=3 binary bits, 0,…,70,\dots,7 become 00000001, 00000010, 00000100, …, 1000000000000001,\ 00000010,\ 00000100,\ \dots,\ 10000000. Value 55 on 8 bits is 0010000000100000. It uses more bits but each bit "says" one thing only (also useful for machine states).

Decoder

An nn-to-mm decoder has nn inputs and m≤2nm\le2^n outputs D0,…,Dm−1D_0,\dots,D_{m-1}: it sets to 1 the output whose index is encoded by the inputs and the others to 0 (m=2nm=2^n if every combination is valid). Its outputs are the 2n2^n minterms of the inputs, Di=miD_i=m_i (Canonical Forms - Minterms, Maxterms, SOP and POSA minterm is a product containing every variable exactly once and is 1 on a single truth-table row; a maxterm is the dual sum and is 0 on a single row; with n variables there are 2^n of each and the complement of minterm i is maxterm i. Canonical SOP = sum of minterms of rows with F=1; canonical POS = product of maxterms of rows with F=0. They come mechanically from the truth table but are redundant, so they are the starting point for minimization. SOP and POS are two-level circuits.Canonical Forms - Minterms, Maxterms, SOP and POS →), so it is built with mm AND gates of nn inputs, each with its direct/negated input pattern.

A1A0=11A_1A_0=11 gives D3D2D1D0=1000D_3D_2D_1D_0=1000; 3-to-8 with input 101101 gives 0010000000100000, D5=A2A1‾A0D_5=A_2\overline{A_1}A_0.

  • 1-to-2: D0=A‾D_0=\overline A, D1=AD_1=A.
  • 2-to-4: D0=A‾1A‾0D_0=\overline A_1\overline A_0, D1=A‾1A0D_1=\overline A_1A_0, D2=A1A‾0D_2=A_1\overline A_0, D3=A1A0D_3=A_1A_0: 2 inverters and 4 two-input ANDs.

Hierarchical construction and cost

For large decoders one nn-input AND per minterm is too costly. A 3-to-8 is built from a 2-to-4, a 1-to-2 and 8 two-input ANDs (each combining one output of each); a 6-to-64 from two 3-to-8 and 64 two-input ANDs. Cost as gate inputs (inverters count 1):

circuit calculation cost
2-to-4 2+4⋅22+4\cdot2 10
3-to-8 hierarchical 10+1+8⋅210+1+8\cdot2 27
6-to-64 hierarchical 2⋅27+64⋅22\cdot27+64\cdot2 182
6-to-64 flat 6+64⋅66+64\cdot6 (64 six-input ANDs) 390

Enable

With enable EN =0=0 all outputs are 0. It is made with mm enabling ANDs on the outputs or, for large decoders (n≥4n\ge4) more cheaply, by feeding EN to the inputs of the final AND level.

Functions with a decoder

Since the decoder generates all minterms, any SOP function is built with a decoder and an OR gate collecting the minterms of the SOP.

Full adder, inputs X,Y,ZX,Y,Z: S=∑m(1,2,4,7)=D1+D2+D4+D7S=\sum m(1,2,4,7)=D_1+D_2+D_4+D_7 and C=∑m(3,5,6,7)=D3+D5+D6+D7C=\sum m(3,5,6,7)=D_3+D_5+D_6+D_7: one 3-to-8 and two 4-input ORs. This is convenient when the function has few minterms; with more than half, use a NOR of the minterms of F‾\overline F (F=∑mi∉F‾F=\overline{\sum m_{i\notin F}}).

Example: BCD to seven segments

Segments a,b,c,d,e,f,ga,b,c,d,e,f,g (from the top, clockwise, then the middle one). Input: BCD digit ABCDABCD (AA = MSB). Table (1 = on; 66 with segment aa, 99 with dd):

digit a b c d e f g
0 1 1 1 1 1 1 0
1 0 1 1 0 0 0 0
2 1 1 0 1 1 0 1
3 1 1 1 1 0 0 1
4 0 1 1 0 0 1 1
5 1 0 1 1 0 1 1
6 1 0 1 1 1 1 1
7 1 1 1 0 0 0 0
8 1 1 1 1 1 1 1
9 1 1 1 1 0 1 1

With 10101010-11111111 as don't care, the seven Karnaugh maps give:

segment minimal SOP
aa A+C+BD+B‾ D‾A+C+BD+\overline B\,\overline D
bb B‾+C‾ D‾+CD\overline B+\overline C\,\overline D+CD
cc B+C‾+DB+\overline C+D
dd A+B‾ D‾+B‾C+CD‾+BC‾DA+\overline B\,\overline D+\overline BC+C\overline D+B\overline CD
ee B‾ D‾+CD‾\overline B\,\overline D+C\overline D
ff A+BC‾+BD‾+C‾ D‾A+B\overline C+B\overline D+\overline C\,\overline D
gg A+B‾C+BC‾+BD‾A+\overline BC+B\overline C+B\overline D

Three implementations: (1) gates with seven independent maps, sharing common products; (2) 4-to-16 decoder plus seven ORs; (3) seven 8-to-1 multiplexers. Check on digit 22 (A=0,B=0,C=1,D=0A=0,B=0,C=1,D=0): only cc and ff must be off: c=B+C‾+D=0c=B+\overline C+D=0, f=A+BC‾+BD‾+C‾ D‾=0f=A+B\overline C+B\overline D+\overline C\,\overline D=0, a=C=1a=C=1.

Encoder

The encoder is the inverse of the decoder: it receives a one-hot signal of 2n2^n bits and produces the nn-bit binary code. Octal-to-binary with inputs D0,…,D7D_0,\dots,D_7 (one 1 at a time): A0=D1+D3+D5+D7,A1=D2+D3+D6+D7,A2=D4+D5+D6+D7.A_0=D_1+D_3+D_5+D_7,\quad A_1=D_2+D_3+D_6+D_7,\quad A_2=D_4+D_5+D_6+D_7 .

D5=1D_5=1 gives A=101=5A=101=5. Each output is the OR of the inputs whose index has that bit at 1. Only 8 of the 256256 input combinations are specified; the rest are don't care.

Two problems. (1) With two inputs at 1 (e.g. D3=D6=1D_3=D_6=1) the output is the OR of the codes, 011+110=111011+110=111, equal to that of D7D_7: wrong. (2) With all inputs 0 the output is 000000, the same as for D0=1D_0=1.

Priority encoder

The priority encoder handles non-one-hot inputs with: (1) a priority function: only the active input with the highest priority counts; (2) a valid output V: V=1V=1 if at least one input is 1, V=0V=0 if all are 0 (then AA is don't care).

Four inputs, priority D3>D2>D1>D0D_3>D_2>D_1>D_0:

D3D_3 D2D_2 D1D_1 D0D_0 A1A_1 A0A_0 VV
0 0 0 0 X X 0
0 0 0 1 0 0 1
0 0 1 X 0 1 1
0 1 X X 1 0 1
1 X X X 1 1 1

Karnaugh maps with Xs give A1=D3+D2,A0=D3+D2‾D1,V=D3+D2+D1+D0.A_1=D_3+D_2,\qquad A_0=D_3+\overline{D_2}D_1,\qquad V=D_3+D_2+D_1+D_0 . On D3D2D1D0=0110D_3D_2D_1D_0=0110: A1=1A_1=1, A0=0A_0=0, A=10=2A=10=2, the index of the highest active input D2D_2. The priority encoder is the basis of interrupt priority handling.

Multiplexer

A 2n2^n-to-1 multiplexer (MUX) has 2n2^n data inputs I0,…,I2n−1I_0,\dots,I_{2^n-1}, nn select inputs Sn−1…S0S_{n-1}\dots S_0 and an output YY: if SS equals ii in binary, Y=IiY=I_i. In general Y=∑imi(S)⋅IiY=\sum_i m_i(S)\cdot I_i: the minterms of the select inputs act as "gates" for the data.

2-to-1: Y=S‾ I0+S I1Y=\overline S\,I_0+S\,I_1. 4-to-1: Y=S‾1S‾0I0+S‾1S0I1+S1S‾0I2+S1S0I3Y=\overline S_1\overline S_0I_0+\overline S_1S_0I_1+S_1\overline S_0I_2+S_1S_0I_3.

4-to-1 with I3I2I1I0=1101I_3I_2I_1I_0=1101: S1S0=10S_1S_0=10 gives Y=I2=1Y=I_2=1; S1S0=01S_1S_0=01 gives Y=I1=0Y=I_1=0. A MUX 8-to-1 has 8 data + 3 select inputs.

Cost of the 4-to-1. Direct: 2 inverters, 4 three-input ANDs, 1 four-input OR: 2+4⋅3+4=182+4\cdot3+4=18. With a decoder (2-to-4 generates the minterms, four 2-input enabling ANDs, a 4-input OR): 10+4⋅2+4=2210+4\cdot2+4=22. The latter is costlier but hierarchical and extensible: a 64-to-1 built so costs 182+128+64=374182+128+64=374; flat (6 inverters, 64 seven-input ANDs, one 64-input OR) 6+448+64=5186+448+64=518.

Vector MUX. A quad 4-to-1 multiplexer has four 4-bit inputs, a 2-bit select and a 4-bit output: one shared decoder (cost 10) driving four 1-bit 4-to-1 MUXes (4⋅2+4=124\cdot2+4=12 each): 10+12⋅4=5810+12\cdot4=58. It selects among 4 registers of 4 bits.

Functions with a MUX

nn variables, 2n2^n-to-1 MUX: the nn variables go to the select inputs (the most significant to Sn−1S_{n-1}) and the data inputs get the truth-table values, Ii=F(i)I_i=F(i), constants 0 or 1. For row ii the MUX selects IiI_i, exactly what FF must output.

F=A⊕BF=A\oplus B with a 4-to-1 MUX and S1S0=ABS_1S_0=AB: I0=0I_0=0, I1=1I_1=1, I2=1I_2=1, I3=0I_3=0.

nn variables, 2n−12^{n-1}-to-1 MUX (last variable as data): connect n−1n-1 variables to the select inputs and apply to the data inputs 00, 11, the remaining variable XX or X‾\overline X. For each select value the two rows (X=0X=0 and X=1X=1) give a pair:

F(X=0)F(X=0) F(X=1)F(X=1) data input
0 0 00
1 1 11
0 1 XX
1 0 X‾\overline X

Example. F(A,B,C,D)=∑m(1,3,4,11,12,13,14,15)F(A,B,C,D)=\sum m(1,3,4,11,12,13,14,15) with an 8-to-1 MUX and S2S1S0=ABCS_2S_1S_0=ABC:

ABCABC minterms D=0,D=1D=0,D=1 (F(0),F(1))(F(0),F(1)) IiI_i
000 0,10,1 (0,1)(0,1) DD
001 2,32,3 (0,1)(0,1) DD
010 4,54,5 (1,0)(1,0) D‾\overline D
011 6,76,7 (0,0)(0,0) 00
100 8,98,9 (0,0)(0,0) 00
101 10,1110,11 (0,1)(0,1) DD
110 12,1312,13 (1,1)(1,1) 11
111 14,1514,15 (1,1)(1,1) 11

So I0=I1=I5=DI_0=I_1=I_5=D, I2=D‾I_2=\overline D, I3=I4=0I_3=I_4=0, I6=I7=1I_6=I_7=1 (mind the order: AA to S2S_2, CC to S0S_0).

Full adder with 4-to-1 MUXes. Select S1S0=XYS_1S_0=XY, data ZZ: S=Z,Z‾,Z‾,ZS=Z,\overline Z,\overline Z,Z and C=0,Z,Z,1C=0,Z,Z,1 for XY=00,01,10,11XY=00,01,10,11. Two 4-to-1 MUXes and an inverter replace two 8-to-1 MUXes. With don't cares a pair (X,any)(X,\text{any}) lets the data input be chosen freely.

Common mistakes

  • Thinking the decoder outputs the binary form: it outputs one-hot.
  • Using a plain encoder with non-one-hot inputs; forgetting the "all 0" case (V needed).
  • Miscounting cost: in the flat 6-to-64 the ANDs have 6 inputs, not 7.
  • Connecting variables to the select inputs in the wrong order; forgetting X‾\overline X for the pair (1,0)(1,0).
  • Thinking a MUX only "selects": it is a universal function generator.

Versione ripasso

  • One-hot: one 1 per word; value 55 on 8 bits is 0010000000100000.
  • Decoder nn-to-mm: binary to one-hot, Di=miD_i=m_i, mm ANDs of nn inputs. A1A0=11⇒1000A_1A_0=11\Rightarrow1000. 2-to-4: D0=A‾1A‾0D_0=\overline A_1\overline A_0, D1=A‾1A0D_1=\overline A_1A_0, D2=A1A‾0D_2=A_1\overline A_0, D3=A1A0D_3=A_1A_0.
  • Hierarchical cost (gate inputs): 2-to-4 =10=10; 3-to-8 =27=27 (2-to-4 + 1-to-2 + 8 two-input ANDs); 6-to-64 =182=182 (two 3-to-8 + 64 two-input ANDs) vs 390390 flat.
  • Enable: EN =0=0 forces all outputs to 0; for n≥4n\ge4 feed EN to the decoder inputs.
  • Function = decoder + OR of its minterms: S=D1+D2+D4+D7S=D_1+D_2+D_4+D_7, C=D3+D5+D6+D7C=D_3+D_5+D_6+D_7. More than half minterms: NOR of the minterms of F‾\overline F.
  • BCD to 7 segments: a=A+C+BD+B‾ D‾a=A+C+BD+\overline B\,\overline D, b=B‾+C‾ D‾+CDb=\overline B+\overline C\,\overline D+CD, c=B+C‾+Dc=B+\overline C+D, d=A+B‾ D‾+B‾C+CD‾+BC‾Dd=A+\overline B\,\overline D+\overline BC+C\overline D+B\overline CD, e=B‾ D‾+CD‾e=\overline B\,\overline D+C\overline D, f=A+BC‾+BD‾+C‾ D‾f=A+B\overline C+B\overline D+\overline C\,\overline D, g=A+B‾C+BC‾+BD‾g=A+\overline BC+B\overline C+B\overline D. Implementations: gates, 4-to-16 decoder + 7 ORs, 7 MUX 8-to-1.
  • Encoder (octal): A0=D1+D3+D5+D7A_0=D_1+D_3+D_5+D_7, A1=D2+D3+D6+D7A_1=D_2+D_3+D_6+D_7, A2=D4+D5+D6+D7A_2=D_4+D_5+D_6+D_7. Fails with two 1s (D3=D6=1→111D_3=D_6=1\to111) and with all 0 (looks like D0D_0).
  • Priority encoder: priority plus valid output V. D3>D2>D1>D0D_3>D_2>D_1>D_0: A1=D3+D2A_1=D_3+D_2, A0=D3+D2‾D1A_0=D_3+\overline{D_2}D_1, V=D3+D2+D1+D0V=D_3+D_2+D_1+D_0; 0110→A=100110\to A=10. Basis of interrupt priorities.
  • MUX 2n2^n-to-1: Y=∑mi(S)IiY=\sum m_i(S)I_i; 2-to-1 Y=S‾ I0+S I1Y=\overline S\,I_0+S\,I_1; 4-to-1 cost 1818 direct, 2222 with decoder; 64-to-1 374374 hierarchical, 518518 flat; quad 4-to-1 5858.
  • Function with MUX: nn variables on a 2n2^n-to-1: Ii=F(i)I_i=F(i) (A⊕BA\oplus B: 0,1,1,00,1,1,0). With a 2n−12^{n-1}-to-1: data =0,1,X,X‾=0,1,X,\overline X for pairs (0,0),(1,1),(0,1),(1,0)(0,0),(1,1),(0,1),(1,0). ∑m(1,3,4,11,12,13,14,15)\sum m(1,3,4,11,12,13,14,15) with S=ABCS=ABC: I0=I1=I5=DI_0=I_1=I_5=D, I2=D‾I_2=\overline D, I3=I4=0I_3=I_4=0, I6=I7=1I_6=I_7=1.
  • Full adder with MUX 4-to-1: S=Z,Z‾,Z‾,ZS=Z,\overline Z,\overline Z,Z; C=0,Z,Z,1C=0,Z,Z,1 for XY=00,01,10,11XY=00,01,10,11.
  • Mistakes: decoder taken as binary; plain encoder with non-one-hot inputs; no V; 7-input ANDs in the flat 6-to-64; select order wrong; X‾\overline X forgotten.

Teoria collegata