NcoRstGenV2.v 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer: Churbanov S.
  5. //
  6. // Create Date: 15:22:20 12/08/2019
  7. // Design Name:
  8. // Module Name: Win_parameters
  9. // Project Name: Compact_main
  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 NcoRstGenV2
  22. (
  23. input Clk_i,
  24. input Rst_i,
  25. input [31:0] NcoPhInc_i,
  26. input StartMeasEvent_i,
  27. output NcoRst_o,
  28. output StartMeasEvent_o
  29. );
  30. //================================================================================
  31. // REG/WIRE
  32. //================================================================================
  33. reg [13:0] startMeasEventReg;
  34. reg [31:0] ncoPhIncReg;
  35. reg [31:0] ncoPhIncRegR;
  36. wire ncoPhIncUpdateFlag = (ncoPhIncRegR!=ncoPhIncReg);
  37. wire delFlag = (startMeasEventReg[13]);
  38. reg [1:0] currState;
  39. reg rst;
  40. reg startMeasEventR;
  41. reg measEvent;
  42. //================================================================================
  43. // PARAMETERS
  44. //================================================================================
  45. parameter [1:0] IDLE = 2'd0;
  46. parameter [1:0] RST = 2'd1;
  47. parameter [1:0] DEL = 2'd2;
  48. //================================================================================
  49. // ASSIGNMENTS
  50. // ================================================================================
  51. assign NcoRst_o = rst;
  52. assign StartMeasEvent_o = startMeasEventReg[13];
  53. assign startMeasDspPos = (!startMeasEventR&StartMeasEvent_i);
  54. //================================================================================
  55. // CODING
  56. //================================================================================
  57. always @(posedge Clk_i) begin
  58. if (!Rst_i) begin
  59. ncoPhIncReg <= NcoPhInc_i;
  60. ncoPhIncRegR <= ncoPhIncReg;
  61. startMeasEventR <= StartMeasEvent_i;
  62. end else begin
  63. ncoPhIncReg <= 0;
  64. ncoPhIncReg <= 0;
  65. startMeasEventR <= 0;
  66. end
  67. end
  68. always @(posedge Clk_i) begin
  69. if (!Rst_i) begin
  70. startMeasEventReg <= {startMeasEventReg[12:0],StartMeasEvent_i};
  71. end else begin
  72. startMeasEventReg <= 0;
  73. end
  74. end
  75. always @(posedge Clk_i) begin
  76. if (!Rst_i) begin
  77. case(currState)
  78. IDLE : begin
  79. if (startMeasDspPos) begin
  80. currState <= RST;
  81. rst <= 1'b1;
  82. end else begin
  83. currState <= IDLE;
  84. rst <= 1'b0;
  85. end
  86. end
  87. RST : begin
  88. if (rst & StartMeasEvent_i) begin
  89. currState <= DEL;
  90. rst <= 1'b0;
  91. end else begin
  92. currState <= RST;
  93. rst <= 1'b1;
  94. end
  95. end
  96. DEL : begin
  97. if (delFlag) begin
  98. currState <= IDLE;
  99. rst <= 1'b0;
  100. end else begin
  101. currState <= DEL;
  102. rst <= 1'b0;
  103. end
  104. end
  105. endcase
  106. end else begin
  107. currState <= 2'd0;
  108. end
  109. end
  110. endmodule