求5~85度的sin和cos值
其它角度和Verilog实现代码类似,查表、移位和加法器
`define DIE 16 //迭代次数
`define PIE 3.1415926
`define MUL 100_000_000 //同比放大
initial begin
int die;
int x[17];
int y[17];
int z[17];
int tan[16] =`{78539816,46364760,24497866,12435499,6241881,3123983,1562372,781234,390623,195312,97656,48828,24414,12207,6104,3052};
int d;
int angle; //角度值
int cosz0,sinz0;
#100;
x[0] =(0.607253*`MUL);
z[0] =(`PIE*`MUL/4);
$display("x[0] = %0d;z[0] = %0d,tan[0]",x[0],z[0],tan[0]) ;
for(angle = 5;angle <= 85;angle++)
begin
z[0] = angle*2*(`MUL*`PIE)/360; //转成弧度后作为初始角度
for(die =0;die<`DIE;die++)begin
@(posedge clk) ;
if(z[die] >= 0)begin
d = 1;
end
else begin
d = -l;
end
x[die+1]= x[die] - d*((y[die]) >> die );
y[die+1]= y[die] + d*((x[die]) >> die );
z[die+1]= z[die] - d*tan[die];
end
cosz0 = x[16];
sinz0 = y[16];
end
end
参考:https://blog.csdn.net/Pieces_thinking/article/details/83512820