mc97_rfi_tb.v 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * mc97_rfi_tb.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. */
  7. `default_nettype none
  8. module mc97_rfi_tb;
  9. localparam integer GEN_FREQ = 15; /* Hz */
  10. // Signals
  11. // -------
  12. // Tick
  13. reg [15:0] tick_cnt;
  14. wire tick;
  15. // Tone Generation
  16. real phase;
  17. real phase_inc = 6.28 * GEN_FREQ / 8000;
  18. real tmp;
  19. // DUT connections
  20. reg [15:0] pcm_data = 0;
  21. wire pcm_stb;
  22. wire rfi;
  23. // Clock reset
  24. reg clk = 1'b0;
  25. reg rst = 1'b1;
  26. // Setup recording
  27. // ---------------
  28. initial begin
  29. $dumpfile("mc97_rfi_tb.vcd");
  30. $dumpvars(0,mc97_rfi_tb);
  31. # 600000000 $finish;
  32. end
  33. always #500 clk <= !clk; // 1 MHz
  34. initial begin
  35. #2000 rst = 0;
  36. end
  37. // Generate tone
  38. // -------------
  39. // Tick at 8000 Hz
  40. always @(posedge clk)
  41. if (rst)
  42. tick_cnt <= 0;
  43. else
  44. tick_cnt <= tick ? 16'd123 : (tick_cnt - 1);
  45. assign tick = tick_cnt[15];
  46. // Tone
  47. always @(posedge clk)
  48. if (rst)
  49. phase <= 0.0;
  50. else if (tick)
  51. phase <= phase + phase_inc;
  52. always @(*)
  53. begin
  54. tmp = $cos(phase) * (1 << 24) / GEN_FREQ;
  55. if (tmp > 32767)
  56. pcm_data = 32767;
  57. else if (tmp < -32768)
  58. pcm_data = -32768;
  59. else
  60. pcm_data = tmp;
  61. end
  62. assign pcm_stb = tick;
  63. // DUT
  64. // ---
  65. mc97_rfi #(
  66. .CLK_FREQ(1_000_000),
  67. .F_MIN(10),
  68. .F_MAX(100)
  69. ) rfi_I (
  70. .pcm_data (pcm_data),
  71. .pcm_stb (pcm_stb),
  72. .rfi (rfi),
  73. .clk (clk),
  74. .rst (rst)
  75. );
  76. endmodule // mc97_rfi_tb