Combinational-Circuit Building Blocks: 7.1. Signal Names
Combinational-Circuit Building Blocks: 7.1. Signal Names
Signal Names
o Objectives o Choose signal names to:
n Indicate an action that is controlled (RESET, LOAD)
This chapter introduces several logical networks that are n A condition that is detected (READY, ERROR)
useful as buliding blocks for larger systems. The objectives of
this section are to: n The type of data carried on a bus (DATA, ADDRESS)
n Discuss naming conventions for digital signals.
o The Active Level for a signal is the level (high or low)
that causes the indicated action to occur. It is the level
n Define and demonstrate the operation of decoders, encoders that causes the signal to be asserted.
and multiplexers, including their use as universal gate
n Active Level notation:
networks.
High Low
n Demonstrate how Verilog can be used to model the RESET+ RESET-
behavior of these networks. RESET RESET*
RESET RESET/
o Reading Assignment RESET /RESET
RESET RESET_L
n Chapter 6 of the text by Brown and Vranesic. The last one is used in the text.
Elec 326 7.1 Combinational-Circuit Building Blocks Elec 326 7.2 Combinational-Circuit Building Blocks
Elec 326 7.3 Combinational-Circuit Building Blocks Elec 326 7.4 Combinational-Circuit Building Blocks
1
7.2. Decoders o Binary Decoders
o Decoders are used to map code words from one code into code n The most common decoders are binary decoders that
words from another code. translate the binary number code into a one-hot or 1-out-of-
o Decoders usually have enable inputs in addition to the code n code.
word inputs. n If there are n input terminals, then a complete decoder has
n When one or more of the enable inputs are deasserted, the outputs all 2n output terminals.
take on a default value. n There may be less than a complete decoding (e.g., decimal
u The default is usually 0 if the outputs are asserted high and 1 if they are numbers)
asserted low.
n Example: 2-to-4 binary decoder.
u The default could also be the high impedance state for tri-state outputs.
n When the enable inputs are all asserted, decoder translates an input
code into an output code.
Elec 326 7.5 Combinational-Circuit Building Blocks Elec 326 7.6 Combinational-Circuit Building Blocks
Elec 326 7.7 Combinational-Circuit Building Blocks Elec 326 7.8 Combinational-Circuit Building Blocks
2
7.3. Verilog Descriptions of Decoders o Verilog descriptions of a 2-to-4 decoder constructed from five
copies of the dec2to4 module:
o The Verilog Case Statement
n This statement can be used within always blocks to select
one of serveral alternatives. module dec2to4(W, Y, En);
input [1:0] W;
n General form: Case (expression) input En;
alternative 1: statement; output [0:3] Y;
alternative 2: statement; reg [0:3] Y;
.
. always @(W or En)
. case ({en,W})
alternative 3: statement; 3’b100: Y = 4’b1000;
[default: statement]; 3’b101: Y = 4’b0100;
endcase 3’b110: Y = 4’b0010;
3’b111: Y = 4’b0001;
default: Y = 4’b0000;
u The statement associated with the first alternative to match the
value of the expression is executed. endcase
u If the expression does not match any alternative and there is a endmodule
default statement, it is executed;
Elec 326 7.9 Combinational-Circuit Building Blocks Elec 326 7.10 Combinational-Circuit Building Blocks
Elec 326 7.11 Combinational-Circuit Building Blocks Elec 326 7.12 Combinational-Circuit Building Blocks
3
o Verilog description of a 4-to-16 decoder constructed as a tree o The Verilog “for loop”
of 2-to-4 decoders:
n Syntax:
module dec4to16 (W, Y, En); for (initial_index; terminal_index; increment) statement;
input [3:0] W; n Example: A 2-to-4 binary decoder specified using the for
input En; loop.
output [0:15] Y; module dec2to4 (W, Y, En);
wire [0:3] M; input [1:0] W;
input En;
dec2to4 Dec1 (W[3:2], M[0:3], En); output [0:3] Y;
dec2to4 Dec2 (W[1:0], Y[0:3], M[0]); reg [0:3] Y;
dec2to4 Dec3 (W[1:0], Y[4:7], M[1]); integer k;
dec2to4 Dec4 (W[1:0], Y[8:11], M[2]);
dec2to4 Dec5 (W[1:0], Y[12:15], M[3]); always @(W or En)
for (k = 0; k <= 3; k = k+1)
endmodule if ((W==k) && (En==1))
Y[k] = 1;
else
Y[k] = 0;
endmodule
Elec 326 7.13 Combinational-Circuit Building Blocks Elec 326 7.14 Combinational-Circuit Building Blocks
Elec 326 7.15 Combinational-Circuit Building Blocks Elec 326 7.16 Combinational-Circuit Building Blocks
4
o Examples Of Multiplexer Chips o Cascading multiplexers
Elec 326 7.17 Combinational-Circuit Building Blocks Elec 326 7.18 Combinational-Circuit Building Blocks
endmodule
Elec 326 7.19 Combinational-Circuit Building Blocks Elec 326 7.20 Combinational-Circuit Building Blocks
5
o Description of a 4-to-1 MUX using if-then-else o Description of a 4-to-1 MUX using a case statement:
statements:
module mux4to1 (W, S, f);
module mux4to1 (W, S, f); input [0:3] W;
input [0:3] W; input [1:0] S;
input [1:0] S; output f;
output f; reg f;
reg f;
always @(W or S)
always @(W or S) case (S)
if (S == 0) 0: f = W[0];
f = W[0]; 1: f = W[1];
else if (S == 1) 2: f = W[2];
f = W[1]; 3: f = W[3];
else if (S == 2) endcase
f = W[2];
else if (S == 3) endmodule
f = W[3];
endmodule
Elec 326 7.21 Combinational-Circuit Building Blocks Elec 326 7.22 Combinational-Circuit Building Blocks
endmodule
Elec 326 7.23 Combinational-Circuit Building Blocks Elec 326 7.24 Combinational-Circuit Building Blocks
6
o Realizing a 4-variable function with a 3-to-8 Decoder 7.6. Encoders
o Encoders are code translators that perform a
transformation that is the inverse of a decoder
transformation.
o Binary encoders
n Binary decoders translate from the binary code to the one-
hot code.
n Binary encoders translate from the one-hot code to the
binary code.
Elec 326 7.25 Combinational-Circuit Building Blocks Elec 326 7.26 Combinational-Circuit Building Blocks
w3 w2 w1 w0 y1 y0 z
0 0 0 0 d d 0 y1 = w3’•w2 + w3
0 0 0 1 0 0 1
0 0 1 x 0 1 1 y2 = w3’•w2’•w1 + w3
Y2 = w7 + w6 + w5 + w4 0 1 x x 1 0 1
z = w0 + w1 + w2 + w3
1 x x x 1 1 1
Y1 = w7 + w6 + w3 + w2
Y0 = w7 + w5 + w3 + w1
n What is the purpose of the signal z?
Elec 326 7.27 Combinational-Circuit Building Blocks Elec 326 7.28 Combinational-Circuit Building Blocks
7
n Verilog description of a priority encoder:
o The Verilog casex and casez statements
module priority (W, Y, z);
n The x and/or z values in the alternatives of a regular case input [3:0] W;
statement must match exactly corresponding x and/or z output [1:0] Y;
signals in the controlling expression of the for loop. output z;
reg [1:0] Y;
n The z value is treated as a don’t care in the alternatives of a reg z;
casez statement.
always @(W)
n Both the x and z values are treated as a don’t cares in the begin
z = 1;
alternatives of a casex statement. casex (W)
n The alternatives do not have to be mutully exclusive in the 4’b1xxx: Y = 3;
4’b01xx: Y = 2;
casex and casez statements. 4’b001x: Y = 1;
u The first matching alternative has priority and is selected. 4’b0001: Y = 0;
default: begin
z=0;
Y = 2’bxx;
end
endcase
end
endmodule
Elec 326 7.29 Combinational-Circuit Building Blocks Elec 326 7.30 Combinational-Circuit Building Blocks
Elec 326 7.31 Combinational-Circuit Building Blocks Elec 326 7.32 Combinational-Circuit Building Blocks