divider_tb.v 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Testbench
  3. * Simulation for divider module
  4. */
  5. // Set timescale
  6. `timescale 1 ns/1 ns
  7. // Includes
  8. // Memory
  9. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/Divider.v"
  10. // Define testmodule
  11. module divider_tb;
  12. // clock/reset I/O
  13. reg clk = 1'b0;
  14. reg reset = 1'b0;
  15. reg start = 1'b0;
  16. reg write_a = 1'b0;
  17. wire busy;
  18. wire done;
  19. wire valid;
  20. wire dbz;
  21. wire ovf;
  22. reg signed [31:0] a = 0;
  23. reg signed [31:0] b = 0;
  24. wire signed [31:0] val;
  25. wire signed [15:0] val_int;
  26. assign val_int = val [31:16];
  27. Divider divider(
  28. .clk (clk),
  29. .rst (reset),
  30. .start(start), // start calculation
  31. .write_a(write_a),
  32. .busy(busy), // calculation in progress
  33. .done(done), // calculation is complete (high for one tick)
  34. .valid(valid), // result is valid
  35. .dbz(dbz), // divide by zero
  36. .ovf(ovf), // overflow
  37. .a_in(a), // dividend (numerator)
  38. .b(b), // divisor (denominator)
  39. .val(val) // result value: quotient
  40. );
  41. initial
  42. begin
  43. // dump everything for GTKwave
  44. $dumpfile("/home/bart/Documents/FPGA/FPGC6/Verilog/output/wave.vcd");
  45. $dumpvars;
  46. #10
  47. // startup
  48. repeat(2)
  49. begin
  50. clk = ~clk;
  51. #10 clk = ~clk;
  52. #10;
  53. end
  54. reset = 1;
  55. repeat(2)
  56. begin
  57. clk = ~clk;
  58. #10 clk = ~clk;
  59. #10;
  60. end
  61. reset = 0;
  62. repeat(4)
  63. begin
  64. clk = ~clk;
  65. #10 clk = ~clk;
  66. #10;
  67. end
  68. a = 17 << 16;
  69. write_a = 1;
  70. repeat(1)
  71. begin
  72. clk = ~clk;
  73. #10 clk = ~clk;
  74. #10;
  75. end
  76. write_a = 0;
  77. repeat(4)
  78. begin
  79. clk = ~clk;
  80. #10 clk = ~clk;
  81. #10;
  82. end
  83. a = 0;
  84. b = 3 << 16;
  85. start = 1;
  86. repeat(64)
  87. begin
  88. clk = ~clk;
  89. #10 clk = ~clk;
  90. #10;
  91. end
  92. #1 $finish;
  93. end
  94. endmodule