-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.sv
86 lines (82 loc) · 2.92 KB
/
control.sv
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
`timescale 1ns / 1ps
module control(input logic Clk, Reset_Load_Clear, Run, M,
output logic clr_ld, shift_en, add, subtract);
enum logic [4:0] {Idle, Add1, Add2, Add3, Add4, Add5, Add6, Add7, Add8, Subtract,
Shift1, Shift2, Shift3, Shift4, Shift5, Shift6, Shift7, Shift8, Reset} curr_state, next_state;
always_ff @ (posedge Clk)
begin
if (Reset_Load_Clear)
curr_state <= Idle;
else
curr_state <= next_state;
end
always_comb begin
next_state = curr_state;
unique case (curr_state)
Idle : if(Run)
next_state = Reset;
Reset : next_state = Add1;
Add1 : next_state = Shift1;
Add2 : next_state = Shift2;
Add3 : next_state = Shift3;
Add4 : next_state = Shift4;
Add5 : next_state = Shift5;
Add6 : next_state = Shift6;
Add7 : next_state = Shift7;
Subtract : next_state = Shift8;
Shift1 : next_state = Add2;
Shift2 : next_state = Add3;
Shift3 : next_state = Add4;
Shift4 : next_state = Add5;
Shift5 : next_state = Add6;
Shift6 : next_state = Add7;
Shift7 : next_state = Subtract;
Shift8 : if (~Run)
next_state = Idle;
endcase
case (curr_state)
Idle:
begin
clr_ld = 1'b0;
shift_en = 1'b0;
add = 1'b0;
subtract = 1'b0;
end
Reset:
begin
clr_ld = 1'b1;
shift_en = 1'b0;
add = 1'b0;
subtract = 1'b0;
end
Add1, Add2, Add3, Add4, Add5, Add6, Add7:
begin
clr_ld = 1'b0;
shift_en = 1'b0;
add = M;
subtract = 1'b0;
end
Subtract:
begin
clr_ld = 1'b0;
shift_en = 1'b0;
add = M;
subtract = M;
end
Shift1, Shift2, Shift3, Shift4, Shift5, Shift6, Shift7, Shift8:
begin
clr_ld = 1'b0;
shift_en = 1'b1;
add = 1'b0;
subtract = 1'b0;
end
default:
begin
clr_ld = 1'b0;
shift_en = 1'b0;
add = 1'b0;
subtract = 1'b0;
end
endcase
end
endmodule