Tải bản đầy đủ (.doc) (30 trang)

Đồ án HDL PROJECT REPORT VERILOG HDL SIMULATIONLABS

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (551.29 KB, 30 trang )

TRƯỜNG ĐẠI HỌC CẦN THƠ
KHOA CÔNG NGHỆ

HDL PROJECT REPORT

VERILOG HDL SIMULATION LABS
Group : 5
Instructor
Lê Hải Toàn

Group Member :
1/ Nguyễn Bá Quốc Huy
2/ Nguyễn Lê Khanh
3/ Lê Quốc Huy
4/ Dương Văn Đoan
5/ Nguyễn Tấn Tài
6/ Nguyễn Trung Nhân

HDL PROJECT REPORT

MSSV : B1306150
MSSV : B1306158
MSSV : B1306149
MSSV : B1306135
MSSV : B1306195
MSSV : B1306179

PAGE 1


TABLE OF CONTENT



Verilog HDL Simulation Labs ………………………………....Page 3
Lab 1 : Building Hierarchy …………………………………….Page 4
Lab 2 : Simulation/Verification ………………………………..Page 7
Lab 3 : Memory …………………………………………………Page 11
Lab 4 : n-bit binary counter ……………………………………Page 16
Lab 5 : Comparator …………………………………………….Page 22
Lab 6 :Arithmetic Logic Unit (ALU)…………………………..Page 26

HDL PROJECT REPORT

PAGE 2


Verilog HDL Simulation Labs
Overview
The Verilog simulation labs in this course are designed to maximize your
hands on introduction to Verilog coding. Therefore, you are asked to
create all hardware modules and testbenches from scratch. After finishing
these labs, you will gain the level of coding skill, syntax proficiency, and
understanding that can only be achieved through meaningful practice and
effort.
Most of the early lab exercises are standalone tasks that reinforce and
illustrate language concepts that are fundamental to all Verilog coding.

Objectives
After completing these labs, you will be able to:
• Write RTL descriptions for simple circuits
• Create a structural Verilog description for simple circuits
• Build hierarchy by using Verilog

• Create a Verilog testbench to verify the hierarchical structure created in
the
previous steps
• Use the simulation software
• Create basic input stimulus
• Run a simulation

Labs Outline
Lab 1: Building Hierarchy
Lab 2: Simulation/Verification
Lab 3: Memory
Lab 4: n-bit Binary Counter
Lab 5: Comparator
Lab 6: Arithmetic Logic Unit (ALU)

HDL PROJECT REPORT

PAGE 3


Lab 1: Building Hierarchy
Request :
In this lab, you will write a complete RTL description for the modules
MY_AND2 and MY_OR2 and build the circuit shown below (Figure 1)
in a structural Verilog description of the top-level module AND_OR

This lab comprises three primary steps: You will create a software
project; write RTL descriptions; and check the syntax of your RTL code.

HDL PROJECT REPORT


PAGE 4


Verilog Code:

// This is module AND_OR in Labs 1
// Design name : AND_OR
// File name
: AND_OR.v
// Coder
: Nhom 5
module AND_OR(
INP,
OUT1
);
input [3:0] INP;
output OUT1;
wire sig1, sig2;
and U0(sig1,INP[0],INP[1]);
and U1(sig2,INP[2],INP[3]);
or U3(OUT1,sig1,sig2);
endmodule

HDL PROJECT REPORT

PAGE 5


Synthesis output:


HDL PROJECT REPORT

PAGE 6


Lab 2: Simulation/Verification
Request :
In this lab, you will write a Verilog testbench for the AND_OR module
completed in the previous exercise. As part of the testbench, you will
create a simple input stimulus by using both concurrent and sequential
statements.
Examine the circuit below (Figure 2). In this lab, you will write a
complete Verilog testbench description for the module AND_OR.

This lab comprises four primary steps: You will create a new project and
import Verilog source files; create a testbench with the Verilog testbench
wizard in the simulation software; create initial and always input stimulus
statements; and, finally, verify the logic structure and functionality by
running a simulation and examining the resulting waveforms.

HDL PROJECT REPORT

PAGE 7


Verilog code:

module AND_OR_TB();
reg [3:0] inp_tb;

wire out_view;
initial
#10
#10
#10
#10
end

begin
inp_tb
inp_tb
inp_tb
inp_tb

