Menu
Coddy logo textTech

Testbench

Parte de la sección Fundamentos del Journey de Verilog de Coddy — lección 90 de 90.

challenge icon

Desafío

Un testbench proporciona entradas a tu diseño y crea un archivo de forma de onda. No tiene puertos propios.

Tu Tarea

Crea un testbench que:

  1. Declare reg para clk, start, y data_in (8 bits)
  2. Declare wire para tx y wire [3:0] para cnt
  3. Instancie el módulo uart_tx, conectando todos los puertos: .clk, .start, .data_in, .tx, .cnt
  4. Genere un reloj (conmuta cada 5 unidades de tiempo)
  5. Dentro de un bloque initial:
    • Cree un archivo de forma de onda llamado "uart.vcd" usando $dumpfile y $dumpvars
    • Establezca clk = 0, start = 1, data_in = 8'b01000001 en el tiempo 0
    • Libere start después de 10 unidades de tiempo (start = 0)
    • Se ejecute durante 200 unidades de tiempo

Después de ejecutar el testbench, abre la forma de onda para verificar la señal tx.

Pruébalo tú mismo

module uart_tx (
  input clk,
  input start,
  input [7:0] data_in,
  output reg tx,
  output reg [3:0] cnt
);

  reg [9:0] shift_reg;

  initial begin
    cnt = 0;
    tx = 1;
    shift_reg = 0;
  end

  always @(posedge clk) begin
    if (cnt == 0 && start) begin
      shift_reg <= {1'b1, data_in, 1'b0};
      cnt <= 1;
    end
    else if (cnt > 0 && cnt < 9) begin
      tx <= shift_reg[0];
      shift_reg <= shift_reg >> 1;
      cnt <= cnt + 1;
    end
    else if (cnt == 9) begin
      tx <= shift_reg[0];
      shift_reg <= shift_reg >> 1;
      cnt <= 0;
    end
  end

endmodule

Todas las lecciones de Fundamentos