Unit 1 Part1 Notes
Unit 1 Part1 Notes
Analysis Procedure
• The analysis is to determine the function of an implemented circuit.
• The task starts with a given logic diagram and culminates with a set of Boolean
functions, a truth table, or, possibly, an explanation of the circuit operation.
• The analysis can be performed manually by finding the Boolean functions or truth table
or by using a computer simulation program.
• The first step in the analysis is to make sure that the given circuit is combinational and
not sequential.
• A combinational circuit has no feedback paths or memory elements.
• A feedback path is a connection from the output of one gate to the input of a second
gate whose output forms part of the input to the first gate.
• Feedback paths in a digital circuit define a sequential circuit.
Design Procedure
• The design is to derive a logic circuit or a set of Boolean functions from the
specification of the design objective.
• The design procedure involves the following steps:
• From the specifications of the circuit, determine the required number of inputs and
outputs and assign a symbol to each.
• Derive the truth table that defines the required relationship between inputs and outputs.
• Obtain the simplified Boolean functions for each output as a function of the input
variables.
• Draw the logic diagram and verify the correctness of the design (manually or by
simulation).
ENCODERS
The inverse function of a decoder.
• 2n (or fewer) input lines and n output lines.
• The output lines generate the binary code corresponding to the input value.
Testbench
module encoder_tb ();
reg [7:0] d;
wire x, y, z;
encoder8_3(d, x, y, z);
initial
begin
d=8’b00000001;
d=8’b00000010;
d=8’b00000100;
d=8’b00001000;
d=8’b00010000;
d=8’b00100000;
d=8’b01000000;
d=8’b10000000;
end
endmodule
PRIORITY ENCODER
Encoder that includes the priority function.
• Resolve the ambiguity of illegal inputs, only one of the inputs is encoded.
• The input having the highest priority will take precedence.
Testbench
2:4 Decoder
module decoder2_4(y,d);
input [1:0]d;
output reg [3:0]y;
always @(*)
begin
case(d)
2’b00: y=4’b0001:
2’b01: y=4’b0010:
2’b10: y=4’b0100:
2’b11: y=4’b1000:
endcase
end
endmodule
MULTIPLEXERS
• Select from one of many inputs and directs it to a single output, controlled by a set of
selection lines.
• A multiplexer is also called a data selector.
• Normally, there are 2n inputs and n selection lines whose bit combinations determine
which input is selected.
4:1 Mux – RTL Code and Testbench
module mux4_1 (y, s1, s0, d);
input [3:0] d;
input s1, s0;
output reg y;
always @ (s1, s0, d)
begin
case ({s1, s0})
2’b00: y=d [0];
2’b01: y=d [1];
2’b10: y=d [2];
2’b11: y=d [3];
endcase
end
endmodule
Testbench
module mux4_1tb ().
reg s1, s0;
reg [3:0] d;
wire y;
mux 4_1 n1(y, s1, s0, d);
initial
begin
#5 $ monitor (“s1=%b s0=%b d=%b y=%b”, s1, s0, d, y);
d=4’b1010;
s1=1’b0; s0=1’b0;
s1=1’b0; s0=1’b1;
s1=1’b1; s0=1’b0;
s1=1’b0; s0=1’b1;
#5 $finish
end
endmodule
Testbench
module Demuxtb;
reg [1:0] S;
reg I;
wire [3:0] Y;
Demux1_4 n1(Y, S, I);
initial
begin
S=2’b00;
I=1’b1;
#5 S=2’b01;
#5 S=2’b10;
#5 S=2’b11;
$monitor (“S=%b,I=%b,Y=%b”,S,I,Y);
end
endmodule
4-bit Comparator
Testbench
module comptb;
reg [3:0] a,b;
wire alb, agb, aeb;
comp4bit n1(alb, agb, aeb, a, b);
initial
begin
a = 4'b1010;
b = 4'b0101;
#20 a=4’b0001;
#40 b=4’b0001;
$monitor (“a=%b, b=%b, alb=%b, aeb=%b, agb=%b”a,b,alb, aeb, agb);
end
endmodule