DitherGen.v 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 DitherGen
  22. #(
  23. parameter CmdDataRegWith = 24,
  24. parameter FrAmpWordWidth = 8
  25. )
  26. (
  27. input Rst_i,
  28. input Clk_i,
  29. input [CmdDataRegWith-1:0] DitherCmd_i,
  30. output DitherCtrlT2R2_o,
  31. output DitherCtrlT1R1_o
  32. );
  33. //================================================================================
  34. // REG/WIRE
  35. //================================================================================
  36. wire [FrAmpWordWidth-1:0] ditherFreq = DitherCmd_i[CmdDataRegWith-1-:FrAmpWordWidth];
  37. wire [FrAmpWordWidth-1:0] ditherAmp = DitherCmd_i[CmdDataRegWith-FrAmpWordWidth-1-:FrAmpWordWidth];
  38. wire ditherT2R2 = DitherCmd_i[1];
  39. wire ditherT1R1 = DitherCmd_i[0];
  40. reg [FrAmpWordWidth-1:0] freqCnt;
  41. reg [FrAmpWordWidth-1:0] ampCnt;
  42. wire DitherReg = ((freqCnt<=ditherFreq/2)&&(ampCnt<=ditherAmp))? 1'b1:1'b0;
  43. wire ClkDiv = (freqCnt<=ditherFreq/2)? 1'b1:1'b0;
  44. //================================================================================
  45. // ASSIGNMENTS
  46. //================================================================================
  47. assign DitherCtrlT2R2_o = (ditherT2R2)? DitherReg:1'b0;
  48. assign DitherCtrlT1R1_o = (ditherT1R1)? DitherReg:1'b0;
  49. //================================================================================
  50. // CODING
  51. //================================================================================
  52. always @(posedge Clk_i) begin
  53. if (!Rst_i) begin
  54. if (freqCnt!=ditherFreq-1) begin
  55. freqCnt<=freqCnt+1;
  56. end else begin
  57. freqCnt<=0;
  58. end
  59. end else begin
  60. freqCnt<=0;
  61. end
  62. end
  63. always @(posedge Clk_i) begin
  64. if (!Rst_i) begin
  65. if (ampCnt!=ditherFreq-1) begin
  66. ampCnt<=ampCnt+1;
  67. end else begin
  68. ampCnt<=0;
  69. end
  70. end else begin
  71. ampCnt<=0;
  72. end
  73. end
  74. endmodule