Win_calc.v 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. `timescale 1ns / 1ps
  2. (* keep_hierarchy = "yes" *)
  3. //////////////////////////////////////////////////////////////////////////////////
  4. // Company:
  5. // Engineer: Churbanov S.
  6. //
  7. // Create Date: 15:22:20 12/08/2019
  8. // Design Name:
  9. // Module Name: Win_parameters
  10. // Project Name: Compact_main
  11. // Target Devices:
  12. // Tool versions:
  13. // Description:
  14. //
  15. // Dependencies:
  16. //
  17. // Revision:
  18. // Revision 0.01 - File Created
  19. // Additional Comments:
  20. //
  21. //////////////////////////////////////////////////////////////////////////////////
  22. module Win_calc (
  23. input clk_i,
  24. input wind_clk,
  25. input [7:0] filterCmd_i,
  26. input reset_i,
  27. input WinCtrl_i,
  28. input MeasWind_i,
  29. input [1:0] TukeyCtrl_i,
  30. input [31:0] win_value_i,
  31. input [2:0] win_type_i,
  32. output signed [17:0] win_o,
  33. output reg signed [17:0] sinWin_o
  34. );
  35. //================================================================================
  36. // REG/WIRE
  37. //================================================================================
  38. reg [2:0] calc_cycle;
  39. reg signed [17:0] a1;
  40. reg signed [17:0] b;
  41. reg signed [17:0] c1;
  42. reg signed [17:0] c2;
  43. wire [47:0] p2;
  44. wire [47:0] p1;
  45. reg signed [17:0] sinWind;
  46. reg signed [17:0] tukeyWind;
  47. reg [1:0] tukeyCtrlR;
  48. reg [1:0] tukeyCtrlRR;
  49. reg [35:0] sinWindPow2;
  50. wire sinFilterFlag = (filterCmd_i>=8'h54 & filterCmd_i<=8'h62);
  51. // wire rectFilterFlag = (filterCmd_i>=8'h63 & filterCmd_i!=8'h70)|filterCmd_i==8'h30;
  52. wire rectFilterFlag = (filterCmd_i>=8'h63 & filterCmd_i!=8'h70);
  53. wire [17:0] bSin = win_value_i[31] ? 18'h3FFFF - win_value_i[31:14] : win_value_i [31:14];
  54. wire [17:0] bTukey = win_value_i[31] ? 18'h3FFFF - win_value_i[31:14] : win_value_i [31:14];
  55. wire [17:0] bCurr = sinFilterFlag ? bSin:bTukey;
  56. wire signed [17:0] constOne = 18'b011111111111111111;
  57. reg signed [18:0] tukeyCorr;
  58. reg [17:0] tukeyWindOut;
  59. wire signed [17:0] windMux1;
  60. wire signed [17:0] windMux2;
  61. //================================================================================
  62. // PARAMETERS
  63. //================================================================================
  64. localparam signed A3_1 = 18'h15584;
  65. // ????????? ??? ?????????? SIN
  66. localparam signed [17:0] A1 = 18'h12400; // a-1
  67. localparam signed [17:0] A2 = 18'h002C0; // b
  68. localparam signed [17:0] A3 = ~A3_1 + 1'b1; // c
  69. localparam signed [17:0] A4 = 18'h0126C; // d
  70. localparam signed [17:0] A5 = 18'h01C5C; // e
  71. //================================================================================
  72. // ASSIGNMENTS
  73. // ================================================================================
  74. // assign win_o = (sinFilterFlag) ? sinWindPow2[34-:18]:tukeyWindOut;
  75. assign win_o = windMux2;
  76. assign windMux1 = (sinFilterFlag) ? sinWindPow2[34-:18]:tukeyWindOut;
  77. assign windMux2 = (rectFilterFlag)? 18'h1ffff:windMux1;
  78. // ================================================================================
  79. // CODING
  80. //================================================================================
  81. always @(posedge clk_i) begin
  82. if (!reset_i) begin
  83. tukeyCtrlR <= TukeyCtrl_i;
  84. tukeyCtrlRR <= tukeyCtrlR;
  85. end else begin
  86. tukeyCtrlR <= 0;
  87. tukeyCtrlRR <= 0;
  88. end
  89. end
  90. always @(posedge clk_i) begin
  91. if (!reset_i) begin
  92. tukeyCorr <= (tukeyWind+constOne);
  93. sinWindPow2 <= sinWind**2;
  94. end else begin
  95. tukeyCorr <= 18'h0;
  96. sinWindPow2 <= 18'h0;
  97. end
  98. end
  99. always @(*) begin
  100. if (!reset_i) begin
  101. case(tukeyCtrlRR)
  102. 2'h0: begin
  103. tukeyWindOut = 0;
  104. end
  105. 2'h1: begin
  106. tukeyWindOut = 18'h1ffff;
  107. end
  108. 2'h2: begin
  109. tukeyWindOut = tukeyCorr[18-:18];
  110. end
  111. default: begin
  112. tukeyWindOut = 0;
  113. end
  114. endcase
  115. end else begin
  116. tukeyWindOut = 18'h0;
  117. end
  118. end
  119. always @(posedge wind_clk) begin
  120. if (!reset_i) begin
  121. case (calc_cycle)
  122. 3'd0:
  123. begin
  124. a1 <= A5;
  125. c1 <= A4;
  126. c2 <= A3;
  127. // b <= win_value_i[31] ? 18'h3FFFF - win_value_i[31:14] : win_value_i [31:14];
  128. b <= bCurr;
  129. end
  130. 3'd1:
  131. begin
  132. a1 <= p2[34:17];
  133. c1 <= A2;
  134. c2 <= A1;
  135. end
  136. 3'd2:
  137. begin
  138. a1 <= p2[34:17];
  139. c1 <= b;
  140. end
  141. endcase
  142. end else begin
  143. a1 <= 18'b0;
  144. c1 <= 18'b0;
  145. c2 <= 18'b0;
  146. b <= 18'b0;
  147. end
  148. end
  149. always @(posedge wind_clk) begin
  150. if (!reset_i) begin
  151. if (!win_type_i) begin
  152. if (calc_cycle == 3'd0) begin
  153. if (p1[47:34] == 0) begin
  154. sinWind <= p1[34-:18];//1.0.17
  155. end else begin
  156. sinWind <= 18'h1FFFF;
  157. end
  158. end
  159. end else begin
  160. sinWind <= 18'h0;
  161. end
  162. end else begin
  163. sinWind <= 18'h0;
  164. end
  165. end
  166. always @(posedge wind_clk) begin
  167. if (!reset_i) begin
  168. if (!win_type_i) begin
  169. if (calc_cycle == 3'd0) begin
  170. if (!WinCtrl_i) begin
  171. tukeyWind <= p1[34-:18];
  172. end else begin
  173. tukeyWind <= 0-p1[34-:18];
  174. end
  175. end
  176. end else begin
  177. tukeyWind <= 18'h0;
  178. end
  179. end else begin
  180. tukeyWind <= 18'h0;
  181. end
  182. end
  183. //??????? "????? ??????? ????????". ???????? [(b*A5+A4) = p1 ? ????????????? ?????? (b*p1+A3)=p2] == 1 ????.
  184. always @(posedge wind_clk) begin
  185. if (!reset_i) begin
  186. if (calc_cycle != 3'd2) begin
  187. calc_cycle <= calc_cycle + 3'd1;
  188. end else begin
  189. calc_cycle <= 3'd0;
  190. end
  191. end else begin
  192. calc_cycle <= 3'd0;
  193. end
  194. end
  195. DSP48E1 #(
  196. // Feature Control Attributes: Data Path Selection
  197. .A_INPUT("DIRECT"), // Selects A input source, "DIRECT" (A port) or "CASCADE" (ACIN port)
  198. .B_INPUT("DIRECT"), // Selects B input source, "DIRECT" (B port) or "CASCADE" (BCIN port)
  199. .USE_DPORT("FALSE"), // Select D port usage (TRUE or FALSE)
  200. .USE_MULT("MULTIPLY"), // Select multiplier usage ("MULTIPLY", "DYNAMIC", or "NONE")
  201. .USE_SIMD("ONE48"), // SIMD selection ("ONE48", "TWO24", "FOUR12")
  202. // Pattern Detector Attributes: Pattern Detection Configuration
  203. .AUTORESET_PATDET("NO_RESET"), // "NO_RESET", "RESET_MATCH", "RESET_NOT_MATCH"
  204. .MASK(48'h3fffffffffff), // 48-bit mask value for pattern detect (1=ignore)
  205. .PATTERN(48'h000000000000), // 48-bit pattern match for pattern detect
  206. .SEL_MASK("MASK"), // "C", "MASK", "ROUNDING_MODE1", "ROUNDING_MODE2"
  207. .SEL_PATTERN("PATTERN"), // Select pattern value ("PATTERN" or "C")
  208. .USE_PATTERN_DETECT("NO_PATDET"), // Enable pattern detect ("PATDET" or "NO_PATDET")
  209. // Register Control Attributes: Pipeline Register Configuration
  210. .ACASCREG(0), // Number of pipeline stages between A/ACIN and ACOUT (0, 1 or 2)
  211. .ADREG(0), // Number of pipeline stages for pre-adder (0 or 1)
  212. .ALUMODEREG(0), // Number of pipeline stages for ALUMODE (0 or 1)
  213. .AREG(0), // Number of pipeline stages for A (0, 1 or 2)
  214. .BCASCREG(0), // Number of pipeline stages between B/BCIN and BCOUT (0, 1 or 2)
  215. .BREG(0), // Number of pipeline stages for B (0, 1 or 2)
  216. .CARRYINREG(0), // Number of pipeline stages for CARRYIN (0 or 1)
  217. .CARRYINSELREG(0), // Number of pipeline stages for CARRYINSEL (0 or 1)
  218. .CREG(0), // Number of pipeline stages for C (0 or 1)
  219. .DREG(0), // Number of pipeline stages for D (0 or 1)
  220. .INMODEREG(0), // Number of pipeline stages for INMODE (0 or 1)
  221. .MREG(0), // Number of multiplier pipeline stages (0 or 1)
  222. .OPMODEREG(0), // Number of pipeline stages for OPMODE (0 or 1)
  223. .PREG(0) // Number of pipeline stages for P (0 or 1)
  224. )
  225. DSP48E1_1inst (
  226. // Cascade: 30-bit (each) output: Cascade Ports
  227. .ACOUT(), // 30-bit output: A port cascade output
  228. .BCOUT(), // 18-bit output: B port cascade output
  229. .CARRYCASCOUT(), // 1-bit output: Cascade carry output
  230. .MULTSIGNOUT(), // 1-bit output: Multiplier sign cascade output
  231. .PCOUT(), // 48-bit output: Cascade output
  232. // Control: 1-bit (each) output: Control Inputs/Status Bits
  233. .OVERFLOW(), // 1-bit output: Overflow in add/acc output
  234. .PATTERNBDETECT(), // 1-bit output: Pattern bar detect output
  235. .PATTERNDETECT(), // 1-bit output: Pattern detect output
  236. .UNDERFLOW(), // 1-bit output: Underflow in add/acc output
  237. // Data: 4-bit (each) output: Data Ports
  238. .CARRYOUT(), // 4-bit output: Carry output
  239. .P(p1), // 48-bit output: Primary data output
  240. // Cascade: 30-bit (each) input: Cascade Ports
  241. .ACIN(), // 30-bit input: A cascade data input
  242. .BCIN(), // 18-bit input: B cascade input
  243. .CARRYCASCIN(), // 1-bit input: Cascade carry input
  244. .MULTSIGNIN(), // 1-bit input: Multiplier sign input
  245. .PCIN(48'b0), // 48-bit input: P cascade input
  246. // Control: 4-bit (each) input: Control Inputs/Status Bits
  247. .ALUMODE(4'b0000), // 4-bit input: ALU control input
  248. .CARRYINSEL(3'b000), // 3-bit input: Carry select input
  249. .CLK(1'b0), // 1-bit input: Clock input
  250. // .CLK(wind_clk), // 1-bit input: Clock input
  251. .INMODE(5'b00000), // 5-bit input: INMODE control input
  252. .OPMODE(7'b0110101), // 7-bit input: Operation mode input
  253. // Data: 30-bit (each) input: Data Ports
  254. .A({{12{a1[17]}},a1}), // 30-bit input: A data input
  255. .B(b), // 18-bit input: B data input
  256. .C({ {13{c1[17]}}, c1[17:0],17'b0 }), // 48-bit input: C data input
  257. .CARRYIN(1'b0), // 1-bit input: Carry input signal
  258. .D(25'b0), // 25-bit input: D data input
  259. // Reset/Clock Enable: 1-bit (each) input: Reset/Clock Enable Inputs
  260. .CEA1(1'b1), // 1-bit input: Clock enable input for 1st stage AREG
  261. .CEA2(1'b1), // 1-bit input: Clock enable input for 2nd stage AREG
  262. .CEAD(1'b1), // 1-bit input: Clock enable input for ADREG
  263. .CEALUMODE(1'b1), // 1-bit input: Clock enable input for ALUMODE
  264. .CEB1(1'b1), // 1-bit input: Clock enable input for 1st stage BREG
  265. .CEB2(1'b1), // 1-bit input: Clock enable input for 2nd stage BREG
  266. .CEC(1'b1), // 1-bit input: Clock enable input for CREG
  267. .CECARRYIN(1'b1), // 1-bit input: Clock enable input for CARRYINREG
  268. .CECTRL(1'b1), // 1-bit input: Clock enable input for OPMODEREG and CARRYINSELREG
  269. .CED(1'b1), // 1-bit input: Clock enable input for DREG
  270. .CEINMODE(1'b1), // 1-bit input: Clock enable input for INMODEREG
  271. .CEM(1'b1), // 1-bit input: Clock enable input for MREG
  272. .CEP(1'b1), // 1-bit input: Clock enable input for PREG
  273. .RSTA(1'b0), // 1-bit input: Reset input for AREG
  274. .RSTALLCARRYIN(1'b0), // 1-bit input: Reset input for CARRYINREG
  275. .RSTALUMODE(1'b0), // 1-bit input: Reset input for ALUMODEREG
  276. .RSTB(1'b0), // 1-bit input: Reset input for BREG
  277. .RSTC(1'b0), // 1-bit input: Reset input for CREG
  278. .RSTCTRL(1'b0), // 1-bit input: Reset input for OPMODEREG and CARRYINSELREG
  279. .RSTD(1'b0), // 1-bit input: Reset input for DREG and ADREG
  280. .RSTINMODE(1'b0), // 1-bit input: Reset input for INMODEREG
  281. .RSTM(1'b0), // 1-bit input: Reset input for MREG
  282. .RSTP(1'b0) // 1-bit input: Reset input for PREG
  283. );
  284. DSP48E1 #(
  285. // Feature Control Attributes: Data Path Selection
  286. .A_INPUT("DIRECT"), // Selects A input source, "DIRECT" (A port) or "CASCADE" (ACIN port)
  287. .B_INPUT("DIRECT"), // Selects B input source, "DIRECT" (B port) or "CASCADE" (BCIN port)
  288. .USE_DPORT("FALSE"), // Select D port usage (TRUE or FALSE)
  289. .USE_MULT("MULTIPLY"), // Select multiplier usage ("MULTIPLY", "DYNAMIC", or "NONE")
  290. .USE_SIMD("ONE48"), // SIMD selection ("ONE48", "TWO24", "FOUR12")
  291. // Pattern Detector Attributes: Pattern Detection Configuration
  292. .AUTORESET_PATDET("NO_RESET"), // "NO_RESET", "RESET_MATCH", "RESET_NOT_MATCH"
  293. .MASK(48'h1), // 48-bit mask value for pattern detect (1=ignore)
  294. .PATTERN(48'h000000000000), // 48-bit pattern match for pattern detect
  295. .SEL_MASK("MASK"), // "C", "MASK", "ROUNDING_MODE1", "ROUNDING_MODE2"
  296. .SEL_PATTERN("PATTERN"), // Select pattern value ("PATTERN" or "C")
  297. .USE_PATTERN_DETECT("NO_PATDET"), // Enable pattern detect ("PATDET" or "NO_PATDET")
  298. // Register Control Attributes: Pipeline Register Configuration
  299. .ACASCREG(0), // Number of pipeline stages between A/ACIN and ACOUT (0, 1 or 2)
  300. .ADREG(0), // Number of pipeline stages for pre-adder (0 or 1)
  301. .ALUMODEREG(0), // Number of pipeline stages for ALUMODE (0 or 1)
  302. .AREG(0), // Number of pipeline stages for A (0, 1 or 2)
  303. .BCASCREG(0), // Number of pipeline stages between B/BCIN and BCOUT (0, 1 or 2)
  304. .BREG(0), // Number of pipeline stages for B (0, 1 or 2)
  305. .CARRYINREG(0), // Number of pipeline stages for CARRYIN (0 or 1)
  306. .CARRYINSELREG(0), // Number of pipeline stages for CARRYINSEL (0 or 1)
  307. .CREG(0), // Number of pipeline stages for C (0 or 1)
  308. .DREG(0), // Number of pipeline stages for D (0 or 1)
  309. .INMODEREG(0), // Number of pipeline stages for INMODE (0 or 1)
  310. .MREG(0), // Number of multiplier pipeline stages (0 or 1)
  311. .OPMODEREG(0), // Number of pipeline stages for OPMODE (0 or 1)
  312. .PREG(0) // Number of pipeline stages for P (0 or 1)
  313. )
  314. DSP48E1_2inst (
  315. // Cascade: 30-bit (each) output: Cascade Ports
  316. .ACOUT(), // 30-bit output: A port cascade output
  317. .BCOUT(), // 18-bit output: B port cascade output
  318. .CARRYCASCOUT(), // 1-bit output: Cascade carry output
  319. .MULTSIGNOUT(), // 1-bit output: Multiplier sign cascade output
  320. .PCOUT(), // 48-bit output: Cascade output
  321. // Control: 1-bit (each) output: Control Inputs/Status Bits
  322. .OVERFLOW(), // 1-bit output: Overflow in add/acc output
  323. .PATTERNBDETECT(), // 1-bit output: Pattern bar detect output
  324. .PATTERNDETECT(), // 1-bit output: Pattern detect output
  325. .UNDERFLOW(), // 1-bit output: Underflow in add/acc output
  326. // Data: 4-bit (each) output: Data Ports
  327. .CARRYOUT(), // 4-bit output: Carry output
  328. .P(p2), // 48-bit output: Primary data output
  329. // Cascade: 30-bit (each) input: Cascade Ports
  330. .ACIN(), // 30-bit input: A cascade data input
  331. .BCIN(), // 18-bit input: B cascade input
  332. .CARRYCASCIN(), // 1-bit input: Cascade carry input
  333. .MULTSIGNIN(), // 1-bit input: Multiplier sign input
  334. .PCIN(48'b0), // 48-bit input: P cascade input
  335. // Control: 4-bit (each) input: Control Inputs/Status Bits
  336. .ALUMODE(4'b0000), // 4-bit input: ALU control input
  337. .CARRYINSEL(3'b000), // 3-bit input: Carry select input
  338. .CLK(1'b0), // 1-bit input: Clock input
  339. // .CLK(wind_clk), // 1-bit input: Clock input
  340. .INMODE(5'b00000), // 5-bit input: INMODE control input
  341. .OPMODE(7'b0110101), // 7-bit input: Operation mode input
  342. // Data: 30-bit (each) input: Data Ports
  343. .A({{12{p1[47]}},p1[34:17]}), // 30-bit input: A data input
  344. .B(b), // 18-bit input: B data input
  345. .C({ {13{c2[17]}}, c2[17:0],17'b0 }), // 48-bit input: C data input
  346. .CARRYIN(1'b0), // 1-bit input: Carry input signal
  347. .D(25'b0), // 25-bit input: D data input
  348. // Reset/Clock Enable: 1-bit (each) input: Reset/Clock Enable Inputs
  349. .CEA1(1'b1), // 1-bit input: Clock enable input for 1st stage AREG
  350. .CEA2(1'b1), // 1-bit input: Clock enable input for 2nd stage AREG
  351. .CEAD(1'b1), // 1-bit input: Clock enable input for ADREG
  352. .CEALUMODE(1'b1), // 1-bit input: Clock enable input for ALUMODE
  353. .CEB1(1'b1), // 1-bit input: Clock enable input for 1st stage BREG
  354. .CEB2(1'b1), // 1-bit input: Clock enable input for 2nd stage BREG
  355. .CEC(1'b1), // 1-bit input: Clock enable input for CREG
  356. .CECARRYIN(1'b1), // 1-bit input: Clock enable input for CARRYINREG
  357. .CECTRL(1'b1), // 1-bit input: Clock enable input for OPMODEREG and CARRYINSELREG
  358. .CED(1'b1), // 1-bit input: Clock enable input for DREG
  359. .CEINMODE(1'b1), // 1-bit input: Clock enable input for INMODEREG
  360. .CEM(1'b1), // 1-bit input: Clock enable input for MREG
  361. .CEP(1'b1), // 1-bit input: Clock enable input for PREG
  362. .RSTA(1'b0), // 1-bit input: Reset input for AREG
  363. .RSTALLCARRYIN(1'b0), // 1-bit input: Reset input for CARRYINREG
  364. .RSTALUMODE(1'b0), // 1-bit input: Reset input for ALUMODEREG
  365. .RSTB(1'b0), // 1-bit input: Reset input for BREG
  366. .RSTC(1'b0), // 1-bit input: Reset input for CREG
  367. .RSTCTRL(1'b0), // 1-bit input: Reset input for OPMODEREG and CARRYINSELREG
  368. .RSTD(1'b0), // 1-bit input: Reset input for DREG and ADREG
  369. .RSTINMODE(1'b0), // 1-bit input: Reset input for INMODEREG
  370. .RSTM(1'b0), // 1-bit input: Reset input for MREG
  371. .RSTP(1'b0) // 1-bit input: Reset input for PREG
  372. );
  373. endmodule