Advertisement
aidanozo

Untitled

Oct 27th, 2024
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module debouncer #(
  2.     parameter p_counter_width = 2;
  3. )(
  4.     output wire o_w_out,
  5.     input wire i_w_in,
  6.     input wire i_w_clk,
  7.     input wire i_w_reset
  8. );
  9.     reg[(p_counter_width - 1):0] l_r_counter;
  10.     reg l_r_button;
  11.     always @(posedge i_w_clk) begin
  12.         if(i_w_reset) begin
  13.             l_r_counter <= 0;
  14.             l_r_button <= 0;
  15.         end else begin
  16.             if(i_w_in == l_r_button) begin
  17.                 l_r_counter <= 0;
  18.             end else begin
  19.                 if(l_r_counter[(p_counter_width - 1)] == 1'b1) begin
  20.                     l_r_button <= ~l_r_button;
  21.                     l_r_counter <= 0;
  22.                 end else begin
  23.                     l_r_counter <= l_r_counter + 1;
  24.                 end
  25.             end
  26.         end
  27.     end
  28.     assign o_w_out = l_r_button;
  29. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement