1
0
forked from tanchou/Verilog

ultrasonic commands commencer et tester mais non fonctionnel donc début de testbench pour pouvoir debuguer

This commit is contained in:
Gamenight77
2025-05-12 12:15:52 +02:00
parent 004def5ba2
commit 30bbe27510
16 changed files with 1273 additions and 171 deletions

View File

@@ -1,6 +1,6 @@
`timescale 1ns/1ps
module tb_uart;
module tb_ultrason_commands;
reg clk = 0;
reg tx_enable = 0;
@@ -11,19 +11,32 @@ module tb_uart;
reg rx_received;
wire rx_enable = 1'b1;
wire pin;
wire rx,tx;
always #18.5 clk = ~clk;
localparam CLK_FREQ = 27_000_000;
localparam BAUD_RATE = 115_200;
ultrasonic_sensor ultrasonic_sensor_instance (
.clk(clk),
.signal(ultrason_sig)
);
top_uart_ultrason_command top_uart_ultrason_command_instance (
.clk(clk),
.rx(rx),
.tx(tx),
.ultrason_sig(ultrason_sig),
.leds()
);
uart_rx #(
.CLK_FREQ(CLK_FREQ),
.BAUD_RATE(BAUD_RATE)
) rx_instance (
.clk(clk),
.rx_pin(pin),
.rx_pin(tx),
.rx_data(data_out),
.rx_received(rx_received),
.rx_enable(rx_enable)
@@ -37,7 +50,7 @@ module tb_uart;
.tx_enable(tx_enable),
.tx_ready(tx_ready),
.data(data_in),
.tx(pin),
.tx(rx),
.rst_p(1'b0)
);
@@ -45,37 +58,11 @@ module tb_uart;
$dumpfile("runs/uart.vcd");
$dumpvars(0, tb_uart);
$display("======== Start UART LOOPBACK test =========");
$display("======== Start UART ULTRASONIC COMMANDS =========");
#100;
data_in <= 8'd234; // 234
tx_enable <= 1;
wait(tx_ready == 1'b0);
tx_enable <= 0;
// Attendre
wait (rx_received == 1'b1); // Attendre que le signal de reception soit actif
$display("Data received: %d", data_out); // Afficher la valeur recu
$display("Data expected: %d", data_in); // Afficher la valeur envoyee
#1000;
wait(tx_ready == 1'b1); // Attendre que le signal de reception soit actif
data_in <= 8'd202; // 202
tx_enable <= 1;
wait(tx_ready == 1'b0);
tx_enable <= 0;
// Attendre
wait (rx_received == 1'b1); // Attendre que le signal de reception soit actif
$display("Data received: %d", data_out); // Afficher la valeur recu
$display("Data expected: %d", data_in); // Afficher la valeur envoyee
$display("======== END UART TX test =========");
$display("======== END UART ULTRASONIC COMMANDS =========");
#1000;
$stop;