-
Notifications
You must be signed in to change notification settings - Fork 2
/
btn_debouncer.v
55 lines (45 loc) · 1.26 KB
/
btn_debouncer.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
/* ------------------------------------------ *
* Title : Button Debouncer *
* Project : Verilog Utility Modules *
* ------------------------------------------ *
* File : btn_debouncer.v *
* Author : Yigit Suoglu *
* Last Edit : 23/11/2020 *
* Licence : CERN-OHL-W *
* ------------------------------------------ *
* Description : Debouncer module for buttons *
* ------------------------------------------ */
module debouncer(clk, rst, in_n, out_c);
input clk, rst, in_n;
output out_c;
reg [1:0] mid;
always@(posedge clk or posedge rst)
begin
if(rst)
begin
mid <= 2'b0;
end
else
begin
mid <= {mid[0], in_n};
end
end
assign out_c = (~mid[1]) & mid[0]; //rising edge
endmodule // debouncer rising edge
module debouncer_fe(clk, rst, in_n, out_c);
input clk, rst, in_n;
output out_c;
reg [1:0] mid;
always@(posedge clk or posedge rst)
begin
if(rst)
begin
mid <= 2'b0;
end
else
begin
mid <= {mid[0], in_n};
end
end
assign out_c = mid[1] & (~mid[0]); //falling edge
endmodule // debouncer falling edge