-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunController.v
115 lines (112 loc) · 2.62 KB
/
RunController.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
`timescale 1ns/1ps
module RunController(
clk,
state,
data,
hadFinish,
initTime,
finishTime,
sleepTime,
msg,
getSecond
);
input clk;
input [2:0] state;
input [25:0] data;
output reg hadFinish = 0;
output reg [2:0] initTime = 5;
output reg [2:0] finishTime = 5;
output reg [1:0] sleepTime = 3;
output reg [25:0] msg = 0;
output getSecond;
parameter shutDownST = 0, beginST = 1, setST = 2, runST = 3;
parameter errorST = 4, pauseST = 5, finishST = 6, sleepST = 7;
second s (clk, getSecond);
always @(posedge getSecond) begin
if (state == runST) begin
if (initTime == 3) begin
msg <= data;
end
else if (msg[25:23] != 0)
msg[25:23] <= msg[25:23] - 1;
else if (msg[22:19] != 0)
msg[22:19] <= msg[22:19] - 1;
else if (msg[18:16] != 0)
msg[18:16] <= msg[18:16] - 1;
else if (msg[15:13] != 0)
msg[15:13] <= msg[15:13] - 1;
else if (msg[12:10] != 0)
msg[12:10] <= msg[12:10] - 1;
else if (msg[9:6] != 0)
msg[9:6] <= msg[9:6] - 1;
else if (msg[5:3] != 0)
msg[5:3] <= msg[5:3] - 1;
else if (msg[2:0] != 0)
msg[2:0] <= msg[2:0] - 1;
else
hadFinish <= 1;
finishTime <= 5;
initTime <= 5;
sleepTime <= 3;
end
else if (state == beginST) begin
initTime <= initTime - 1;
finishTime <= 5;
msg <= data;
hadFinish <= 0;
sleepTime <= 3;
end
else if (state == finishST) begin
finishTime <= finishTime - 1;
initTime <= 5;
msg <= data;
hadFinish <= 0;
sleepTime <= 3;
end
else if (state == pauseST || state == errorST) begin
finishTime <= 5;
initTime <= 5;
msg <= msg;
hadFinish <= 0;
sleepTime <= 3;
end
else if (state == setST) begin
finishTime <= 5;
initTime <= 3;
msg <= data;
hadFinish <= 0;
sleepTime <= 3;
end
else if (state == sleepST) begin
sleepTime <= sleepTime - 1;
finishTime <= 5;
initTime <= 5;
msg <= msg;
hadFinish <= 0;
end
else begin
finishTime <= 5;
initTime <= 5;
msg <= data;
hadFinish <= 0;
sleepTime <= 3;
end
end
endmodule // RunController
module second(
input clk,
output reg cp
);
parameter delay = 5000;
integer count = 0;
initial begin
cp = 1;
end
always @(posedge clk) begin
count = count + 1;
if (count == delay) begin
cp = ~cp;
count = 0;
end
end
endmodule // second