go-board-code/debounce_filter.v

31 lines
499 B
Coq
Raw Normal View History

2024-07-06 18:51:29 +00:00
module Debounce_Filter
#(parameter DEBOUNCE_LIMIT = 20) (
input i_Clk,
input i_Bouncy,
output o_Debounced
);
reg [$clog2(DEBOUNCE_LIMIT)-1:0] r_Count = 0;
reg r_State = 1'b0;
always @(posedge i_Clk)
begin
if (i_Bouncy !== r_State && r_Count < DEBOUNCE_LIMIT - 1)
begin
r_Count <= r_Count + 1;
end
else if (r_Count == DEBOUNCE_LIMIT - 1)
begin
r_State <= i_Bouncy;
r_Count <= 0;
end
else
begin
r_Count <= 0;
end
end
assign o_Debounced = r_State;
endmodule