请教:用 CORDIC算法如何计算arctan?
是不是我太笨了啊……
哪位能指点一二
谢拉
hehe,这个需要慢慢看 参考一下经典论文
同时可以用Mathmatics仿真来验证自己的理解
我写的verilog函数,z=atan(y/x),8位精度。
module r2p(clk,reset_n,x,y,start,z);
parameter WIDTH_DATA = 20;
parameter [7 : 0] PI_2 = 63;
input clk ,reset_n,start;
input signed [WIDTH_DATA-1 : 0] x,y;
output reg [8 : 0] z;
reg [8 : 0] rom_atan;
reg [2 : 0] addr_rom;
reg signed [WIDTH_DATA+3 : 0] x0,y0;
reg [8 : 0] z0;
reg state;
always @*
begin
case(addr_rom)
0: rom_atan <= 31;
1: rom_atan <= 18;
2: rom_atan <= 9;
3: rom_atan <= 5;
4: rom_atan <= 2;
5: rom_atan <= 1;
6: rom_atan <= 0;
7: rom_atan <= 0;
endcase
end
always @(posedge clk or negedge reset_n)
begin
if (!reset_n) begin
addr_rom <= 0;
x0 <= 0;
y0 <= 0;
z0 <= 0;
z <=0;
end else begin
if (state==0) begin
if (start) begin
state <= 1;
if (y<0) begin
x0 <= -y;
y0 <= x;
z0 <= -PI_2;
end else begin
x0 <= y;
y0 <= -x;
z0 <= +PI_2;
end
end
end else begin
if (addr_rom == 7) begin
state <= 0;
z <= z0;
addr_rom <= 0;
end else begin
addr_rom <= addr_rom + 1;
end
if ( y0 < 0 ) begin
x0 <= x0 - (y0 >>> addr_rom);
y0 <= y0 + (x0 >>> addr_rom);
z0 <= z0 - rom_atan;
end else begin
x0 <= x0 + (y0 >>> addr_rom);
y0 <= y0 - (x0 >>> addr_rom);
z0 <= z0 + rom_atan;
end
end
end
end