-
Notifications
You must be signed in to change notification settings - Fork 1
/
time_gen.v
72 lines (61 loc) · 1.99 KB
/
time_gen.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
// ECE 4/530 Fall 2012
//
// David Poole 27-Oct-2012
//
// Generate wall clock seconds, minutes
`timescale 1 ns / 10 ps
module TIME_GEN
( input wire clk256, // input clock should be 256Hz
input wire reset,
input wire fast_mode, // when enabled, one_minute every second
output wire one_second,
output wire one_minute );
reg [8:0] sec_counter = 9'b0;
reg [5:0] min_counter = 6'b0;
reg int_one_minute = 1'b0;
// 256Hz means we can count once per clock in a 9-bit counter. The overflow
// (9th) bit is our one second clock.
always @(posedge clk256, posedge reset )
begin
if( reset )
begin
sec_counter <= 9'b0;
end
else
begin
sec_counter <= sec_counter + 9'b00000001;
end
end
// seconds_edge <= sec_counter[7];
// Want to increment the minute counter every second. Rather than adding a
// a compare on the sec_counter for 256*60, we will watch the 7th bit of
// the sec_counter (256). When the 7th bit transitions (once a second) we
// will udate our min_counter.
always @(posedge reset, posedge sec_counter[7])
// always @(posedge reset, posedge sec_counter[8], negedge sec_counter[8] )
begin
if( reset )
begin
int_one_minute <= 1'b0;
min_counter <= 6'b0;
end
else
begin
if( min_counter < 59 )
begin
min_counter <= min_counter + 1;
int_one_minute <= 0;
end
else
begin
min_counter <= 0;
int_one_minute <= 1;
end
end
end
// if fast mode is enabled, minutes will become seconds and seconds will
// become 1/4 seconds
// TODO need to ask what to really do about seconds in fastmode
assign one_second = fast_mode ? sec_counter[6] : sec_counter[7];
assign one_minute = fast_mode ? sec_counter[7] : int_one_minute;
endmodule