DitherGenv2.v 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer: Churbanov S.
  5. //
  6. // Create Date: 10:00:14 13/08/2019
  7. // Design Name:
  8. // Module Name: DspPpiOut
  9. // Project Name:
  10. // Target Devices:
  11. // Tool versions:
  12. // Description:
  13. //
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21. module DitherGenv2
  22. #(
  23. parameter CmdDataRegWith = 24,
  24. parameter FrAmpWordWidth = 8,
  25. parameter RefFreqDiv = 5
  26. )
  27. (
  28. input Rst_i,
  29. input Clk_i,
  30. input [CmdDataRegWith-1:0] DitherCmd_i,
  31. output DitherCtrlT2R2_o,
  32. output DitherCtrlT1R1_o
  33. );
  34. //================================================================================
  35. // REG/WIRE
  36. //================================================================================
  37. wire [FrAmpWordWidth-1:0] ditherFreq = DitherCmd_i[CmdDataRegWith-1-:FrAmpWordWidth];
  38. wire [4-1:0] ditherAmpT2R2 = DitherCmd_i[15:12];
  39. wire [4-1:0] ditherAmpT1R1 = DitherCmd_i[11:8];
  40. wire [4-1:0] rampLimit = DitherCmd_i[7:4];
  41. wire ditherEnT2R2 = DitherCmd_i[1];
  42. wire ditherEnT1R1 = DitherCmd_i[0];
  43. wire [3:0] ncoArray [15:0];
  44. assign ncoArray [0] = 0;
  45. assign ncoArray [1] = 1;
  46. assign ncoArray [2] = 2;
  47. assign ncoArray [3] = 3;
  48. assign ncoArray [4] = 4;
  49. assign ncoArray [5] = 5;
  50. assign ncoArray [6] = 6;
  51. assign ncoArray [7] = 7;
  52. assign ncoArray [8] = 8;
  53. assign ncoArray [9] = 7;
  54. assign ncoArray [10] = 6;
  55. assign ncoArray [11] = 5;
  56. assign ncoArray [12] = 4;
  57. assign ncoArray [13] = 3;
  58. assign ncoArray [14] = 2;
  59. assign ncoArray [15] = 1;
  60. reg [3:0] sawCnt;
  61. reg [FrAmpWordWidth-1:0] currStateT2R2;
  62. reg [FrAmpWordWidth-1:0] currStateT1R1;
  63. wire [3:0] ncoSignalT2R2 = ncoArray[currStateT2R2[FrAmpWordWidth-1-:4]];
  64. wire [3:0] ncoSignalT1R1 = ncoArray[currStateT1R1[FrAmpWordWidth-1-:4]];
  65. wire dithGenT2R2 = ((ncoSignalT2R2>>ditherAmpT2R2)>sawCnt) ? 1'b1:1'b0;
  66. wire dithGenT1R1 = ((ncoSignalT1R1>>ditherAmpT1R1)>sawCnt) ? 1'b1:1'b0;
  67. //================================================================================
  68. // ASSIGNMENTS
  69. //================================================================================
  70. assign DitherCtrlT2R2_o = (ditherEnT2R2) ? dithGenT2R2:1'b0;
  71. assign DitherCtrlT1R1_o = (ditherEnT1R1) ? dithGenT1R1:1'b0;
  72. //================================================================================
  73. // CODING
  74. //================================================================================
  75. always @(posedge Clk_i) begin
  76. if (!Rst_i) begin
  77. if (sawCnt != rampLimit) begin
  78. sawCnt <= sawCnt +1;
  79. end else begin
  80. sawCnt <= 0;
  81. end
  82. end else begin
  83. sawCnt <= 0;
  84. end
  85. end
  86. wire Clk5=(sawCnt<=10/2-1)? 1'b1:1'b0;
  87. always @(posedge Clk_i) begin
  88. if (!Rst_i) begin
  89. if (sawCnt ==rampLimit) begin
  90. currStateT2R2 <= currStateT2R2+ditherFreq;
  91. currStateT1R1 <= currStateT1R1+ditherFreq;
  92. end
  93. end else begin
  94. currStateT2R2 <=0;
  95. currStateT1R1 <=0;
  96. end
  97. end
  98. endmodule