forked from tanchou/Verilog
- Created a new testbench file `top_ultrasonic_led_tb.vvp` to simulate the functionality of the `top_ultrasonic_led` module. - Included necessary signal definitions and event triggers for clock, reset, start, echo, and trigger signals. - Implemented a state machine to handle the ultrasonic measurement process and LED display logic. - Added simulation parameters for distance measurement and LED control. - Integrated VPI calls for waveform dumping and simulation control.
62 lines
1.0 KiB
Verilog
62 lines
1.0 KiB
Verilog
`timescale 1ns/1ps
|
|
|
|
module tb_top_ultrasonic_led;
|
|
|
|
reg clk;
|
|
reg rst;
|
|
reg start;
|
|
reg echo;
|
|
wire trig;
|
|
wire [5:0] leds;
|
|
|
|
// Instance du module top
|
|
top_ultrasonic_led uut (
|
|
.clk(clk),
|
|
.rst(rst),
|
|
.start(start),
|
|
.echo(echo),
|
|
.trig(trig),
|
|
.leds(leds)
|
|
);
|
|
|
|
always #18.5 clk = ~clk;
|
|
|
|
initial begin
|
|
// Initialisation
|
|
$dumpfile("top_ultrasonic_led.vcd");
|
|
$dumpvars(0, tb_top_ultrasonic_led);
|
|
|
|
clk = 0;
|
|
rst = 1;
|
|
start = 0;
|
|
echo = 0;
|
|
|
|
#100;
|
|
rst = 0;
|
|
|
|
#50;
|
|
start = 1;
|
|
#20;
|
|
start = 0;
|
|
|
|
// Attente du signal trig
|
|
wait (trig == 1);
|
|
$display("TRIG HIGH at %t", $time);
|
|
wait (trig == 0);
|
|
$display("TRIG LOW at %t", $time);
|
|
|
|
repeat (500) @(posedge clk);
|
|
echo = 1;
|
|
#12000
|
|
|
|
echo = 0;
|
|
|
|
repeat (500) @(posedge clk);
|
|
|
|
$display("Leds allumer : %b", leds);
|
|
|
|
$finish;
|
|
end
|
|
|
|
endmodule
|