|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
testvench文件
`timescale 1 ns/1 ns
module cordic_atan_tb();
//æ¶éå¨æï¼åä½ä¸ºnsï¼å¯å¨æ¤ä¿®æ¹æ¶éå¨æã
parameter CYCLE = 20;
//å¤ä½æ¶é´ï¼æ¤æ¶è¡¨ç¤ºå¤ä½3个æ¶éå¨æçæ¶é´ã
parameter RST_TIME = 3 ;
// Inputs
reg clk_50M;
reg rst_n;
reg ena;
reg [31:0] x;
reg [31:0] y;
//reg [31:0] x_in;
//reg [31:0] y_in;
//wire [31:0] finished;
wire [31:0] atan;
// Instantiate the Unit Under Test (UUT)
Cordic_atan uut(
.clk_50M (clk_50M ),
.rst_n (rst_n ),
.x (x ),
.y (y ),
.ena (ena ),
.finished (finished ),
.atan (atan )
);
//çææ¬å°æ¶é50M
initial begin
clk_50M = 0;
forever
#(CYCLE/2)
clk_50M=~clk_50M;
end
//产çå¤ä½ä¿¡å·
initial begin
rst_n = 1;
#2;
rst_n = 0;
#(CYCLE*RST_TIME);
rst_n = 1;
end
//è¾å
¥ä¿¡å·din0èµå¼æ¹å¼
initial begin
#50;
x = 0;
y = 1000;
ena = 1;
while(x<=1000)begin
#380;
x<=x+2'b10;
y<=y-2'b10;
end
end
endmodule
//**********************************//
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 [31:0] ena ;
output [31:0] 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;
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;
always@ (posedge clk_50M or negedge rst_n) begin
if(!rst_n)
begin
x_in<= 1'b0;
y_in<= 1'b0;
z_in<= 1'b0;
end
else begin
if(ena)
begin //?0???????????
case ({x[31],y[31]}) //????
2'b00:
begin //1??
x_in <= x;
y_in <= y;
end
2'b10:
begin //2??
x_in<= -x;
y_in<= y;
end
2'b11:
begin //3??
x_in<= -x;
y_in <= -y;
end
2'b01:
begin //4??
x_in <= x;
y_in <= -y;
end
endcase
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x0 <= 1'b0;
y0 <= 1'b0;
z0 <= 1'b0;
end
else
begin
x0 <= x_in<<16;
y0 <= y_in<<16;
z0 <= 32'd0;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x1 <= 1'b0;
y1 <= 1'b0;
z1 <= 1'b0;
end
else if(y0[31]==1'b1)//Di is -1ï¼
begin
x1 <= x0 - y0;
y1 <= y0 + x0;
z1 <= z0 - `angle_0;
end
else
begin //Di is 1ï¼
x1 <= x0 + y0;
y1 <= y0 - x0;
z1 <= z0 + `angle_0;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x2 <= 1'b0;
y2 <= 1'b0;
z2 <= 1'b0;
end
else if( y1[31]==1'b1)
begin
x2 <= x1 - (y1 >>> 1);
y2 <= y1 + (x1 >>> 1);
z2 <= z1 - `angle_1;
end
else
begin
x2 <= x1 + (y1 >>> 1);
y2 <= y1 - (x1 >>> 1);
z2 <= z1 + `angle_1;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x3 <= 1'b0;
y3 <= 1'b0;
z3 <= 1'b0;
end
else if( y2[31]==1'b1)
begin
x3 <= x2 - (y2 >>> 2);
y3 <= y2 + (x2 >>> 2);
z3 <= z2 - `angle_2;
end
else
begin
x3 <= x2 + (y2 >>> 2);
y3 <= y2 - (x2 >>> 2);
z3 <= z2 + `angle_2;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x4 <= 1'b0;
y4 <= 1'b0;
z4 <= 1'b0;
end
else if( y3[31]==1'b1)
begin
x4 <= x3 - (y3 >>> 3);
y4 <= y3 + (x3 >>> 3);
z4 <= z3 - `angle_3;
end
else
begin
x4 <= x3 + (y3 >>> 3);
y4 <= y3 -(x3 >>> 3);
z4 <= z3 + `angle_3;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x5 <= 1'b0;
y5 <= 1'b0;
z5 <= 1'b0;
end
else if( y4[31]==1'b1)
begin
x5 <= x4 - (y4 >>> 4);
y5 <= y4 + (x4 >>> 4);
z5 <= z4 -`angle_4;
end
else
begin
x5 <= x4 + (y4 >>> 4);
y5 <= y4 - (x4 >>> 4);
z5 <= z4 + `angle_4;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x6 <= 1'b0;
y6 <= 1'b0;
z6 <= 1'b0;
end
else if( y5[31]==1'b1)
begin
x6 <= x5 - (y5 >>> 5);
y6 <= y5 + (x5 >>> 5);
z6 <= z5 - `angle_5;
end
else
begin
x6 <= x5 + (y5 >>> 5);
y6 <= y5 - (x5 >>> 5);
z6 <= z5 + `angle_5;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x7 <= 1'b0;
y7 <= 1'b0;
z7 <= 1'b0;
end
else if(y6[31]==1'b1)
begin
x7 <= x6 - (y6 >>> 6);
y7 <= y6 + (x6 >>> 6);
z7 <= z6 - `angle_6;
end
else
begin
x7 <= x6 + (y6 >>> 6);
y7 <= y6 - (x6 >>> 6);
z7 <= z6 + `angle_6;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x8 <= 1'b0;
y8 <= 1'b0;
z8 <= 1'b0;
end
else if(y7[31]==1'b1)
begin
x8 <= x7 - (y7 >>> 7);
y8 <= y7 + (x7 >>> 7);
z8 <= z7 - `angle_7;
end
else
begin
x8 <= x7 + (y7 >>> 7);
y8 <= y7 - (x7 >>> 7);
z8 <= z7 + `angle_7;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x9 <= 1'b0;
y9 <= 1'b0;
z9 <= 1'b0;
end
else if(y8[31]==1'b1)
begin
x9 <= x8 - (y8 >>> 8);
y9 <= y8 + (x8 >>> 8);
z9 <= z8 - `angle_8;
end
else
begin
x9 <= x8 + (y8 >>> 8);
y9 <= y8 - (x8 >>> 8);
z9 <= z8 + `angle_8;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x10 <= 1'b0;
y10 <= 1'b0;
z10 <= 1'b0;
end
else if( y9[31]==1'b1)
begin
x10 <= x9 - (y9 >>> 9);
y10 <= y9 + (x9 >>> 9);
z10 <= z9 - `angle_9;
end
else
begin
x10 <= x9 + (y9 >>> 9);
y10 <= y9 - (x9 >>> 9);
z10 <= z9 + `angle_9;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x11 <= 1'b0;
y11 <= 1'b0;
z11 <= 1'b0;
end
else if( y10[31]==1'b1)
begin
x11 <= x10 - (y10 >>> 10);
y11 <= y10 + (x10 >>> 10);
z11 <= z10 - `angle_10;
end
else
begin
x11 <= x10 + (y10 >>> 10);
y11 <= y10 - (x10 >>> 10);
z11 <= z10 + `angle_10;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x12 <= 1'b0;
y12 <= 1'b0;
z12 <= 1'b0;
end
else if(y11[31]==1'b1)
begin
x12 <= x11 - (y11 >>> 11);
y12 <= y11 + (x11 >>> 11);
z12 <= z11 - `angle_11;
end
else
begin
x12 <= x11 + (y11 >>> 11);
y12 <= y11 - (x11 >>> 11);
z12 <= z11 + `angle_11;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x13 <= 1'b0;
y13 <= 1'b0;
z13 <= 1'b0;
end
else if( y12[31]==1'b1)
begin
x13 <= x12 - (y12 >>> 12);
y13 <= y12 + (x12 >>> 12);
z13 <= z12 - `angle_12;
end
else
begin
x13 <= x12 + (y12 >>> 12);
y13 <= y12 - (x12 >>> 12);
z13 <= z12 + `angle_12;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x14 <= 1'b0;
y14 <= 1'b0;
z14 <= 1'b0;
end
else if( y13[31]==1'b1)
begin
x14 <= x13 - (y13 >>> 13);
y14 <= y13 + (x13 >>> 13);
z14 <= z13 - `angle_13;
end
else
begin
x14 <= x13 + (y13 >>> 13);
y14 <= y13 - (x13 >>> 13);
z14 <= z13 + `angle_13;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x15 <= 1'b0;
y15 <= 1'b0;
z15 <= 1'b0;
end
else if(y14[31]==1'b1)
begin
x15 <= x14 - (y14 >>> 14);
y15 <= y14 + (x14 >>> 14);
z15 <= z14 - `angle_14;
end
else
begin
x15 <= x14 + (y14 >>> 14);
y15 <= y14 - (x14 >>> 14);
z15 <= z14 + `angle_14;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
x16 <= 1'b0;
y16 <= 1'b0;
z16 <= 1'b0;
end
else if( y15[31]==1'b1)
begin
x16 <= x15 - (y15 >>> 15);
y16 <= y15 + (x15 >>> 15);
z16 <= z15 - `angle_15;
end
else
begin
x16 <= x15 + (y15 >>> 15);
y16 <= y15 - (x15 >>> 15);
z16 <= z15 + `angle_15;
end
end
always @ (posedge clk_50M or negedge rst_n)
begin
if(!rst_n)
begin
atan <= 1'b0;
end
else if(finished)
begin //?0???????????
case ({x[31],y[31]}) //????
2'b00:
begin //1??
atan=z16<<16
end
2'b10:
begin //2??
atan=(z16<<16)+90
end
2'b11:
begin //3??
atan=(z16<<16)+180
end
2'b01:
begin //4??
atan=(z16<<16)+270
end
endcase
end
endmodule
|
-
出现错误描述
|