`timescale 1ns/1ps

module tb_ultrasonic_fpga;

    reg clk = 0;
    reg rst = 1;
    reg start = 0;
    reg echo = 0;
    wire trig_out;
    wire [8:0] distance;

    time t_start, t_end;

    // Clock 27MHz => periode = 37ns
    always #18 clk = ~clk;

    ultrasonic_fpga uut (
        .clk(clk),
        .rst(rst),
        .start(start),
        .echo(echo),
        .trig_out(trig_out),
        .distance(distance)
    );

    initial begin
        $dumpfile("ultrasonic.vcd");
        $dumpvars(0, tb_ultrasonic_fpga);

        // Reset
        #100;
        rst = 0;

        // Start
        #100;
        start = 1;
        #40;
        start = 0;

 

        #500;

        // Affiche la distance
        if (distance > 0) begin
            $display("Distance measured: %d cm", distance);
        end else begin
            $display("No distance measured.");
        end

        $finish;
    end

endmodule
