-
Notifications
You must be signed in to change notification settings - Fork 2
/
alarm.v
121 lines (109 loc) · 3.01 KB
/
alarm.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
116
117
118
119
120
121
/* ------------------------------------------------ *
* Title : Alarm Module *
* Project : Digital Clock *
* ------------------------------------------------ *
* File : alarm.v *
* Author : Yigit Suoglu *
* Last Edit : 28/04/2020 *
* Licence : CERN-OHL-W *
* ------------------------------------------------ *
* Description : A clock alarm module *
* ------------------------------------------------ */
module alarmHex(clk, rst, en_in, time_in, time_set_in, set_time, ring, end_ring);
input clk, rst, set_time, end_ring, en_in;
output reg ring;
//Alarm is not sensitive to seconds
input [10:0] time_set_in, time_in;
reg [10:0] time_alarm;
reg en;
//set alarm time
always@(posedge clk or posedge rst)
begin
if(rst)
begin
time_alarm <= 11'd0;
end
else
begin
time_alarm <= (set_time) ? time_set_in : time_alarm;
end
end
//handle to ringing of the alarm
always@(posedge clk or posedge rst)
begin
if(rst)
begin
ring <= 1'b0;
end
else
begin
if(en)
begin
//while ringing: stop if end ring pressed
//otherwise start ringing when time is equal to snooze
ring <= (ring) ? (~end_ring) : (time_alarm == time_in);
end
end
end
//keep ringing shut after end_ring if high, but not disable for next day
always@(posedge clk)
begin
if(time_alarm == time_in)
begin
en <= (end_ring) ? 1'b0 : en;
end
else
begin
en <= en_in;
end
end
endmodule//alarm
module alarmDec(clk, rst, en_in, time_in, time_set_in, set_time, ring, end_ring);
input clk, rst, set_time, end_ring, en_in;
output reg ring;
//Alarm is not sensitive to seconds
input [12:0] time_set_in, time_in;
reg [12:0] time_alarm;
reg en;
//set alarm time
always@(posedge clk or posedge rst)
begin
if(rst)
begin
time_alarm <= 13'd0;
end
else
begin
time_alarm <= (set_time) ? time_set_in : time_alarm;
end
end
//handle to ringing of the alarm
always@(posedge clk or posedge rst)
begin
if(rst)
begin
ring <= 1'b0;
end
else
begin
if(en)
begin
//while ringing: stop if end ring pressed
//otherwise start ringing when time is equal to snooze
ring <= (ring) ? (~end_ring) : (time_alarm == time_in);
end
end
end
//keep ringing shut after end_ring if high, but not disable for next day
always@(posedge clk)
begin
if(time_alarm == time_in)
begin
en <= (end_ring) ? 1'b0 : en;
end
else
begin
en <= en_in;
end
end
endmodule//alarm