data/full_repos/permissive/423014416/MA7_Clock.srcs/sources_1/new/ButtonDebouncer.v
data/verilator_xmls/f280018e-f37e-40f9-808c-b83f6f3878e3.xml
module ButtonDebouncer(
    input clk,
    input buttonState,

    output reg debouncedState,
    output reg debouncedPosedgePulse,
    output reg debouncedNegedgePulse
);

    reg [23:0] debouncerReg;
    initial begin
        debouncedState = 0;
        debouncedPosedgePulse = 0;
        debouncedNegedgePulse = 0;
    end
    always @(negedge clk) begin


        if (|debouncerReg) 
            debouncerReg <= debouncerReg + 1;


        if (buttonState != debouncedState && ~|debouncerReg)
        begin
            debouncerReg <= debouncerReg + 1;
            debouncedState <= buttonState;
            if (debouncedState)
                debouncedPosedgePulse <= 1;
            else
                debouncedNegedgePulse <= 1;
        end else begin
            debouncedPosedgePulse <= 0;
            debouncedNegedgePulse <= 0;
        end

    end

endmodule
module ButtonDebouncer(
    input clk,
    input buttonState,

    output reg debouncedState,
    output reg debouncedPosedgePulse,
    output reg debouncedNegedgePulse
);


    reg [23:0] debouncerReg;
    initial begin
        debouncedState = 0;
        debouncedPosedgePulse = 0;
        debouncedNegedgePulse = 0;
    end
    always @(negedge clk) begin


        if (|debouncerReg) 
            debouncerReg <= debouncerReg + 1;


        if (buttonState != debouncedState && ~|debouncerReg)
        begin
            debouncerReg <= debouncerReg + 1;
            debouncedState <= buttonState;
            if (debouncedState)
                debouncedPosedgePulse <= 1;
            else
                debouncedNegedgePulse <= 1;
        end else begin
            debouncedPosedgePulse <= 0;
            debouncedNegedgePulse <= 0;
        end

    end

endmodule