data/full_repos/permissive/134757352/mojo-io-shield/src/debouncer.v
data/verilator_xmls/1b41f38e-5030-4941-821a-b06b52385114.xml
module debouncer #(
    parameter LENGTH = 16
  )(
    input      clk,
    input      in,
    output reg out,
    output     down,
    output     up
  );

  reg btn_sync;
  reg [LENGTH-1 : 0] count;

  wire idle = (out == btn_sync);


  wire max_count = &count;


  assign down = ~idle & max_count &  out;
  assign up   = ~idle & max_count & ~out;


  always @(posedge clk) begin
    btn_sync <= in;
  end

  always @(posedge clk) begin
    if (idle) begin
      count <= 0;
    end else begin
      count <= count + 1'b1;
      if (max_count)
        out <= ~out;
    end
  end

endmodule
module debouncer #(
    parameter LENGTH = 16
  )(
    input      clk,
    input      in,
    output reg out,
    output     down,
    output     up
  );


  reg btn_sync;
  reg [LENGTH-1 : 0] count;

  wire idle = (out == btn_sync);


  wire max_count = &count;


  assign down = ~idle & max_count &  out;
  assign up   = ~idle & max_count & ~out;


  always @(posedge clk) begin
    btn_sync <= in;
  end

  always @(posedge clk) begin
    if (idle) begin
      count <= 0;
    end else begin
      count <= count + 1'b1;
      if (max_count)
        out <= ~out;
    end
  end

endmodule