National University of Science and Technology: Digital System Design (EE-421) Assignment #1
National University of Science and Technology: Digital System Design (EE-421) Assignment #1
TECHNOLOGY
Group Members
Name CMS ID
Tariq Umar 334943
Danial Ahmed 331388
Table of Contents
• Introduction
• Structure
• Modules
I. ROM
II. Counter
III. MUX
IV. Decoder
V. Registers
VI. ALU
VII. Binary to HEX
VIII. Clock
• Fibonacci File
• Simulations
i) Hardware Simulation
ii) RTL Viewer
iii) Test bench Simulation
• Conclusion
Structure
We were given the main structure of the Number crunching machine to perform the
Fibonacci sequence. We started by making separate modules for each portion which
includes ALU, Registers, MUX, Decoder, Counter and ROM. In the end, we stitched
it all up together in the Top Module which we have named as ‘Assignment’.
Our process starts from the ROM, to which we have stored all the instructions at the
beginning. We will be using a 4-bit counter connected to address line of instruction
memory, such that initially the value of counter is zero. As soon as the positive edge
of clock comes, zeroth instruction is executed by our design as well as the counter
gets incremented.
The 8-bit wide instruction will then control the ALU and registers to perform our
Arithmetic operations accordingly.
Top Module:
We have named our top module as ‘Assignment’ and we have instantiated all other
modules in this. This is our Top level entity and stiches all the other modules
together.
wire Reset;
wire Load;
wire [3:0]Custom_in;
wire s_cin;
wire J;
wire C;
wire Sreg;
wire [3:0]Mux_out;
wire Ra_en;
wire Rb_en;
wire Ro_en;
wire Carry_out;
wire [1:0]Dec_in;
wire [3:0]Dec_out;
/// Assignments ///
rom r1(
//.clk(clk),
.clk(CLOCK_50), //For Simulation Purpose
.addr(Counter_out),
.q(Code)
flop4e Ra (
// .clk(clk),
.clk(CLOCK_50), //For Simulation Purpose
.d(Mux_out),
.q(Ra_out),
.enable(Ra_en),
.Reset(Reset)
);
flop4e Rb (
// .clk(clk),
.clk(CLOCK_50), //For Simulation Purpose
.d(Mux_out),
.q(Rb_out) ,
.enable(Rb_en),
.Reset(Reset)
);
flop4e Ro (
// .clk(clk),
.clk(CLOCK_50), //For Simulation Purpose
.d(Ra_out),
.q(Ro_out) ,
.enable(Ro_en),
.Reset(Reset)
);
flop4e Ra (
// .clk(clk),
.clk(CLOCK_50), //For Simulation Purpose
.d(Mux_out),
.q(Ra_out),
.enable(Ra_en),
.Reset(Reset)
);
flop4e Rb (
// .clk(clk),
.clk(CLOCK_50), //For Simulation Purpose
.d(Mux_out),
.q(Rb_out) ,
.enable(Rb_en),
.Reset(Reset)
);
flop4e Ro (
// .clk(clk),
.clk(CLOCK_50), //For Simulation Purpose
.d(Ra_out),
.q(Ro_out) ,
.enable(Ro_en),
.Reset(Reset)
);
flop f1(
// .clk(clk),
.clk(CLOCK_50), //For Simulation Purpose
.d(ALU_out[4]),
.Reset(Reset),
.q(Carry_out)
);
dec_2to4 dec1 (
.D(Dec_in),
.O(Dec_out)
);
mux_4b_2to1 m1 (
.s(Sreg),
.u(ALU_out[3:0]),
.v(Custom_in),
.m(Mux_out)
);
endmodule
module rom
#(parameter DATA_WIDTH=8, parameter ADDR_WIDTH=4)
(
input clk,
input [(ADDR_WIDTH-1):0] addr,
output [(DATA_WIDTH-1):0] q
);
initial
begin
$readmemb("C:/intelFPGA_lite/20.1/projects/Assignment1/Fibonacci.txt", rom);
end
assign q = rom[addr];
endmodule
module Counter (
input clk,
input [3:0] Custom_input,
input Load,
input Reset,
output reg [3:0] Counter_out
);
always @ (posedge clk, negedge Reset) begin
if(Reset == 0)
Counter_out <= 4'b0000;
else if (Load)
Counter_out <= Custom_input;
else
Counter_out <= Counter_out + 1;
end
endmodule
module mux_4b_2to1 (
input s,
input [3:0] u,
input [3:0] v,
output reg [3:0] m
);
always @(*) begin
case (s)
1'b0: begin
m = u;
end
1'b1: begin
m = v;
end
default: begin
m = 4'b0000;
end
endcase
end
endmodule
if (Reset == 0) begin
q <= 4'b0000;
end else if(enable == 1)begin
q <= d;
end else begin
q <= q;
end
end
endmodule
module Fourbitadder(
input s_cin,
input [3:0]a,
input [3:0]b,
output reg [4:0]s
);
always@(*)
begin
if(s_cin==0)
s = a + b;
else
s = a - b;
end
endmodule
module Binary2HEX (
input [3:0]Bin,
output reg [6:0]HEX0,
output reg [6:0]HEX1
);
reg [3:0]OUT;
always @(Bin)
begin
OUT = Bin;
if (Bin < 4'b1010) begin
HEX1 = 7'b1000000;
end else begin
HEX1 = 7'b1111001;
OUT = Bin - 10;
end
case (OUT)
0 : HEX0 = 7'b1000000;
1 : HEX0 = 7'b1111001;
2 : HEX0 = 7'b0100100;
3 : HEX0 = 7'b0110000;
4 : HEX0 = 7'b0011001;
5 : HEX0 = 7'b0010010;
6 : HEX0 = 7'b0000010;
7 : HEX0 = 7'b1111000;
8 : HEX0 = 7'b0000000;
9 : HEX0 = 7'b0010000;
default : HEX0 = 7'b1111111;
endcase
end
endmodule
Conclusion:
In this assignment, we made a 4-bit Microprocessor that can perform Addition as
well as Subtraction. It uses an 8-bit Opcode that tells the microprocessor what to do.
It also has one of the basic functions like performing a number of instruction multiple
by jumping the flow of commands from one point to another within the memory of
the ROM.
In this assignment, we used this microprocessor to display the Fibonacci series from
0-13 in a loop, with an option to reset to 0 at any point. The results were displayed
on 7-Segment. This was implemented on Intel’s DE10-Standard FPGA board.