data/full_repos/permissive/505898990/verilog/rtl/distance_display.v
1: b'%Warning-WIDTH: data/full_repos/permissive/505898990/verilog/rtl/distance_display.v:192: Operator ASSIGNDLY expects 12 bits on the Assign RHS, but Assign RHS\'s REPLICATE generates 11 bits.\n                                                                                       : ... In instance distance_display.b_t_btc\n        r_bcd <= {DECIMAL_DIGITS*4-1{1\'b0}};\n              ^~\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/505898990/verilog/rtl/distance_display.v:193: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s REPLICATE generates 8 bits.\n                                                                                       : ... In instance distance_display.b_t_btc\n        r_Binary <= {INPUT_WIDTH-1{1\'b0}};\n                 ^~\n%Warning-WIDTH: data/full_repos/permissive/505898990/verilog/rtl/distance_display.v:194: Operator ASSIGNDLY expects 3 bits on the Assign RHS, but Assign RHS\'s REPLICATE generates 2 bits.\n                                                                                       : ... In instance distance_display.b_t_btc\n        r_Digit_Index <= {DECIMAL_DIGITS-1{1\'b0}};\n                      ^~\n%Warning-WIDTH: data/full_repos/permissive/505898990/verilog/rtl/distance_display.v:124: Logical Operator LOGNOT expects 1 bit on the LHS, but LHS\'s VARREF \'s_COUNT_ECHO\' generates 2 bits.\n                                                                                       : ... In instance distance_display.d_m\n            if(!s_COUNT_ECHO || r_measurment_counter_10_uS > MAX_DISTANCE_CYCLES - 1) begin\n               ^\n%Warning-WIDTH: data/full_repos/permissive/505898990/verilog/rtl/distance_display.v:134: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s DIVS generates 32 bits.\n                                                                                       : ... In instance distance_display.d_m\n            o_distance <= ((r_measurment_counter_10_uS / 10)) / 58;\n                       ^~\n%Error: Exiting due to 5 warning(s)\n'
module distance_measurement(
	  input wire        i_clk,
    input wire        i_reset,
    input wire        i_sensor_echo,
    output reg        o_sensor_trigger = 0,
    output reg [8:0]  o_distance = 0,
    output reg        o_rdy = 0
);


    localparam MAX_DISTANCE_CYCLES = 232_0;


    integer  r_measurment_counter_10_uS = 0; 
    reg      r_echo_received = 0;


    reg [1:0] r_current_state;


    localparam s_IDLE             = 2'b00;
    localparam s_TRIGGER          = 2'b01;
    localparam s_COUNT_ECHO       = 2'b10;
    localparam s_WAIT             = 2'b11;



    wire w_div_clk_100_mS;

    clock_divider #(.DIV_VAL(49_999)) c_d(
      .i_clk(i_clk),
      .o_div_clk(w_div_clk_100_mS)
    );

    always@(posedge i_clk or posedge i_reset) begin

      if(i_reset) begin
        r_current_state <= s_IDLE;
        r_measurment_counter_10_uS <= 0;
        o_rdy <= 1'b0;
        o_distance <= 0;
        o_sensor_trigger <= 1'b0;

      end else begin
        case (r_current_state)

          s_IDLE:
            begin
              o_rdy <= 1'b0;

              if(w_div_clk_100_mS == 1'b1) begin
                r_measurment_counter_10_uS <= 0;
                o_sensor_trigger <= 1'b1;
                r_current_state <= s_TRIGGER;
              end else begin
                r_current_state <= s_IDLE;
              end
            end

          s_TRIGGER:
          begin
            o_sensor_trigger <= 1'b0;
            r_current_state <= s_COUNT_ECHO;
          end

          s_COUNT_ECHO:
          begin
            if(!s_COUNT_ECHO || r_measurment_counter_10_uS > MAX_DISTANCE_CYCLES - 1) begin
              r_measurment_counter_10_uS <= r_measurment_counter_10_uS + 1;
              r_current_state <= s_COUNT_ECHO;
            end else begin
              r_current_state <= s_WAIT;
            end
          end

          s_WAIT:
          begin
            o_distance <= ((r_measurment_counter_10_uS / 10)) / 58;
            o_rdy <= 1'b1;
          end
        endcase
      end
    end

endmodule
module distance_measurement(
	  input wire        i_clk,
    input wire        i_reset,
    input wire        i_sensor_echo,
    output reg        o_sensor_trigger = 0,
    output reg [8:0]  o_distance = 0,
    output reg        o_rdy = 0
);



    localparam MAX_DISTANCE_CYCLES = 232_0;


    integer  r_measurment_counter_10_uS = 0; 
    reg      r_echo_received = 0;


    reg [1:0] r_current_state;


    localparam s_IDLE             = 2'b00;
    localparam s_TRIGGER          = 2'b01;
    localparam s_COUNT_ECHO       = 2'b10;
    localparam s_WAIT             = 2'b11;



    wire w_div_clk_100_mS;

    clock_divider #(.DIV_VAL(49_999)) c_d(
      .i_clk(i_clk),
      .o_div_clk(w_div_clk_100_mS)
    );

    always@(posedge i_clk or posedge i_reset) begin

      if(i_reset) begin
        r_current_state <= s_IDLE;
        r_measurment_counter_10_uS <= 0;
        o_rdy <= 1'b0;
        o_distance <= 0;
        o_sensor_trigger <= 1'b0;

      end else begin
        case (r_current_state)

          s_IDLE:
            begin
              o_rdy <= 1'b0;

              if(w_div_clk_100_mS == 1'b1) begin
                r_measurment_counter_10_uS <= 0;
                o_sensor_trigger <= 1'b1;
                r_current_state <= s_TRIGGER;
              end else begin
                r_current_state <= s_IDLE;
              end
            end

          s_TRIGGER:
          begin
            o_sensor_trigger <= 1'b0;
            r_current_state <= s_COUNT_ECHO;
          end

          s_COUNT_ECHO:
          begin
            if(!s_COUNT_ECHO || r_measurment_counter_10_uS > MAX_DISTANCE_CYCLES - 1) begin
              r_measurment_counter_10_uS <= r_measurment_counter_10_uS + 1;
              r_current_state <= s_COUNT_ECHO;
            end else begin
              r_current_state <= s_WAIT;
            end
          end

          s_WAIT:
          begin
            o_distance <= ((r_measurment_counter_10_uS / 10)) / 58;
            o_rdy <= 1'b1;
          end
        endcase
      end
    end

endmodule