Testbench
CoddyのVerilogジャーニー「基礎」セクションの一部。レッスン 90/90。
チャレンジ
testbench は設計に入力を提供し、波形ファイルを作成します。独自のポートはありません。
タスク
次の条件を満たす testbench を作成してください:
clk、start、data_in(8ビット)用のregを宣言するtx用のwireと、cnt用のwire [3:0]を宣言するuart_txモジュールをインスタンス化し、すべてのポートを接続する:.clk、.start、.data_in、.tx、.cnt- クロックを生成する(5時間単位ごとにトグル)
initialブロック内で:$dumpfileと$dumpvarsを使用して、uart.vcdという名前の波形ファイルを作成する- 時刻 0 で
clk = 0、start = 1、data_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基礎のすべてのレッスン
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic自分で練習してみよう: Verilogオンラインコンパイラ