// Simple debouncer for 4 buttons.
// Choose "count" size so its period is longer than worst-case bounce.
module top (clk, button_in, button_out);
input clk; // my clock is 50 MHz
input [3:0] button_in; // four bouncy buttons
reg [19:0] count = 0; // period approximately 20 ms
reg [3:0] button_tmp = 0; // synchronize the inputs
output reg [3:0] button_out = 0; // four debounced buttons
always @ (posedge clk) begin
count <= count + 1;
button_tmp <= button_in;
if (count == 0)
button_out <= button_tmp;
end
endmodule