-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmid-term-Q1.v
More file actions
73 lines (60 loc) · 1 KB
/
mid-term-Q1.v
File metadata and controls
73 lines (60 loc) · 1 KB
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
/* Author: Mayank Parasar */
module Q1( go_in, d_in, clk, valid_out, data_out );
input wire go_in;
input wire [7:0] d_in;
input wire clk;
output reg valid_out;
output reg [10:0] data_out = 11'b00000000000;
reg [10:0] sum_sig = 11'b0;
reg done_sig = 0;
reg [1:0]i_sig = 2'b00;
reg [1:0]i_reg = 2'b11;
reg [10:0]sum_reg = 11'b0;
reg PS = 0;
reg NS = 0;
always @(posedge clk)
begin
PS <=NS;
i_reg <= i_sig;
// $display("PS: %b", PS);
// $display("i_sig: %b, i_reg: %b", i_sig, i_reg);
end
always @(*) // check if this is the right way to code up the diagram
begin
case(PS)
2'b0:
begin
if (go_in == 0)
begin
NS = PS;
i_sig = i_reg;
end
else
begin
NS = 2'b01;
end
end
2'b1:
begin
sum_sig = sum_reg + d_in;
i_sig = i_reg - 1;
if (i_reg == 0)
begin
NS = 2'b00;
done_sig = 1;
end
else
begin
NS = PS;
end
end
default:
begin
done_sig = 0;
sum_sig= 0;
// i_sig = i_reg;
NS = 0;
end
endcase
end
endmodule