Lab 2
Lab 2
Spring 2021
Lab Report 2
IMPLEMENTATION OF COMBINATIONAL CIRCUITS
Prepared By:
Shahzaib Ahmad Qureshi: F2016019065
Digital System Design LAB 2
OBJECTIVES
INTRODUCTION
A number of standard combinational logic functions have been developed for digital circuits
that represent many of the useful tasks that can be performed with digital circuits.
Decoders detect the presence of particular binary states and can activate other circuits based
on their input values or can convert an input code to a different output code.
Encoders generate a binary or binary coded decimal (BCD) code corresponding to an active
input.
Multiplexers and de-multiplexers are used for data routing. They select a transmission path
for incoming or outgoing data, based on a selection made by a set of binary-related inputs.
DECODERS
The general function of a decoder is to activate one or more circuit outputs upon detection of
a particular digital state. The simplest decoder is a single logic gate, such as a NAND or AND,
hose output activates when all its inputs are HIGH. When combined with one or more
inverters, a NAND or AND can detect any unique combination of binary input values. An
extension of this type of decoder is a device containing several such gates, each of which
responds to a different input state. Usually, for an n-bit input, there are 2n logic gates, each
of which decodes a different combination of input variables. Some types of decoders translate
binary inputs to other forms, such as the decoders that drive seven-segment numerical
displays. The decoder has one output for every segment in the display. These segments
Digital System Design LAB 2
illuminate in unique combinations for each input code. Figure 1 shows the logic circuit of a 2-
line-to-4-line decoder.
A Verilog module is shown below. Create a new project using Xilinx ISE. Add this module to
project and verify it by simulating its behavior.
module decoder_2x4_gates_tb;
//
Inputs
reg A;
reg B;
reg enable;
// Outputs
wire [0:3] D;
initial begin
// Initialize Inputs
A = 0;
B = 0;
enable = 0;
A = 1;
B = 0;
enable = 0;
A = 0;
B = 1;
enable = 0;
A = 1;
B = 1;
enable = 0;
// Wait
100 ns for global
reset to finish
#100;
// Add stimulus here
end
endmodule
Digital System Design LAB 2
From the output we can see that when the input is 0111 the output is 0. When the
_
Input is 1101 the output is 1. And when the input is 1011 the output is 0. And for 1110 the
_
output is 1.
_
Draw results from Test bench? Indicate Input & Output signals?
Digital System Design LAB 2
A Verilog module is shown below. Create a new project using Xilinx ISE. Add this module to
project and verify it by simulating its behavior.
module decoder_2x4_df (
initial begin
// Initialize Inputs
A = 0; B = 0; enable = 0; #100;
A = 1; B = 0; enable = 0; #100;
A = 0; B = 1; enable = 0; #100;
A = 1; B = 1; enable = 0; #100;
// Add stimulus here
end
endmodule
Digital System Design LAB 2
From the output we can see that when the input is 0111 the output is 0. When the
_
Input is 1111 the output is 1. And when the input is 1011 the output is 0. And for 1110 the
_
output is 1.
Draw results from Test bench? Indicate Input & Output signals?
Digital System Design LAB 2
MULTIPLEXER
Multiplexers are used for a variety of applications, including selection of one data stream out
of several choices, switching multiple-bit data from several channels to one multiple bit
output, sharing data on one output over time, and generating bit patterns or waveforms.
In Verilog, you must be aware that Case statements can be full or not full, and they can also
be parallel or not parallel. A Case statement is:
endmodule
Digital System Design LAB 2
initial begin
// Initialize Inputs
A = 0; B = 1; select = 0; #100;
A = 1; B = 1; select = 0; #100;
A = 0; B = 1; select = 0; #100;
A = 1; B = 0; select = 1; #100;
A = 0; B = 1; select = 1; #100;
A = 1; B = 0; select = 1; #100;
// Add stimulus here
end
endmodule
Draw results from Test bench? Indicate Input & Output signals?
Digital System Design LAB 2
initial begin
// Initialize Inputs
A = 1; B = 0; C = 0; D = 0; S0 = 0; S1 = 0; #100;
A = 0; B = 1; C = 0; D = 0; S0 = 1; S1 = 0; #100;
A = 0; B = 0; C = 1; D = 0; S0 = 0; S1 = 1; #100;
A = 0; B = 0; C = 0; D = 1; S0 = 1; S1 = 1; #100;
A = 0; B = 1; C = 1; D = 1; S0 = 0; S1 = 0; #100;
end
endmodule
Draw results from Test bench? Indicate Input & Output signals?
Observations/Comments/Explanation of Results