data/full_repos/permissive/121410129/step5/debouncer.v
data/verilator_xmls/e1a3c100-b979-42f5-9179-a0d00fd699e9.xml
module debounce (clk, reset, noisy, clean);
parameter DELAY = 1000000;
input wire clk, reset, noisy;
output reg clean;

reg [19:0] count;
reg isPressed;

always @ (posedge clk or posedge reset) begin
	if(reset == 1) begin
		isPressed	<= 1'b0;
		clean 		<= 1'b0;
		count		<= 20'd0;
	end
	else begin
		if (noisy == 1'b1) begin
			if (count == DELAY) begin
				if (isPressed == 1'b0) begin
					clean		<= 1'b1;
					isPressed	<= 1'b1;
				end
				else begin
					clean		<= 1'b0;
				end
			end
			else begin
				clean <= 1'b0;
				count <= count + 20'd1;
			end
		end
		else begin
			clean		<= 1'b0;
			count		<= 20'd0;
			isPressed	<= 1'b0;
		end
	end
end
endmodule
module debounce (clk, reset, noisy, clean);

parameter DELAY = 1000000;
input wire clk, reset, noisy;
output reg clean;

reg [19:0] count;
reg isPressed;

always @ (posedge clk or posedge reset) begin
	if(reset == 1) begin
		isPressed	<= 1'b0;
		clean 		<= 1'b0;
		count		<= 20'd0;
	end
	else begin
		if (noisy == 1'b1) begin
			if (count == DELAY) begin
				if (isPressed == 1'b0) begin
					clean		<= 1'b1;
					isPressed	<= 1'b1;
				end
				else begin
					clean		<= 1'b0;
				end
			end
			else begin
				clean <= 1'b0;
				count <= count + 20'd1;
			end
		end
		else begin
			clean		<= 1'b0;
			count		<= 20'd0;
			isPressed	<= 1'b0;
		end
	end
end
endmodule