Menu
Coddy logo textTech

Testbench

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

challenge icon

チャレンジ

testbench は設計に入力を提供し、波形ファイルを作成します。独自のポートはありません。

タスク

次の条件を満たす testbench を作成してください:

  1. clkstartdata_in(8ビット)用の reg を宣言する
  2. tx 用の wire と、cnt 用の 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時間単位実行する

testbench を実行した後、波形を開いて 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

基礎のすべてのレッスン

自分で練習してみよう: Verilogオンラインコンパイラ