data/full_repos/permissive/147690299/lab/32_fsm_ultrasonic/rtl/sr04_control.v
None: at end of input
1: b"%Error: data/full_repos/permissive/147690299/lab/32_fsm_ultrasonic/rtl/sr04_control.v:33: Cannot find file containing module: 'prm_register'\n    prm_register #(2) state_r (clk, rst_n, state_nx, state);\n    ^~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/147690299/lab/32_fsm_ultrasonic/rtl,data/full_repos/permissive/147690299/prm_register\n             data/full_repos/permissive/147690299/lab/32_fsm_ultrasonic/rtl,data/full_repos/permissive/147690299/prm_register.v\n             data/full_repos/permissive/147690299/lab/32_fsm_ultrasonic/rtl,data/full_repos/permissive/147690299/prm_register.sv\n             prm_register\n             prm_register.v\n             prm_register.sv\n             obj_dir/prm_register\n             obj_dir/prm_register.v\n             obj_dir/prm_register.sv\n%Error: data/full_repos/permissive/147690299/lab/32_fsm_ultrasonic/rtl/sr04_control.v:38: Cannot find file containing module: 'prm_register_we'\n    prm_register_we #(DELAY_WIDTH) delay_r (clk, rst_n, delay_we, delay_nx, delay);\n    ^~~~~~~~~~~~~~~\n%Error: Exiting due to 2 error(s)\n"
module sr04_control
#(
    parameter DELAY_TRIGGER = 10,
              DELAY_ECHO    = 25000,
              DELAY_POSTFIX = 500000,
              DELAY_WIDTH   = $clog2(DELAY_POSTFIX)
)(
    input      clk,
    input      rst_n,
    input      strobe_us,
    input      strobe_cm,
    input      echo,
    output reg trigger,
    output reg measure_cm,
    output reg measure_end
);
    localparam S_TRIGGER = 0,
               S_ECHO    = 1,
               S_SAVE    = 2,
               S_POSTFIX = 3;
    







    wire [            1:0] state;
    reg  [            1:0] state_nx;
    prm_register #(2) state_r (clk, rst_n, state_nx, state);

    wire [DELAY_WIDTH-1:0] delay;
    wire [DELAY_WIDTH-1:0] delay_nx = (state_nx != state) ? 0 : delay + 1;
    wire                   delay_we = strobe_us;
    prm_register_we #(DELAY_WIDTH) delay_r (clk, rst_n, delay_we, delay_nx, delay);


    always @(*) begin
        state_nx = state;
        case (state)
            S_TRIGGER : if (delay == DELAY_TRIGGER)
                            state_nx = S_ECHO;
            S_ECHO    : if (delay == DELAY_ECHO)
                            state_nx = S_SAVE;
            S_SAVE    : state_nx = S_POSTFIX;
            S_POSTFIX : if (delay == DELAY_POSTFIX)
                            state_nx = S_TRIGGER;
        endcase
    end


    always @(*) begin
        trigger     = 1'b0;
        measure_cm  = 1'b0;
        measure_end = 1'b0;
        case (state)
            S_TRIGGER : trigger     = 1'b1;
            S_ECHO    : measure_cm  = strobe_cm & echo;
            S_SAVE    : measure_end = 1'b1;
        endcase
    end

endmodule
module sr04_control
#(
    parameter DELAY_TRIGGER = 10,
              DELAY_ECHO    = 25000,
              DELAY_POSTFIX = 500000,
              DELAY_WIDTH   = $clog2(DELAY_POSTFIX)
)(
    input      clk,
    input      rst_n,
    input      strobe_us,
    input      strobe_cm,
    input      echo,
    output reg trigger,
    output reg measure_cm,
    output reg measure_end
);

    localparam S_TRIGGER = 0,
               S_ECHO    = 1,
               S_SAVE    = 2,
               S_POSTFIX = 3;
    







    wire [            1:0] state;
    reg  [            1:0] state_nx;
    prm_register #(2) state_r (clk, rst_n, state_nx, state);

    wire [DELAY_WIDTH-1:0] delay;
    wire [DELAY_WIDTH-1:0] delay_nx = (state_nx != state) ? 0 : delay + 1;
    wire                   delay_we = strobe_us;
    prm_register_we #(DELAY_WIDTH) delay_r (clk, rst_n, delay_we, delay_nx, delay);


    always @(*) begin
        state_nx = state;
        case (state)
            S_TRIGGER : if (delay == DELAY_TRIGGER)
                            state_nx = S_ECHO;
            S_ECHO    : if (delay == DELAY_ECHO)
                            state_nx = S_SAVE;
            S_SAVE    : state_nx = S_POSTFIX;
            S_POSTFIX : if (delay == DELAY_POSTFIX)
                            state_nx = S_TRIGGER;
        endcase
    end


    always @(*) begin
        trigger     = 1'b0;
        measure_cm  = 1'b0;
        measure_end = 1'b0;
        case (state)
            S_TRIGGER : trigger     = 1'b1;
            S_ECHO    : measure_cm  = strobe_cm & echo;
            S_SAVE    : measure_end = 1'b1;
        endcase
    end

endmodule