Skip to content

Instantly share code, notes, and snippets.

@bit-hack
Created October 6, 2021 17:20
Show Gist options
  • Save bit-hack/645fd2da1dc6ddb4fc1448d822a53e55 to your computer and use it in GitHub Desktop.
Save bit-hack/645fd2da1dc6ddb4fc1448d822a53e55 to your computer and use it in GitHub Desktop.
A simple verilog debouncer circuit
module debounce(
input clk,
input iKey,
output oOut,
);
reg [3:0] state;
assign oOut = state[3];
always @(posedge clk) begin
if (iKey) begin
state <= (state == 4'hf) ? 4'hf : (state + 1);
end else begin
state <= (state == 4'h0) ? 4'h0 : (state - 1);
end
end
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment