-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimer.v
101 lines (87 loc) · 2.03 KB
/
timer.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
// Since the system clock is 50MHz, every 500,000th count corresponds to 0.01 seconds.
// The segments 'd', 'e', 'f', and 'h' are designed to reset to 0 when they reach 10. The segments 'g' and 'i' are designed to reset to 0 when they reach 6.
// If the previous value exceeds 10 or 6, the number in the next unit increases by +1.
// When a soft_reset or hard_reset is received, all segments return to 0.
module timer(
clk,
hard_reset,
sec_count,
soft_reset,
d,
e,
f,
g,
h,
i
);
input clk;
input hard_reset;
input [18:0] sec_count;
input soft_reset;
output reg [3:0] d;
output reg [3:0] e;
output reg [3:0] f;
output reg [3:0] g;
output reg [3:0] h;
output reg [3:0] i;
always@(posedge clk or negedge hard_reset) begin
if (~hard_reset) d<= 4'd0;
else begin
if ((d==4'd10) || ~soft_reset) d<= 4'd0;
else begin
if(sec_count == 19'd499_999) d<= d+4'd1;
else;
end
end
end
always@(posedge clk or negedge hard_reset) begin
if (~hard_reset) e<= 4'd0;
else begin
if ((e==4'd10) || ~soft_reset) e<= 4'd0;
else begin
if(d==4'd10) e<= e+4'd1;
else;
end
end
end
always@(posedge clk or negedge hard_reset) begin
if (~hard_reset) f<= 4'd0;
else begin
if ((f==4'd10) || ~soft_reset) f<= 4'd0;
else begin
if(e==4'd10) f<= f+4'd1;
else;
end
end
end
always@(posedge clk or negedge hard_reset) begin
if (~hard_reset) g<= 4'd0;
else begin
if ((g==4'd6) || ~soft_reset) g<= 4'd0;
else begin
if(f==4'd10) g<= g+4'd1;
else;
end
end
end
always@(posedge clk or negedge hard_reset) begin
if (~hard_reset) h<= 4'd0;
else begin
if ((h==4'd10) || ~soft_reset) h<= 4'd0;
else begin
if(g==4'd6) h<= h+4'd1;
else;
end
end
end
always@(posedge clk or negedge hard_reset) begin
if (~hard_reset) i<= 5'd0;
else begin
if ((i==4'd6) || ~soft_reset) i<= 4'd0;
else begin
if(h==4'd10) i<= i+4'd1;
else;
end
end
end
endmodule