NcoRstGen.v 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 NcoRstGen
  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 [15:0] startMeasEventReg;
  34. reg [31:0] ncoPhIncReg;
  35. reg [31:0] ncoPhIncRegR;
  36. wire ncoPhIncUpdateFlag = (ncoPhIncRegR!=ncoPhIncReg);
  37. wire delFlag = (startMeasEventReg[15]);
  38. reg [1:0] currState;
  39. reg rst;
  40. //================================================================================
  41. // PARAMETERS
  42. //================================================================================
  43. parameter [1:0] IDLE = 2'd0;
  44. parameter [1:0] RST = 2'd1;
  45. parameter [1:0] DEL = 2'd2;
  46. //================================================================================
  47. // ASSIGNMENTS
  48. // ================================================================================
  49. assign NcoRst_o = rst;
  50. assign StartMeasEvent_o = (currState == IDLE)? StartMeasEvent_i:startMeasEventReg[15];
  51. //================================================================================
  52. // CODING
  53. //================================================================================
  54. always @(posedge Clk_i) begin
  55. if (!Rst_i) begin
  56. ncoPhIncReg <= NcoPhInc_i;
  57. ncoPhIncRegR <= ncoPhIncReg;
  58. end else begin
  59. ncoPhIncReg <= 0;
  60. ncoPhIncRegR <= 0;
  61. end
  62. end
  63. always @(posedge Clk_i) begin
  64. if (!Rst_i) begin
  65. startMeasEventReg <= {startMeasEventReg[15:0],StartMeasEvent_i};
  66. end else begin
  67. startMeasEventReg <= 0;
  68. end
  69. end
  70. always @(posedge Clk_i) begin
  71. if (!Rst_i) begin
  72. case(currState)
  73. IDLE : begin
  74. if (ncoPhIncUpdateFlag) begin
  75. currState <= RST;
  76. rst <= 1'b1;
  77. end else begin
  78. currState <= IDLE;
  79. rst <= 1'b0;
  80. end
  81. end
  82. RST : begin
  83. if (rst & StartMeasEvent_i) begin
  84. currState <= DEL;
  85. rst <= 1'b0;
  86. end else begin
  87. currState <= RST;
  88. rst <= 1'b1;
  89. end
  90. end
  91. DEL : begin
  92. if (delFlag) begin
  93. currState <= IDLE;
  94. rst <= 1'b0;
  95. end else begin
  96. currState <= DEL;
  97. rst <= 1'b0;
  98. end
  99. end
  100. endcase
  101. end else begin
  102. currState <= 2'd0;
  103. end
  104. end
  105. endmodule