MeasCtrlModule.v 7.3 KB

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