-
Notifications
You must be signed in to change notification settings - Fork 2
/
Memory_FSM.v
143 lines (137 loc) · 2.93 KB
/
Memory_FSM.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// company:
// Engineer:
//
// create Date: 14:01:00 09/24/2015
// Design Name:
// Module Name: Memory_FSM
// project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File created
// additional comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Memory_FSM(
input clk,
input reset_btn,
output [6:0] seven_segment,
output [3:0] enable,
output [3:0] led
);
reg [14:0] port_a_address, port_b_address;
reg [15:0] port_a_in, port_b_in;
reg port_a_we, port_b_we;
wire [15:0] port_a_out, port_b_out;
reg [2:0] operation;
reg[15:0] output_to_display;
integer count;
reg[15:0] read_temp_1, read_temp_2;
Memory memory (
.port_a_address(port_a_address),
.port_b_address(port_b_address),
.port_a_in(port_a_in),
.port_b_in(port_b_in),
.port_a_we(port_a_we),
.port_b_we(port_b_we),
.clk(clk),
.port_a_out(port_a_out),
.port_b_out(port_b_out)
);
BCD_To_7Seg bcd (
.binary(output_to_display),
.clk(clk),
.seven_segment(seven_segment),
.enable(enable),
.leds(led)
);
//Where in memory to start the fibonacci.
parameter start_address = 15'd0;
always@ (posedge(clk))
begin
if(reset_btn == 1)
begin
count = 0;
operation = 0;
end
else if(count == 32'd150000000)
begin
count = 0;
if(operation == 5)
operation = 2;
else
operation = operation + 1;
end
else
count = count + 1;
case(operation)
0:
begin
//Write a 1 in the first address
port_a_address = start_address;
port_b_address = 0;
port_a_in = 16'd1;
port_b_in = 0;
port_a_we = 1;
port_b_we = 0;
output_to_display = port_a_out;
end
1:
begin
//Write a 1 in the next address
port_b_address = port_a_address + 1;
port_a_in = 0;
port_b_in = 16'd1;
port_a_we = 0;
port_b_we = 1;
output_to_display = port_b_out;
end
2:
begin
//Read both those addresses
port_a_in = 0;
port_b_in = 0;
port_a_we = 0;
port_b_we = 0;
read_temp_1 = port_a_out;
read_temp_2 = port_b_out;
end
3:
begin
//Write the sum of those values into the next address
port_a_address = port_a_address + 2;
port_a_in = read_temp_1 + read_temp_2;
port_b_in = 0;
port_a_we = 1;
port_b_we = 0;
output_to_display = port_a_out;
end
4:
begin
//Read last 2 addresses
port_a_in = 0;
port_b_in = 0;
port_a_we = 0;
port_b_we = 0;
read_temp_1 = port_a_out;
read_temp_2 = port_b_out;
end
5:
begin
//Write the sum of those values into the next address
port_b_address = port_b_address + 2;
port_a_in = 0;
port_b_in = read_temp_1 + read_temp_2;
port_a_we = 0;
port_b_we = 1;
output_to_display = port_b_out;
end
endcase
end
endmodule