=
=
=
=

4'b0000;
4'b1111;
4'b0011;
4'b0000;

always begin
#10 inp_tb = inp_tb + 1;
end
initial begin
$monitor("INP = %b , OUT = %d " ,
inp_tb,out_view);

#300 $stop;
end
AND_OR U_test( inp_tb , out_view);
endmodule

HDL PROJECT REPORT

PAGE 8


Simulation Result:

HDL PROJECT REPORT

PAGE 9


Waveforms:

HDL PROJECT REPORT

PAGE 10


Lab 3: Memory (ROM)
Request :
In this lab, you will write a complete RTL description for a ROM module
by using a one-dimensional array and a Verilog reg data type and a case
statement.


The memory was modeled as a ROM, which is a constant; therefore, you
were required to assign values at the time of declaration.
This lab comprises three primary steps: You will create a one
dimensional
memory array using case statement; create a testbench with the Verilog
testbench wizard in the simulation software; finally, verify the logic
structure and functionality by running a simulation and examining the
resulting waveforms.

HDL PROJECT REPORT

PAGE 11


Verilog Code:
//
This is a ROM module by using a
one-dimensional array
//
and a Verilog reg data type and a
case statement.
//File
: rom_case.v
//Coder
: Nhom 5
module rom_case(
address
,
read_en
,

clk
,
data
);
input [3:0] address;
input read_en;
input clk;
output [7:0] data;
reg [7:0] data;
always @(posedge clk, read_en) begin
if (read_en == 0) data = 0'bzzzzzzzz;
else
case (address)
0: data = 8'b1111_1110;
1: data = 8'b1111_1101;
2: data = 8'b1111_1011;
3: data = 8'b1111_0111;
4: data = 8'b1110_1111;
5: data = 8'b1101_1111;
6: data = 8'b1011_1111;
7: data = 8'b0111_1111;
8: data = 8'b0000_1000;
9: data = 8'b0000_1001;
default: data = 8'bzzzz_zzzz;
endcase
end
endmodule

HDL PROJECT REPORT


PAGE 12


Testbench:

module rom_case_tb();
reg [3:0] address_tb;
reg clk, read_en_tb;
wire [7:0] data_tb;
initial begin
$monitor("Address = %b , read_en
= %d , data = %b",
address_tb,
read_en_tb,
data_tb
);
#200 $stop
;
end
initial begin
clk = 0;
read_en_tb = 0;
#20 read_en_tb = 1;
#10 address_tb = 8;
#10 address_tb = 0;
repeat (16) #10 address_tb =
address_tb + 1;
end
always #5 clk = !clk;
rom_case ROM_version1 (

.address (address_tb)
.clk
(clk)
.read_en (read_en_tb)
.data
(data_tb)
);
endmodule

HDL PROJECT REPORT

,
,
,

PAGE 13


Simulation result:

HDL PROJECT REPORT

PAGE 14


Waveforms
HDL PROJECT REPORT

PAGE 15



Lab 4 Counter
Request :
In this lab, you will write a complete RTL description for the module
CNTR by using parameter statements to specify the bit width. This is an
n-bit binary, up/down, loadable counter, with active-Low asynchronous
reset. You will then build a Verilog HDL testbench to verify the
functionality of the RTL code as well as the hardware it models.
Examine the circuit below (Figure 3). In this exercise, you will create a
fully functional binary counter that can be dynamically scaled to any
length. The use of parameter statements is an important tool for module
reuse and source code readability. The circuit is an n-bit binary, up/down
loadable counter, with active- Low asynchronous reset.

This lab comprises three primary steps: You will create a software project; declare
the parameter statements; and, finally, create a testbench to verify the design.
Create the input stimulus:
1. Set the CLOCK input to toggle at a rate of 100 MHz
2. Assert the RESET input at time 15 ns, hold for 25 ns, then de-assert
3. Set the CE input initially High, de-assert (set Low) at time 300, hold for 100 ns,
reassert
4. Set the LOAD input initially Low, toggle High at time 500 ns, for one full clock
cycle
5. Set UPDN to initially High, then Low at time 750 ns
7. Set the D_IN input value to 8’h0F or 8’b00001111
HDL PROJECT REPORT

PAGE 16



