summaryrefslogtreecommitdiff
path: root/rtl/debounce.sv
blob: dff9e9e2f51c1dcecbb407549b9375ad461c06a1 (plain)
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
module debounce
(
	input  logic clk,
	             dirty,
	output logic clean
);

	logic last;
	logic[15:0] clean_for;

	always @(posedge clk) begin
		last <= dirty;
		clean_for <= last == dirty ? clean_for + 1 : 0;

		if(&clean_for)
			clean <= last;
	end

	initial begin
		last = 0;
		clean = 0;
		clean_for = 0;
	end

endmodule