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 bits has exactly one 1, in the position that identifies the value. With binary bits, become . Value on 8 bits is . It uses more bits but each bit "says" one thing only (also useful for machine states).
Decoder
An -to- decoder has inputs and outputs : it sets to 1 the output whose index is encoded by the inputs and the others to 0 ( if every combination is valid). Its outputs are the minterms of the inputs, (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 AND gates of inputs, each with its direct/negated input pattern.
gives ; 3-to-8 with input gives , .
- 1-to-2: , .
- 2-to-4: , , , : 2 inverters and 4 two-input ANDs.
Hierarchical construction and cost
For large decoders one -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 | 10 | |
| 3-to-8 hierarchical | 27 | |
| 6-to-64 hierarchical | 182 | |
| 6-to-64 flat | (64 six-input ANDs) | 390 |
Enable
With enable EN all outputs are 0. It is made with enabling ANDs on the outputs or, for large decoders () 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 : and : 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 ().
Example: BCD to seven segments
Segments (from the top, clockwise, then the middle one). Input: BCD digit ( = MSB). Table (1 = on; with segment , with ):
| 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 - as don't care, the seven Karnaugh maps give:
| segment | minimal SOP |
|---|---|
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 (): only and must be off: , , .
Encoder
The encoder is the inverse of the decoder: it receives a one-hot signal of bits and produces the -bit binary code. Octal-to-binary with inputs (one 1 at a time):
gives . Each output is the OR of the inputs whose index has that bit at 1. Only 8 of the input combinations are specified; the rest are don't care.
Two problems. (1) With two inputs at 1 (e.g. ) the output is the OR of the codes, , equal to that of : wrong. (2) With all inputs 0 the output is , the same as for .
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: if at least one input is 1, if all are 0 (then is don't care).
Four inputs, priority :
| 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 On : , , , the index of the highest active input . The priority encoder is the basis of interrupt priority handling.
Multiplexer
A -to-1 multiplexer (MUX) has data inputs , select inputs and an output : if equals in binary, . In general : the minterms of the select inputs act as "gates" for the data.
2-to-1: . 4-to-1: .
4-to-1 with : gives ; gives . 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: . With a decoder (2-to-4 generates the minterms, four 2-input enabling ANDs, a 4-input OR): . The latter is costlier but hierarchical and extensible: a 64-to-1 built so costs ; flat (6 inverters, 64 seven-input ANDs, one 64-input OR) .
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 ( each): . It selects among 4 registers of 4 bits.
Functions with a MUX
variables, -to-1 MUX: the variables go to the select inputs (the most significant to ) and the data inputs get the truth-table values, , constants 0 or 1. For row the MUX selects , exactly what must output.
with a 4-to-1 MUX and : , , , .
variables, -to-1 MUX (last variable as data): connect variables to the select inputs and apply to the data inputs , , the remaining variable or . For each select value the two rows ( and ) give a pair:
data input 0 0 1 1 0 1 1 0
Example. with an 8-to-1 MUX and :
| minterms | |||
|---|---|---|---|
| 000 | |||
| 001 | |||
| 010 | |||
| 011 | |||
| 100 | |||
| 101 | |||
| 110 | |||
| 111 |
So , , , (mind the order: to , to ).
Full adder with 4-to-1 MUXes. Select , data : and for . Two 4-to-1 MUXes and an inverter replace two 8-to-1 MUXes. With don't cares a pair 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 for the pair .
- Thinking a MUX only "selects": it is a universal function generator.
Versione ripasso
- One-hot: one 1 per word; value on 8 bits is .
- Decoder -to-: binary to one-hot, , ANDs of inputs. . 2-to-4: , , , .
- Hierarchical cost (gate inputs): 2-to-4 ; 3-to-8 (2-to-4 + 1-to-2 + 8 two-input ANDs); 6-to-64 (two 3-to-8 + 64 two-input ANDs) vs flat.
- Enable: EN forces all outputs to 0; for feed EN to the decoder inputs.
- Function = decoder + OR of its minterms: , . More than half minterms: NOR of the minterms of .
- BCD to 7 segments: , , , , , , . Implementations: gates, 4-to-16 decoder + 7 ORs, 7 MUX 8-to-1.
- Encoder (octal): , , . Fails with two 1s () and with all 0 (looks like ).
- Priority encoder: priority plus valid output V. : , , ; . Basis of interrupt priorities.
- MUX -to-1: ; 2-to-1 ; 4-to-1 cost direct, with decoder; 64-to-1 hierarchical, flat; quad 4-to-1 .
- Function with MUX: variables on a -to-1: (: ). With a -to-1: data for pairs . with : , , , .
- Full adder with MUX 4-to-1: ; for .
- 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; forgotten.