Testbench
Fait partie de la section Fondamentaux du Journey Verilog de Coddy. Leçon 90 sur 90.
Défi
Un testbench fournit des entrées à votre conception et crée un fichier de forme d’onde. Il n’a pas de ports propres.
Votre tâche
Créez un testbench qui :
- Déclare
regpourclk,startetdata_in(8 bits) - Déclare
wirepourtxetwire [3:0]pourcnt - Instancie le module
uart_txen connectant tous les ports :.clk,.start,.data_in,.tx,.cnt - Génère une horloge (basculement toutes les 5 unités de temps)
- À l’intérieur d’un bloc
initial:- Crée un fichier de forme d’onde nommé
uart.vcdà l’aide de$dumpfileet$dumpvars - Définit
clk = 0,start = 1,data_in = 8'b01000001au temps 0 - Désactive
startaprès 10 unités de temps (start = 0) - S’exécute pendant 200 unités de temps
- Crée un fichier de forme d’onde nommé
Après avoir exécuté le testbench, ouvrez la forme d’onde pour vérifier le signal tx.
Essayez vous-même
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
endmoduleToutes les leçons de Fondamentaux
1Introduction
Qu’est-ce que VerilogMatériel vs logicielVotre premier moduleCommentairesNiveaux d’abstraction de conception4Operators 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 LogicEntraînez-vous par vous-même : Compilateur Verilog en ligne