data/full_repos/permissive/169373084/RomReader/src/debouncer.v
 line:23: before: "DEBOUNCE_VALUE"
data/verilator_xmls/3d775cbb-db61-4d90-83ff-15d127be9262.xml
module debouncer #
(
    DEBOUNCE_VALUE = 100
)
(
    input wire clk,
    input wire reset,
    input wire line,
    output reg debounced_line
);



reg [31:0] debounce_counter;

always @(posedge clk)
begin
    if (~reset)
    begin
        debounced_line <= line == 1 ? 1 : 0;
        debounce_counter <= 0;
    end
    else
    begin
        if (~line)
        begin

            if (debounced_line == 1)
            begin
                $display("falling edge detected");
                debounce_counter <= debounce_counter + 1;
                if (debounce_counter == DEBOUNCE_VALUE)
                begin
                    debounced_line <= 0;
                    debounce_counter <= 0;
                end
            end

            else
            begin

                debounced_line <= 0;
            end
        end
        else
        begin

            if (debounced_line == 0)
            begin
                $display("rising edge detected");
                debounce_counter <= debounce_counter + 1;
                if (debounce_counter == DEBOUNCE_VALUE)
                begin
                    debounced_line <= 1;
                    debounce_counter <= 0;
                end
            end

            else 
            begin

                debounced_line <= 1;
            end
        end
    end
end

endmodule
module debouncer #
(
    DEBOUNCE_VALUE = 100
)
(
    input wire clk,
    input wire reset,
    input wire line,
    output reg debounced_line
);




reg [31:0] debounce_counter;

always @(posedge clk)
begin
    if (~reset)
    begin
        debounced_line <= line == 1 ? 1 : 0;
        debounce_counter <= 0;
    end
    else
    begin
        if (~line)
        begin

            if (debounced_line == 1)
            begin
                $display("falling edge detected");
                debounce_counter <= debounce_counter + 1;
                if (debounce_counter == DEBOUNCE_VALUE)
                begin
                    debounced_line <= 0;
                    debounce_counter <= 0;
                end
            end

            else
            begin

                debounced_line <= 0;
            end
        end
        else
        begin

            if (debounced_line == 0)
            begin
                $display("rising edge detected");
                debounce_counter <= debounce_counter + 1;
                if (debounce_counter == DEBOUNCE_VALUE)
                begin
                    debounced_line <= 1;
                    debounce_counter <= 0;
                end
            end

            else 
            begin

                debounced_line <= 1;
            end
        end
    end
end

endmodule