Win_calc.v 18 KB

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