求助:Cordic算法计算反正切,再通过自定义指令整合到nios...
`timescale 1ns/1nsmodule cordic_arctan(clk, clk_en,reset,done,result,dataa,datab);
parameterW = 32, W_Z = 32;
input clk;
//input x_in;
//input y_in;
//output reg x_out;
//output reg y_out;
//output reg z_out;
input clk_en;
input reset;
output reg done;
input dataa;
input datab;
output reg result;
reg x, y;
reg z;
always @(posedge clk or posedge reset)
begin
if(reset)
z <= 32'h0;
else
begin
x <= dataa;
y <= datab;
z <= 32'h0;
// 旋转45度
if(~y) begin
x <= x + y;
y <= y - x;
z <= z + 32'h20000;
end
else begin
x <= x - y;
y <= y + x;
z <= z - 32'h20000;
end
// 旋转26.57度
if(~y)begin
x <= x + {{1{y}}, y};
y <= y - {{1{x}}, x};
z <= z + 32'h12e40;
end
else begin
x <= x - {{1{y}}, y};
y <= y + {{1{x}}, x};
z <= z - 32'h12e40;
end
// 旋转14.04度
if(~y)begin
x <= x + {{2{y}}, y};
y <= y - {{2{x}}, x};
z <= z + 32'h09fb4;
end
else begin
x <= x - {{2{y}}, y};
y <= y + {{2{x}}, x};
z <= z - 32'h09fb4;
end
// 旋转7.13度
if(~y)begin
x <= x + {{3{y}}, y};
y <= y - {{3{x}}, x};
z <= z + 32'h05111;
end
else begin
x <= x - {{3{y}}, y};
y <= y + {{3{x}}, x};
z <= z - 32'h05111;
end
// 旋转3.58度
if(~y)begin
x <= x + {{4{y}}, y};
y <= y - {{4{x}}, x};
z <= z + 32'h028b1;
end
else begin
x <= x - {{4{y}}, y};
y <= y + {{4{x}}, x};
z <= z - 32'h028b1;
end
// 旋转1.79度
if(~y)begin
x <= x + {{5{y}}, y};
y <= y - {{5{x}}, x};
z <= z + 32'h0145d;
end
else begin
x <= x - {{5{y}}, y};
y <= y + {{5{x}}, x};
z <= z - 32'h0145d;
end
// 旋转0.90度
if(~y)begin
x <= x + {{6{y}}, y};
y <= y - {{6{x}}, x};
z <= z + 32'h00a2f;
end
else begin
x <= x - {{6{y}}, y};
y <= y + {{6{x}}, x};
z <= z - 32'h00a2f;
end
// 旋转0.45度
if(~y)begin
x <= x + {{7{y}}, y};
y <= y - {{7{x}}, x};
z <= z + 32'h00518;
end
else begin
x <= x - {{7{y}}, y};
y <= y + {{7{x}}, x};
z <= z - 32'h00518;
end
//0.225
if(~y)begin
x <= x + {{8{y}}, y};
y <= y - {{8{x}}, x};
z <= z + 32'h0028c;
end
else begin
x <= x - {{8{y}}, y};
y <= y + {{8{x}}, x};
z <= z - 32'h0028c;
end
//0.1125
if(~y)begin
x <= x + {{9{y}}, y};
y <= y - {{9{x}}, x};
z <= z + 32'h00146;
done <= 1;
end
else begin
x <= x - {{9{y}}, y};
y <= y + {{9{x}}, x};
z <= z - 32'h00146;
done <= 1;
end
//x_out <= x;
//y_out <= y;
result <= z;
end
end
endmodule
我遇到的问题是:自定义指令里面的控制信号start,done和clk_en,,,不知道怎样用到我的程序里面,,,求详细解答!!!
页:
[1]