forked from tanchou/Verilog
Refactor ultrasonic_fpga module: update distance output and state handling; add top_ultrason_uart module for integration with UART and ultrasonic sensor
This commit is contained in:
@@ -4,10 +4,9 @@ module ultrasonic_fpga #(
|
||||
input wire clk,
|
||||
input wire start,
|
||||
inout wire sig, // Broche bidirectionnelle vers le capteur
|
||||
output reg [15:0] distance // Distance mesurée en cm
|
||||
output reg [15:0] distance, // Distance mesurée en cm
|
||||
output reg [2:0] state
|
||||
);
|
||||
|
||||
reg [2:0] state;
|
||||
reg [15:0] trig_counter;
|
||||
reg [31:0] echo_counter;
|
||||
reg sig_out;
|
||||
@@ -27,7 +26,7 @@ module ultrasonic_fpga #(
|
||||
|
||||
localparam integer TRIG_PULSE_CYCLES = CLK_FREQ / 100_000; // 10us pulse
|
||||
localparam integer DIST_DIVISOR = (58 * CLK_FREQ) / 1_000_000; // pour conversion us -> cm
|
||||
localparam integer MAX_CM = 370;
|
||||
localparam integer MAX_CM = 350;
|
||||
localparam integer TIMEOUT_CYCLES = (MAX_CM * 58 * CLK_FREQ) / 1_000_000;
|
||||
|
||||
localparam WAIT_NEXT_CYCLES = (CLK_FREQ / 1000) * 100; // 60 ms
|
||||
|
@@ -1,9 +1,10 @@
|
||||
module uart_tx(
|
||||
input wire clk,
|
||||
input wire start, // Signal de démarrage de la transmission
|
||||
input wire [7:0] data, // Données à transmettre
|
||||
output reg tx = 1, // Sortie de transmission
|
||||
output reg busy = 0 // Indicateur de transmission en cours
|
||||
input wire clk,
|
||||
input wire start,
|
||||
input wire [7:0] data,
|
||||
|
||||
output reg tx = 1,
|
||||
output reg busy = 0
|
||||
);
|
||||
|
||||
parameter CLK_FREQ = 27_000_000;
|
||||
|
55
Semaine 1/top_ultrason_uart.v
Normal file
55
Semaine 1/top_ultrason_uart.v
Normal file
@@ -0,0 +1,55 @@
|
||||
module top_ultrason_uart(
|
||||
input wire clk,
|
||||
input wire start,
|
||||
inout wire sig,
|
||||
output wire tx,
|
||||
);
|
||||
|
||||
parameter CLK_FREQ = 27_000_000;
|
||||
parameter BAUD_RATE = 115_200;
|
||||
localparam BIT_PERIOD = CLK_FREQ / BAUD_RATE;
|
||||
|
||||
// Paramètres pour le capteur à ultrasons
|
||||
wire [15:0] distance;
|
||||
wire [2:0] state_sensor;
|
||||
|
||||
// Signaux pour l'UART TX
|
||||
reg [15:0] tx_data;
|
||||
reg tx_start = 0;
|
||||
|
||||
// Instance du capteur à ultrasons
|
||||
ultrasonic_fpga #(
|
||||
.CLK_FREQ(CLK_FREQ)
|
||||
) sensor_inst (
|
||||
.clk(clk),
|
||||
.start(start),
|
||||
.sig(sig),
|
||||
|
||||
.distance(distance),
|
||||
.state(state_sensor)
|
||||
);
|
||||
|
||||
// Instance de l'UART TX
|
||||
uart_tx #(
|
||||
.CLK_FREQ(CLK_FREQ),
|
||||
.BAUD_RATE(BAUD_RATE)
|
||||
) tx_instance (
|
||||
.clk(clk),
|
||||
.start(tx_start),
|
||||
.data(tx_data[7:0]),
|
||||
|
||||
.tx(tx)
|
||||
);
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (state_sensor == 3'd6) begin // Lorsque la mesure est terminée, préparer les données
|
||||
|
||||
tx_data <= distance;
|
||||
tx_start <= 1;
|
||||
|
||||
end else begin
|
||||
tx_start <= 0;
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
Reference in New Issue
Block a user