Menu
Coddy logo textTech

テストベンチ

CoddyのVerilogジャーニー「基礎」セクションの一部 — レッスン 90/90。

challenge icon

チャレンジ

テストベンチは、設計した回路に入力を提供し、波形ファイルを作成します。テストベンチ自体にはポートはありません。

あなたのタスク

以下の機能を持つテストベンチを作成してください:

  1. clkstart、および data_in (8ビット) 用の reg を宣言する
  2. tx 用の wirecnt 用の wire [3:0] を宣言する
  3. uart_tx モジュールをインスタンス化し、すべてのポート.clk.start.data_in.tx.cnt)を接続する
  4. クロックを生成する(5時間単位ごとに反転)
  5. initial ブロック内で以下を行う:
    • $dumpfile$dumpvars を使用して、"uart.vcd" という名前の波形ファイルを作成する
    • 時刻 0 で clk = 0start = 1data_in = 8'b01000001 に設定する
    • 10時間単位後に start を解除する(start = 0
    • 200時間単位分実行する

テストベンチを実行した後、波形を開いて tx 信号を確認してください。

自分で試してみよう

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

基礎のすべてのレッスン