Verilog Code:
// This is an n-bit binary, up/down, loadable
counter,
// with active-low asynchronous reset
// Coder: Nhom 5
module CNTR(
d_in,
ce,
load,
updn,
clk,
rst,
q_out
);
parameter n = 4;
input
input
input
input
input
input

[n-1:0] d_in;
ce;
load;
updn;
clk;
rst;

output [n-1:0] q_out;

reg [n-1:0] q_o;
initial q_o = 0;
always @(posedge clk) begin
if
(rst == 1'b0) q_o = 1'b0;
//Reset ve 0
else if (ce == 1)
if
(load == 1) q_o = d_in;
//Load dl tu d_in
else if (updn == 1) q_o = q_o
+1; //Dem len
else
q_o = q_o
-1; //Dem xuong
else
q_o = q_o;
end
assign q_out = (ce)? q_o : 16'bz;
//n<=16,
n>16 mach ko dung
endmodule
HDL PROJECT REPORT

PAGE 17


Testbench
// This is an testbench for 8-bit binary, up/down, loadable
counter,

// with active-low asynchronous reset
// Coder: Nhom 5
module CNTR_TB ();
reg [7:0] d_in_tb;
reg clk_tb;
reg ce_tb;
reg load_tb;
reg rst_tb;
reg updn_tb;
wire [7:0] q_out_tb;
always #10 clk_tb = !clk_tb;
initial fork
clk_tb = 0;
begin
time 15 ns
#15 rst_tb = 0;
assert
#25 rst_tb = 1;
end
ce_tb = 1;
begin
#300 ce_tb = 0;
#100 ce_tb = 1;
end
load_tb = 0;
begin
#500 load_tb = 1;
#20 load_tb = 0;
end
updn_tb = 1;

#750 updn_tb = 0;
d_in_tb = 8'h0F;
join

//Assert the Reset input at
//hold for 25 ns, then de-

//Chip enable initially is High
//set Low at the time 300,
//hold for 100 ns, reassert
//Load initially Low,
//toggle High at time 500ns
//full clock cycle

CNTR #(8) my_counter(
.d_in
(d_in_tb) ,
.clk
(clk_tb),
.ce
(ce_tb),
.load
(load_tb),
.updn
(updn_tb),
.rst
(rst_tb),
.q_out (q_out_tb));
endmodule


HDL PROJECT REPORT

PAGE 18


HDL PROJECT REPORT

PAGE 19


HDL PROJECT REPORT

PAGE 20


Waveforms:
HDL PROJECT REPORT

PAGE 21


Lab 5 Comparator
Request :
In this lab, you will write description for the module COMP
(Synchronous Comparator) using an if/else statement.
Examine the circuit below (Figure 4):

This lab comprises four primary steps: You will create a software project;
create an RTL version of COMP; and, finally, create a testbench to verify
that the behavioral model functions correctly.

If the expected result and the data are equal, the result is TRUE;
otherwise, the result is FALSE.
Declarations of input and output are shown in the following table:

HDL PROJECT REPORT

PAGE 22


Verilog code:

// Module name
// File
// Coder

:
:
:

comp
comp.v
Nhom 5

module comp(
expected,
data,
enable,
clk,
result);
input [3:0] expected;

input [3:0] data;
input clk;
input enable;
output result;
reg result;
initial result = 1'bz;
always @(posedge clk)
if (enable)
if (expected == data)
result = 1'b1;
else
result = 1'b0;
else result = 1'bz;
endmodule

HDL PROJECT REPORT

PAGE 23


Testbench:
//Module name :
comp_tb
//
-> comparator testbench
//File name
:
comp_tb.v
//Coder
:

Nhom 5
module comp_tb();
reg [3:0] expected ;
reg clk;
reg enable;
reg [3:0] data;
wire result;
initial begin
clk = 0;
data = 0;
expected =0;
end
initial begin
#10 enable = 0;
#5 enable = 1;
#5 data
= 1;
#10 data
= 1;
expected = 1;
#5 expected = 0;
#10 data
= 5;
expected = 4;
#5 expected = 5;
end
always #5 clk = !clk;
comp compare1(
.expected (expected),
.clk

(clk),
.enable
(enable),
.data
(data),
.result
(result)
);
endmodule

HDL PROJECT REPORT

PAGE 24


Waveform

HDL PROJECT REPORT

PAGE 25


×