data/full_repos/permissive/517239653/debounce.v
data/verilator_xmls/5c09e44e-5603-452b-acc6-2f45b79cdd74.xml
module debounce(btn_out, clk, btn_in);

output btn_out;
input clk;
input btn_in;

parameter DEBOUNCE_CLKS = 2500000;

reg [31:0] counter = 0;
reg edge_detected = 0;
reg reset_edge_detect = 0;
reg btn_state = 1;

assign btn_out = btn_state;


always @(btn_in) begin
	if(btn_in != btn_state) begin
		edge_detected = 'b1;
	end else begin
		edge_detected ='b0;
	end
end

always @(posedge clk) begin
	if(edge_detected) begin
		counter = counter + 1;
		if(counter >= DEBOUNCE_CLKS) begin
			btn_state = ~btn_state;
			counter = 0;
		end
	end
end

endmodule
module debounce(btn_out, clk, btn_in);


output btn_out;
input clk;
input btn_in;

parameter DEBOUNCE_CLKS = 2500000;

reg [31:0] counter = 0;
reg edge_detected = 0;
reg reset_edge_detect = 0;
reg btn_state = 1;

assign btn_out = btn_state;


always @(btn_in) begin
	if(btn_in != btn_state) begin
		edge_detected = 'b1;
	end else begin
		edge_detected ='b0;
	end
end

always @(posedge clk) begin
	if(edge_detected) begin
		counter = counter + 1;
		if(counter >= DEBOUNCE_CLKS) begin
			btn_state = ~btn_state;
			counter = 0;
		end
	end
end

endmodule