|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
网上搜索关于这个问题的解决方案并没有很多,能应用到我这里的。而且我已经在同一文件夹下放入了bsd_16bit的.v文件,就是一个加法器
Checker 'bsd_16bit' not found. Instantiation 'bsd_x1' must be of a visible checker.
module Cordic_atan
(
clk_50M,rst_n,
x,
y,
ena ,
finished,
atan
);
input clk_50M;
input rst_n;
input [31:0] x;
input [31:0] y;
input ena ;
output finished;
output [31:0] atan;
`define angle_0 32'd2949120 //45°*2^16
`define angle_1 32'd1740992 //26.5651°*2^16
`define angle_2 32'd919872 //14.0362°*2^16
`define angle_3 32'd466944 //7.1250°*2^16
`define angle_4 32'd234368 //3.5763°*2^16
`define angle_5 32'd117312 //1.7899°*2^16
`define angle_6 32'd58688 //0.8952°*2^16
`define angle_7 32'd29312 //0.4476°*2^16
`define angle_8 32'd14656 //0.2238°*2^16
`define angle_9 32'd7360 //0.1119°*2^16
`define angle_10 32'd3648 //0.0560°*2^16
`define angle_11 32'd1856 //0.0280°*2^16
`define angle_12 32'd896 //0.0140°*2^16
`define angle_13 32'd448 //0.0070°*2^16
`define angle_14 32'd257 //0.0035°*2^16
`define angle_15 32'd128 //0.0018°*2^16
parameter Pipeline = 16;
parameter K = 32'h09b74; //K=0.607253*2^16,32'h09b74,
reg signed [31:0] atan;
reg signed [31:0] x0=0,y0=0,z0=0;
reg signed [31:0] x1=0,y1=0,z1=0;
reg signed [31:0] x2=0,y2=0,z2=0;
reg signed [31:0] x3=0,y3=0,z3=0;
reg signed [31:0] x4=0,y4=0,z4=0;
reg signed [31:0] x5=0,y5=0,z5=0;
reg signed [31:0] x6=0,y6=0,z6=0;
reg signed [31:0] x7=0,y7=0,z7=0;
reg signed [31:0] x8=0,y8=0,z8=0;
reg signed [31:0] x9=0,y9=0,z9=0;
reg signed [31:0] x10=0,y10=0,z10=0;
reg signed [31:0] x11=0,y11=0,z11=0;
reg signed [31:0] x12=0,y12=0,z12=0;
reg signed [31:0] x13=0,y13=0,z13=0;
reg signed [31:0] x14=0,y14=0,z14=0;
reg signed [31:0] x15=0,y15=0,z15=0;
reg signed [31:0] x16=0,y16=0,z16=0;
reg signed [31:0] x_in=0,y_in=0,z_in=0;
reg [5:0] count;
reg signed [31:0] x_n0=0,x_p0=0,y_n0=0,y_p0=0,z_n0=0,z_p0=0;
reg signed [31:0] x_n1=0,x_p1=0,y_n1=0,y_p1=0,z_n1=0,z_p1=0;
wire signed [31:0] sum_x1_n=0,sum_x1_p=0,sum_y1_n=0,sum_y1_p=0,sum_z1_n=0,sum_z1_p=0;
wire signed [31:0] sum_x2_n=0,sum_x2_p=0,sum_y2_n=0,sum_y2_p=0,sum_z2_n=0,sum_z2_p=0;
always@ (posedge clk_50M or negedge rst_n) begin
if(!rst_n)
count <= 6'b000000;
else if( ena )
begin
if( count!=6'b010010 )
count <= count+6'b000001;
else if( count == 6'b010010 )
count <= 0;
end
else
count <= 6'b000000;
end
assign finished = (count == 6'b010010)?1'b1:1'b0;
1
2 always @ (posedge clk_50M or negedge rst_n)
3 begin
4 if(!rst_n)
5 begin
6 x0 <= 1'b0;
7 y0 <= 1'b0;
8 z0 <= 1'b0;
9 end
10 else
11 begin
12 x0 <= x_in<<<16;
13 y0 <= y_in<<<16;
14 z0 <= 32'd0;
15 //接下来给x0 y0 z0编码 首先要转化为冗余2进制才能进行编码
16 x_n0<=32'b0;x_p0<=x0;
17 y_n0<=32'b0;y_p0<=y0;
18 z_n0<=32'b0;z_p0<=z0;
19 end
20 end
21
22
23 always @ (posedge clk_50M or negedge rst_n)
24 begin
25 if(!rst_n)
26 begin
27 x1 <= 1'b0;
28 y1 <= 1'b0;
29 z1 <= 1'b0;
30 end
31 else if(y0[31]==1'b1)//Di is -1;
32 /*
33 begin
34 x1 <= x0 + ((~y0)+1'b1);
35 y1 <= y0 + x0;
36 z1 <= z0 + ((~`angle_0)+1'b1);
37 end
38 */
39 bsd_16bit bsd_x1(
40 .rst_n(rst_n),
41 .x_n(x_n0),
42 .x_p(x_p0),
43 .y_n(y_n0),
44 .y_p(y_p0),
45 .sum_n(sum_x1_n),
46 .sum_p(sum_x1_p),
47 .sum()
48 );
49 assign x_n1=sum_x1_n;
50 assign x_p1=sum_x1_p;
51 bsd_16bit bsd_y1(
52 .rst_n(rst_n),
53 .x_n(y_n0),
54 .x_p(y_p0),
55 .y_n(x_n0),
56 .y_p(x_p0),
57 .sum_n(sum_y1_n),
58 .sum_p(sum_y1_p),
59 .sum()
60 );
61 assign y_n1=sum_y1_n;
62 assign y_p1=sum_y1_p;
63 bsd_16bit bsd_z1(
64 .rst_n(rst_n),
65 .x_n(z_n0),
66 .x_p(z_p0),
67 .y_n(0),
68 .y_p(32'b01011010000000000000000),
69 .sum_n(sum_z1_n),
70 .sum_p(sum_z1_p),
71 .sum()
72 );
73 assign z_n1=sum_z1_n;
74 assign z_p1=sum_z1_p;
75
76 else
77 begin //Di is 1;
78 x1 <= x0 + y0;
79 y1 <= y0 + ((~x0)+1'b1);
80 z1 <= z0 + `angle_0;
81 end
82 end
83
84 always @ (posedge clk_50M or negedge rst_n)
85 begin
86 if(!rst_n)
87 begin
88 x2 <= 1'b0;
89 y2 <= 1'b0;
90 z2 <= 1'b0;
91 end
92 else if( y1[31]==1'b1)
93 begin
94 x2 <= x1 - (y1 >>> 1);
95 y2 <= y1 + (x1 >>> 1);
96 z2 <= z1 - `angle_1;
97 end
98 else
99 begin
100 x2 <= x1 + (y1 >>> 1);
101 y2 <= y1 - (x1 >>> 1);
102 z2 <= z1 + `angle_1;
103 end
104 end
105
106 always @ (posedge clk_50M or negedge rst_n)
107 begin
108 if(!rst_n)
109 begin
110 x3 <= 1'b0;
111 y3 <= 1'b0;
112 z3 <= 1'b0;
113 end
114 else if( y2[31]==1'b1)
115 begin
116 x3 <= x2 - (y2 >>> 2);
117 y3 <= y2 + (x2 >>> 2);
118 z3 <= z2 - `angle_2;
119 end
120 else
121 begin
122 x3 <= x2 + (y2 >>> 2);
123 y3 <= y2 - (x2 >>> 2);
124 z3 <= z2 + `angle_2;
125 end
126 end
127
128 always @ (posedge clk_50M or negedge rst_n)
129 begin
130 if(!rst_n)
131 begin
132 x4 <= 1'b0;
133 y4 <= 1'b0;
134 z4 <= 1'b0;
135 end
136 else if( y3[31]==1'b1)
137 begin
138 x4 <= x3 - (y3 >>> 3);
139 y4 <= y3 + (x3 >>> 3);
140 z4 <= z3 - `angle_3;
141 end
142 else
143 begin
144 x4 <= x3 + (y3 >>> 3);
145 y4 <= y3 -(x3 >>> 3);
146 z4 <= z3 + `angle_3;
147 end
148 end
149
150 always @ (posedge clk_50M or negedge rst_n)
151 begin
152 if(!rst_n)
153 begin
154 x5 <= 1'b0;
155 y5 <= 1'b0;
156 z5 <= 1'b0;
157 end
158 else if( y4[31]==1'b1)
159 begin
160 x5 <= x4 - (y4 >>> 4);
161 y5 <= y4 + (x4 >>> 4);
162 z5 <= z4 -`angle_4;
163 end
164 else
165 begin
166 x5 <= x4 + (y4 >>> 4);
167 y5 <= y4 - (x4 >>> 4);
168 z5 <= z4 + `angle_4;
169 end
170 end
171
172 always @ (posedge clk_50M or negedge rst_n)
173 begin
174 if(!rst_n)
175 begin
176 x6 <= 1'b0;
177 y6 <= 1'b0;
178 z6 <= 1'b0;
179 end
180 else if( y5[31]==1'b1)
181 begin
182 x6 <= x5 - (y5 >>> 5);
183 y6 <= y5 + (x5 >>> 5);
184 z6 <= z5 - `angle_5;
185 end
186 else
187 begin
188 x6 <= x5 + (y5 >>> 5);
189 y6 <= y5 - (x5 >>> 5);
190 z6 <= z5 + `angle_5;
191 end
192 end
193
194 always @ (posedge clk_50M or negedge rst_n)
195 begin
196 if(!rst_n)
197 begin
198 x7 <= 1'b0;
199 y7 <= 1'b0;
200 z7 <= 1'b0;
201 end
202 else if(y6[31]==1'b1)
203 begin
204 x7 <= x6 - (y6 >>> 6);
205 y7 <= y6 + (x6 >>> 6);
206 z7 <= z6 - `angle_6;
207 end
208 else
209 begin
210 x7 <= x6 + (y6 >>> 6);
211 y7 <= y6 - (x6 >>> 6);
212 z7 <= z6 + `angle_6;
213 end
214 end
215
216 always @ (posedge clk_50M or negedge rst_n)
217 begin
218 if(!rst_n)
219 begin
220 x8 <= 1'b0;
221 y8 <= 1'b0;
222 z8 <= 1'b0;
223 end
224 else if(y7[31]==1'b1)
225 begin
226 x8 <= x7 - (y7 >>> 7);
227 y8 <= y7 + (x7 >>> 7);
228 z8 <= z7 - `angle_7;
229 end
230 else
231 begin
232 x8 <= x7 + (y7 >>> 7);
233 y8 <= y7 - (x7 >>> 7);
234 z8 <= z7 + `angle_7;
235 end
236 end
237
238 always @ (posedge clk_50M or negedge rst_n)
239 begin
240 if(!rst_n)
241 begin
242 x9 <= 1'b0;
243 y9 <= 1'b0;
244 z9 <= 1'b0;
245 end
246 else if(y8[31]==1'b1)
247 begin
248 x9 <= x8 - (y8 >>> 8);
249 y9 <= y8 + (x8 >>> 8);
250 z9 <= z8 - `angle_8;
251 end
252 else
253 begin
254 x9 <= x8 + (y8 >>> 8);
255 y9 <= y8 - (x8 >>> 8);
256 z9 <= z8 + `angle_8;
257 end
258 end
259
260 always @ (posedge clk_50M or negedge rst_n)
261 begin
262 if(!rst_n)
263 begin
264 x10 <= 1'b0;
265 y10 <= 1'b0;
266 z10 <= 1'b0;
267 end
268 else if( y9[31]==1'b1)
269 begin
270 x10 <= x9 - (y9 >>> 9);
271 y10 <= y9 + (x9 >>> 9);
272 z10 <= z9 - `angle_9;
273 end
274 else
275 begin
276 x10 <= x9 + (y9 >>> 9);
277 y10 <= y9 - (x9 >>> 9);
278 z10 <= z9 + `angle_9;
279 end
280 end
281
283 endmodule
|
-
|