Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. /*
  2. Integrated Master in Electrical and Computer Engineering - FEUP
  3.  
  4. EEC0055 - Digital Systems Design 2019/2020
  5.  
  6. ----------------------------------------------------------------------
  7. module rec2pol - Converts rectangular coords to polar coords using the CORDIC algorithm
  8.  
  9. Summary
  10. This module implements the CORDIC algorithm in vectoing mode to
  11. convert the rectangular coordinates of a vector to polar coordinates.
  12.  
  13. The inputs X and Y are 32 bit integers representing the X and Y coordinates
  14. with 16 integer bits and 16 fractional bits (16Q16 format)
  15.  
  16. The outputs are the modulus represented in the same format and the
  17. angle represented in degrees with 8 integer bits and 24 fractional bits
  18.  
  19. Input range:
  20. The input X must be positive and less than 32767;
  21. The Y input can be positive or negative in the interval [-32768, 32767];
  22. The output modulus cannot exceed the 16-bit maximum positive in two's complement (32767)
  23.  
  24. ----------------------------------------------------------------------
  25. Date created: 4 Oct 2019
  26. Author: jca@fe.up.pt
  27.  
  28. ----------------------------------------------------------------------
  29. This Verilog code is property of the University of Porto, Portugal
  30. Its utilization beyond the scope of the course Digital Systems Design
  31. (Projeto de Sistemas Digitais) of the Integrated Master in Electrical
  32. and Computer Engineering requires explicit authorization from the author.
  33.  
  34. */
  35.  
  36. module rec2pol(
  37. input clock,
  38. input reset,
  39. input enable, // set and keep high to enable iteration
  40. input start, // set to 1 for one clock to start
  41. input signed [31:0] x, // X component, 16Q16
  42. input signed [31:0] y, // Y component, 16Q16
  43. output signed [31:0] mod, // Modulus, 16Q16
  44. output signed [31:0] angle // Angle in degrees, 8Q24
  45. );
  46.  
  47.  
  48. // ADD YOUR CODE HERE
  49.  
  50. wire [33:0] out01;
  51. wire [33:0] out02;
  52. wire [33:0] out03;
  53. reg [33:0] out04;
  54. reg [33:0] out05;
  55. wire signed[33:0] out06;
  56. wire signed[33:0] out07;
  57. wire signed[33:0] out08;
  58. reg signed[33:0] out09;
  59. reg signed[33:0] out10;
  60. wire signed[31:0] out11;
  61. wire signed[31:0] out12;
  62. reg signed[31:0] out13;
  63. reg signed [31:0] out14;
  64. wire [5:0] count;
  65. reg signed [33:0] XR;
  66. reg signed [33:0] YR;
  67. reg signed [31:0] ZR;
  68. wire signed [31:0] arroz;
  69.  
  70. //parte 1
  71. ITERCOUNTER it0 (
  72.  
  73. .clock(clock),
  74. .reset(reset),
  75. .start(start),
  76. .enable(enable),
  77. .count(count)
  78. );
  79.  
  80. ATAN_ROM at0(
  81.  
  82. .addr(count),
  83. .data(arroz)
  84.  
  85. );
  86.  
  87. MODSCALE mt0(
  88.  
  89. .XF(XR),
  90. .MODUL(mod)
  91.  
  92. );
  93.  
  94. assign out01= YR>>>count ;
  95. assign out02=XR+out01;
  96. assign out03=XR-out01;
  97.  
  98. always @*
  99. begin
  100. if ( YR[33] )
  101. out04 = out03;
  102. else
  103. out04 = out02;
  104. end
  105.  
  106. always @*
  107. begin
  108. if ( start )
  109. out05 = x;
  110. else
  111. out05 = out04;
  112.  
  113. end
  114.  
  115. always@(posedge clock)
  116. begin
  117. if(reset)
  118. XR<=34'b0;
  119. else if(enable)
  120. XR<=out05;
  121.  
  122. end
  123.  
  124. //parte 2
  125.  
  126.  
  127.  
  128. assign out06= XR>>>count ;
  129. assign out07=YR+out06;
  130. assign out08=YR-out06;
  131.  
  132.  
  133. always @*
  134. begin
  135. if ( YR[33] )
  136. out09 = out07;
  137. else
  138. out09 = out08;
  139.  
  140. end
  141.  
  142. always @*
  143. begin
  144. if ( start )
  145. out10 = y;
  146. else
  147. out10 = out09;
  148.  
  149. end
  150.  
  151. always@(posedge clock)
  152. begin
  153. if(reset)
  154. YR<=34'b0;
  155. else if(enable)
  156. YR<=out10;
  157.  
  158. end
  159.  
  160. // parte 3
  161.  
  162.  
  163.  
  164. assign out11=ZR+arroz;
  165. assign out12=ZR-arroz;
  166.  
  167.  
  168. always @*
  169. begin
  170. if ( YR[33] )
  171. out13 = out12;
  172. else
  173. out13 = out11;
  174.  
  175. end
  176.  
  177. always @*
  178. begin
  179. if ( start )
  180. out14 = 32'd0;
  181. else
  182. out14 = out13;
  183.  
  184. end
  185.  
  186. always@(posedge clock)
  187. begin
  188. if(reset)
  189. ZR<=34'b0;
  190. else if(enable)
  191. ZR<=out14;
  192.  
  193. end
  194.  
  195. assign angle=ZR;
  196.  
  197. endmodule
  198. // end of module rec2pol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement