PCI
用modelsim进行仿真时,编写testbench,inout信号应该如何处理。
回帖(1)
2019-3-20 18:04:54
看下这个
- module inout_1_tb;
- // Inputs
- reg clk;
- reg rst_n;
- reg read;
- reg data;
- // Outputs
- wire b;
- // Bidirs
- wire a;
- // Instantiate the Unit Under Test (UUT)
- inout_1 uut (
- .clk(clk),
- .rst_n(rst_n),
- .read(read),
- .data(data),
- .a(a),
- .b(b)
- );
- reg in_a;
- assign a = read == 1 ? in_a : 1'bz;
- always #1 clk = ~clk;
- initial begin
- // Initialize Inputs
- clk = 0;
- rst_n = 0;
- read = 0;
- data = 0;
- in_a = 0;
- #10 rst_n = 1;
- repeat(10) begin //a作为输出 此时a的值等于data
- #2 data = {$random}%2;
- end
- read = 1;
- repeat(10) begin //a作为输入,此时a的值为in_a
- #2 in_a = {$random}%2;
- end
- // Add stimulus here
- end
- endmodule
看下这个
- module inout_1_tb;
- // Inputs
- reg clk;
- reg rst_n;
- reg read;
- reg data;
- // Outputs
- wire b;
- // Bidirs
- wire a;
- // Instantiate the Unit Under Test (UUT)
- inout_1 uut (
- .clk(clk),
- .rst_n(rst_n),
- .read(read),
- .data(data),
- .a(a),
- .b(b)
- );
- reg in_a;
- assign a = read == 1 ? in_a : 1'bz;
- always #1 clk = ~clk;
- initial begin
- // Initialize Inputs
- clk = 0;
- rst_n = 0;
- read = 0;
- data = 0;
- in_a = 0;
- #10 rst_n = 1;
- repeat(10) begin //a作为输出 此时a的值等于data
- #2 data = {$random}%2;
- end
- read = 1;
- repeat(10) begin //a作为输入,此时a的值为in_a
- #2 in_a = {$random}%2;
- end
- // Add stimulus here
- end
- endmodule
举报
更多回帖