当前位置:   article > 正文

Writing testbench

Writing testbench

1. clock

  1. module top_module ( );
  2. reg clk;
  3. initial
  4. begin
  5. clk = 1'b0;
  6. end
  7. always #5 clk = ~clk;
  8. dut t1(clk);
  9. endmodule

2. testbench 1

  1. module top_module ( output reg A, output reg B );//
  2. // generate input patterns here
  3. initial begin
  4. A = 1'b0;
  5. B = 1'b0;
  6. #10 A = ~A;
  7. #5 B = ~B;
  8. #5 A = ~A;
  9. #20 B = ~B;
  10. end
  11. endmodule

3.Andgate 

  1. module top_module();
  2. reg [1:0] in;
  3. reg out;
  4. initial
  5. begin
  6. in[0]= 1'b0;
  7. in[1] = 1'b0;
  8. #10 in[0] = ~in[0];
  9. #10 in[0] = ~in[0];
  10. in[1] = ~in[1];
  11. #10 in[0] = ~in[0];
  12. end
  13. andgate t1(.in(in),.out(out));
  14. endmodule

4.testbench 2 

  1. module top_module();
  2. reg clk;
  3. reg in;
  4. reg [2:0] s;
  5. reg out;
  6. initial
  7. begin
  8. clk = 1'b0;
  9. in = 1'b0;
  10. s = 3'd2;
  11. end
  12. always #5 clk = ~clk;
  13. initial
  14. begin
  15. #10 s = 3'd6;
  16. #10 in = ~in;
  17. s = 3'd2;
  18. #10 in = ~in;
  19. s = 3'd7;
  20. #10 in = ~in;
  21. s = 3'd0;
  22. #30 in = ~in;
  23. s = 3'd0;
  24. end
  25. q7 t1(
  26. .clk(clk),
  27. .in(in),
  28. .s(s),
  29. .out(out)
  30. );
  31. endmodule

5.Flip-flop

  1. module top_module ();
  2. reg clk;
  3. reg reset;
  4. reg t;
  5. reg q;
  6. initial
  7. begin
  8. clk = 1'b0;
  9. reset = 1'b0;
  10. t = 1'b0;
  11. end
  12. always #5 clk = ~clk;
  13. initial
  14. begin
  15. #6 reset = ~reset;
  16. #15 reset = ~reset;
  17. end
  18. always@(posedge clk)
  19. begin
  20. if(reset)
  21. t <= 1'b0;
  22. else
  23. t <= 1'b1;
  24. end
  25. tff t1(
  26. .clk(clk),
  27. .reset(reset),
  28. .t(t),
  29. .q(q)
  30. );
  31. endmodule

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/660027
推荐阅读