Win_calc.v 19 KB

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