-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.v
More file actions
104 lines (87 loc) · 2.85 KB
/
timer.v
File metadata and controls
104 lines (87 loc) · 2.85 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
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
module timer (HEX0, HEX1, HEX2, HEX3, CLOCK_50, timer_enable);
input CLOCK_50;
output [6:0] HEX0;
output [6:0] HEX1;
output [6:0] HEX2;
output [6:0] HEX3;
reg [1:0] Sel;
wire [3:0] seconds, seconds2, minutes, minutes2;
wire enable;
wire [25:0] counter;
input timer_enable;
wire [25:0] upperBound;
assign upperBound = 26'b010111110101111000001111111;
rateDividerForTime r(CLOCK_50, upperBound, enable,counter);
fourbitcounter c(enable, timer_enable, CLOCK_50, seconds, seconds2, minutes, minutes2);
hexDisplay H0(seconds[3:0], HEX0);
hexDisplay H1(seconds2[3:0], HEX1);
hexDisplay H2(minutes[3:0], HEX2);
hexDisplay H3(minutes2[3:0], HEX3);
endmodule
module rateDividerForTime(input clock, input [25:0] upperBound, output reg enable, output reg [25:0] counter);
always @(posedge clock)
begin
if (counter === 26'bx)
begin
counter <= 26'b0;
end
else if (counter == upperBound)
begin
enable= 1'b1;
counter <= 26'b0;
end
else
begin
enable = 1'b0;
counter <= counter + 1 ;
end
end
endmodule
module fourbitcounter(input enable, input timer_enable, clock, output reg [3:0] seconds, output reg [3:0] seconds2, output reg [3:0] minutes, output reg [3:0] minutes2);
initial minutes2 = 0;
always @(posedge clock) // triggered every time clock rises
begin
if ((enable == 1'b1) && (timer_enable == 1'b1))
begin
seconds <= seconds + 1;
if ((seconds % 9) == 0 && (seconds != 0)) begin
seconds <= 0 ;
seconds2 <= seconds2 + 1;
end
if ((seconds2 == 5) && (seconds == 9)) begin
seconds2 <= 0;
seconds <= 0;
minutes <= minutes + 1;
end
if (((minutes % 9) == 0) && (minutes != 0) && (seconds2 == 5) && (seconds == 9)) begin
seconds <= 0;
seconds2 <= 0;
minutes <= 0;
minutes2 <= minutes2 + 1;
end
end
else if (timer_enable == 1'b0) begin
seconds <= 0;
seconds2 <= 0;
minutes <= 0;
minutes2 <= 0;
end
end
endmodule
module hexDisplay(input [3:0] SW, output [6:0] HEX0);
reg c0,c1,c2,c3;
always @(*)
begin
c3=SW[3];
c2=SW[2];
c1=SW[1];
c0=SW[0];
end
assign HEX0[0]=~((c3|c2|c1|~c0)&(c3|~c2|c1|c0)&(~c3|c2|~c1|~c0)&(~c3|~c2|c1|~c0));
assign HEX0[1]=~((c3|~c2|c1|~c0)& (c3|~c2|~c1|c0)&(~c3|c2|~c1|~c0)&(~c3|~c2|c1|c0)&(~c3|~c2|~c1|c0)& (~c3|~c2|~c1|~c0));
assign HEX0[2]=~((c3|c2|~c1|c0)&(~c3|~c2|c1|c0)&(~c3|~c2|~c1|c0)&(~c3|~c2|~c1|~c0));
assign HEX0[3]=~((c3|c2|c1|~c0)&(c3|~c2|c1|c0)&(c3|~c2|~c1|~c0)&(~c3|c2|~c1|c0)&(~c3|~c2|~c1|~c0));
assign HEX0[4]=~((c3|c2|c1|~c0)&(c3|c2|~c1|~c0)&(c3|~c2|c1|c0)&(c3|~c2|c1|~c0)&(c3|~c2|~c1|~c0)&(~c3|c2|c1|~c0));
assign HEX0[5]=~((c3|c2|c1|~c0)&(c3|c2|~c1|c0)&(c3|c2|~c1|~c0)&(c3|~c2|~c1|~c0)&(~c3|~c2|c1|~c0));
assign HEX0[6]=~((c3|c2|c1|c0)&(c3|c2|c1|~c0)&(c3|~c2|~c1|~c0)& (~c3|~c2|c1|c0));
endmodule