MeasCtrlModule.v 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer:
  5. //
  6. // Create Date: 14:22:41 09/18/2019
  7. // Design Name:
  8. // Module Name: MeasCtrlModule
  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 MeasCtrlModule
  22. #(
  23. parameter WindPNumWidth = 48,
  24. localparam TukeyWinAlpha = 4
  25. )
  26. (
  27. input Clk_i,
  28. input Rst_i,
  29. output OscWind_o,
  30. input StartMeas_i,
  31. input StartMeasDsp_i,
  32. input [7:0] FilterCmd_i,
  33. input Mode_i,
  34. input OscDataRdFlag_i,
  35. input [32-1:0] MeasNum_i,
  36. input [WindPNumWidth-1:0] WindPointsNum_i,
  37. input [32-1:0] WindPhInc_i,
  38. input [32-1:0] WindPhIncStart_i,
  39. output [32-1:0] WindArg_o,
  40. output StartFpConv_o,
  41. output MeasWind_o,
  42. output MeasWindDel_o,
  43. output StopMeas_o,
  44. output MeasEnd_o,
  45. output WinCtrl_o,
  46. output [1:0] TukeyCtrl_o
  47. );
  48. //================================================================================
  49. // REG/WIRE
  50. reg startFpConv;
  51. reg [1:0] startFpConvPipe [3:0];
  52. integer i;
  53. reg measWind;
  54. reg measWindR;
  55. reg startMeasReg;
  56. reg startMeasDspReg;
  57. wire startMeasCmd = (StartMeas_i & !startMeasReg); //esli prihodit bol'she chem 1 sigtal zapuska na 1 izmerenie, to ostal'nie ignoriruutsya
  58. wire stopMeasCmd = (!StartMeasDsp_i & startMeasDspReg);
  59. wire startMeasDspPos = (StartMeasDsp_i & !startMeasDspReg);
  60. reg [31:0] measCnt;
  61. reg [WindPNumWidth-1:0] pNumCnt;
  62. reg measWindEnd;
  63. reg pMeasEnd;
  64. wire pNumCntRes = !measWind;
  65. wire measCntRes = pMeasEnd|!StartMeasDsp_i;
  66. wire stopCalc = (stopMeasCmd|measWindEnd);
  67. reg [32-1:0] windArg;
  68. wire oscMode = (Mode_i == 1'b1);
  69. reg oscWind;
  70. wire [31:0] tukeyCosPNum = WindPointsNum_i/TukeyWinAlpha;
  71. wire [31:0] tukeyCosPNumDiv2 = tukeyCosPNum/2;
  72. wire [31:0] tukeyFirstCosValues = tukeyCosPNum/2;
  73. wire [31:0] tukeyFirstCosValuesDiv2 = tukeyFirstCosValues/2;
  74. wire [31:0] tukeySecondCosValuesDiv2 = (WindPointsNum_i-tukeyFirstCosValuesDiv2);
  75. wire [31:0] tukeySecondCosValues = (WindPointsNum_i-tukeyCosPNum/2);
  76. reg [1:0] tukeyCtrl;
  77. reg [1:0] tukeyCtrlR;
  78. reg [1:0] tukeyCtrlRR;
  79. wire incPhase = (pNumCnt <= tukeyFirstCosValues);
  80. wire decrPhase = (pNumCnt >= tukeySecondCosValues-1 & pNumCnt <= WindPointsNum_i-1);
  81. wire wideFilterFlag = (FilterCmd_i>=8'h54 & FilterCmd_i!=8'h70);
  82. //================================================================================
  83. // ASSIGNMENTS
  84. assign StartFpConv_o = startFpConvPipe [2];
  85. assign MeasWind_o = measWind;
  86. assign MeasWindDel_o = measWindR;
  87. assign StopMeas_o = pMeasEnd;
  88. assign MeasEnd_o = stopMeasCmd;
  89. assign WindArg_o = windArg;
  90. assign OscWind_o = oscWind;
  91. assign TukeyCtrl_o = tukeyCtrl;
  92. assign WinCtrl_o = (pNumCnt<=tukeyFirstCosValuesDiv2+1|pNumCnt>tukeySecondCosValuesDiv2);
  93. //================================================================================
  94. // CODING
  95. always @(*) begin
  96. if (!Rst_i) begin
  97. if (measWind) begin
  98. if (pNumCnt != 0) begin
  99. if (pNumCnt <= tukeyFirstCosValues-1 | pNumCnt > tukeySecondCosValues) begin
  100. tukeyCtrl = 2'd2;
  101. end else begin
  102. tukeyCtrl = 2'd1;
  103. end
  104. end else begin
  105. tukeyCtrl = 2'd0;
  106. end
  107. end else begin
  108. tukeyCtrl = 2'd0;
  109. end
  110. end else begin
  111. tukeyCtrl = 2'd0;
  112. end
  113. end
  114. always @(posedge Clk_i) begin
  115. if (!Rst_i) begin
  116. measWindR <= measWind;
  117. end else begin
  118. measWindR <= 1'b0;
  119. end
  120. end
  121. always @(posedge Clk_i) begin
  122. if (!Rst_i) begin
  123. tukeyCtrlR <= tukeyCtrl;
  124. tukeyCtrlRR <= tukeyCtrlR;
  125. end else begin
  126. tukeyCtrlR <= 1'b0;
  127. tukeyCtrlRR <= 1'b0;
  128. end
  129. end
  130. always @(posedge Clk_i) begin
  131. if (!Rst_i) begin
  132. if (measWindR) begin
  133. if (pNumCnt == WindPointsNum_i-1) begin
  134. measWindEnd <= 1'b1;
  135. end else begin
  136. measWindEnd <= 1'b0;
  137. end
  138. end else begin
  139. measWindEnd <= 1'b0;
  140. end
  141. end else begin
  142. measWindEnd <= 1'b0;
  143. end
  144. end
  145. always @(posedge Clk_i) begin
  146. if (!Rst_i) begin
  147. if (!oscMode) begin
  148. if (measCnt == MeasNum_i-1) begin
  149. if (measWindEnd) begin
  150. pMeasEnd <= 1'b1;
  151. end else begin
  152. pMeasEnd <= 1'b0;
  153. end
  154. end else begin
  155. pMeasEnd <= 1'b0;
  156. end
  157. end else begin
  158. if (measCnt == MeasNum_i-1) begin
  159. if (OscDataRdFlag_i) begin
  160. pMeasEnd <= 1'b1;
  161. end else begin
  162. pMeasEnd <= 1'b0;
  163. end
  164. end else begin
  165. pMeasEnd <= 1'b0;
  166. end
  167. end
  168. end else begin
  169. pMeasEnd <= 1'b0;
  170. end
  171. end
  172. always @(posedge Clk_i) begin
  173. if (!Rst_i) begin
  174. if (wideFilterFlag) begin
  175. if (measWind) begin
  176. windArg <= windArg+WindPhInc_i;
  177. end else begin
  178. windArg <= WindPhInc_i>>1;
  179. end
  180. end else begin
  181. if (measWind) begin
  182. if (incPhase) begin
  183. windArg <= windArg+WindPhInc_i;
  184. end
  185. if (decrPhase) begin
  186. windArg <= windArg-WindPhInc_i;
  187. end
  188. end else begin
  189. windArg <= WindPhIncStart_i;
  190. end
  191. end
  192. end else begin
  193. windArg <= 0;
  194. end
  195. end
  196. always @(posedge Clk_i) begin
  197. if (!Rst_i) begin
  198. if (!measCntRes) begin
  199. if (!oscMode) begin
  200. if (measCnt != MeasNum_i-1) begin
  201. if (measWindEnd) begin
  202. measCnt <= measCnt+1;
  203. end
  204. end
  205. end else begin
  206. if (measCnt != MeasNum_i-1) begin
  207. if (OscDataRdFlag_i) begin
  208. measCnt <= measCnt+1;
  209. end
  210. end
  211. end
  212. end else begin
  213. measCnt <= 0;
  214. end
  215. end else begin
  216. measCnt <= 0;
  217. end
  218. end
  219. always @(posedge Clk_i) begin
  220. if (!Rst_i) begin
  221. if (oscMode) begin
  222. if (startMeasDspPos) begin
  223. oscWind <= 1'b1;
  224. end
  225. if (pMeasEnd) begin
  226. oscWind <= 1'b0;
  227. end
  228. end else begin
  229. oscWind <= 1'b0;
  230. end
  231. end else begin
  232. oscWind <= 1'b0;
  233. end
  234. end
  235. always @(posedge Clk_i) begin
  236. if (!Rst_i) begin
  237. if (measWindEnd) begin
  238. startFpConv <= 1'b1;
  239. end else begin
  240. startFpConv <= 1'b0;
  241. end
  242. end else begin
  243. startFpConv <= 1'b0;
  244. end
  245. end
  246. always @(posedge Clk_i) begin
  247. startFpConvPipe[0] <= startFpConv;
  248. for(i=1; i<4; i=i+1) begin
  249. startFpConvPipe [i]<=startFpConvPipe[i-1];
  250. end
  251. end
  252. always @(posedge Clk_i) begin
  253. if (!Rst_i) begin
  254. if (pNumCntRes) begin
  255. pNumCnt <= {WindPNumWidth{1'b0}};
  256. end else begin
  257. pNumCnt <= pNumCnt + {{WindPNumWidth-1{1'b0}},1'b1};
  258. end
  259. end else begin
  260. pNumCnt <= {WindPNumWidth{1'b0}};
  261. end
  262. end
  263. always @(posedge Clk_i) begin
  264. if (!Rst_i) begin
  265. startMeasReg <= StartMeas_i;
  266. end else begin
  267. startMeasReg <= 1'b0;
  268. end
  269. end
  270. always @(posedge Clk_i) begin
  271. if (!Rst_i) begin
  272. startMeasDspReg <= StartMeasDsp_i;
  273. end else begin
  274. startMeasDspReg <= 1'b0;
  275. end
  276. end
  277. always @(*) begin
  278. if (!Rst_i) begin
  279. if (StartMeasDsp_i) begin
  280. if (!measWind) begin
  281. if (startMeasCmd) begin
  282. measWind = 1'b1;
  283. end
  284. end else if (stopCalc) begin
  285. measWind = 1'b0;
  286. end
  287. end else begin
  288. measWind = 1'b0;
  289. end
  290. end else begin
  291. measWind <= 1'b0;
  292. end
  293. end
  294. endmodule