... | @@ -31,6 +31,75 @@ end |
... | @@ -31,6 +31,75 @@ end |
|
|
|
|
|
ここでは Verilog の基本的な module の書き方や testbench の作成方法を簡潔に解説します。
|
|
ここでは Verilog の基本的な module の書き方や testbench の作成方法を簡潔に解説します。
|
|
|
|
|
|
|
|
### 1. 基本のmoduleの書き方
|
|
|
|
|
|
|
|
Verilog HDLでは`module`を使って回路ブロックを作成します。
|
|
|
|
|
|
|
|
#### 例:ANDゲート
|
|
|
|
```verilog
|
|
|
|
module and_gate (
|
|
|
|
input wire inA,
|
|
|
|
input wire inB,
|
|
|
|
output wire out
|
|
|
|
);
|
|
|
|
assign out = inA & inB;
|
|
|
|
endmodule
|
|
|
|
```
|
|
|
|
|
|
|
|
ここで使用されている`assign`は、入力`inA`と`inB`のビット単位のAND演算をリアルタイムで出力`out`に反映する文です。`assign`文は、組み合わせ回路の記述において広く用いられます。
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### 2. テストベンチの基本
|
|
|
|
|
|
|
|
テストベンチは、記述した回路が正しく動作するかを検証するためのVerilog HDLコードです。
|
|
|
|
|
|
|
|
### 例:ANDゲート用 Testbench
|
|
|
|
```verilog
|
|
|
|
module testbench;
|
|
|
|
// パラメータ
|
|
|
|
parameter CYCLE = 1000;
|
|
|
|
parameter HALF_CYCLE = 500;
|
|
|
|
parameter DLY = 500;
|
|
|
|
|
|
|
|
// シグナル
|
|
|
|
reg clk;
|
|
|
|
reg inA, inB;
|
|
|
|
wire out_and_gate;
|
|
|
|
|
|
|
|
// テスト対象モジュール
|
|
|
|
and_gate and_gate_0 (
|
|
|
|
.inA(inA),
|
|
|
|
.inB(inB),
|
|
|
|
.out(out_and_gate)
|
|
|
|
);
|
|
|
|
|
|
|
|
// クロック生成
|
|
|
|
always begin
|
|
|
|
clk = 1'b1;
|
|
|
|
#(HALF_CYCLE) clk = 1'b0;
|
|
|
|
#(HALF_CYCLE);
|
|
|
|
end
|
|
|
|
|
|
|
|
// テストシナリオ
|
|
|
|
initial begin
|
|
|
|
inA = 1'b0; inB = 1'b0;
|
|
|
|
|
|
|
|
inA = 1'b0; inB = 1'b0;
|
|
|
|
#100 $display("inA=%b inB=%b out=%b", inA, inB, out_and_gate);
|
|
|
|
inA = 1'b1; inB = 1'b0;
|
|
|
|
#100 $display("inA=%b inB=%b out=%b", inA, inB, out_and_gate);
|
|
|
|
inA = 1'b0; inB = 1'b1;
|
|
|
|
#100 $display("inA=%b inB=%b out=%b", inA, inB, out_and_gate);
|
|
|
|
inA = 1'b1; inB = 1'b1;
|
|
|
|
#100 $display("inA=%b inB=%b out=%b", inA, inB, out_and_gate);
|
|
|
|
|
|
|
|
repeat(10) @(posedge clk); // 10回繰り返し
|
|
|
|
$finish;
|
|
|
|
end
|
|
|
|
endmodule
|
|
|
|
```
|
|
|
|
|
|
## 代入
|
|
## 代入
|
|
|
|
|
|
```
|
|
```
|
... | | ... | |