/////////////////////////////////////////////////////////////////////////////// // // Pushbutton Debounce Module // /////////////////////////////////////////////////////////////////////////////// module debounce (reset, clk, noisy, clean); input reset, clk, noisy; output clean; parameter NDELAY = 650000; parameter NBITS = 20; reg [NBITS-1:0] count; reg xnew, clean; always @(posedge clk) if (reset) begin xnew <= noisy; clean <= noisy; count <= 0; end else if (noisy != xnew) begin xnew <= noisy; count <= 0; end else if (count == NDELAY) clean <= xnew; else count <= count+1; endmodule