我编写了以下代码,使用Cordic算法生成正弦角。以下是为给定角度生成x,y,z坐标的代码的一部分。
genvar i;
generate
for (i=0; i < (width-1); i=i+1) begin
wire z_sign;
wire signed [width-1:0] x_shr, y_shr;
assign x_shr = x[i] >>> i; // signed shift right
assign y_shr = y[i] >>> i;
initial begin
#20 $display("x_shr = %b, y_shr = %b ",x_shr,y_shr);
end
//the sign of the current rotation angle
assign z_sign = z[i][31];
always @(posedge clock) begin
// add/subtract shifted data
x[i+1] <= z_sign ? x[i] + y_shr : x[i] - y_shr;
y[i+1] <= z_sign ? y[i] - x_shr : y[i] + x_shr;
z[i+1] <= z_sign ? z[i] + atan_table[i] : z[i] - atan_table[i];
#25 $display("x[%d] = %b",i,x[i]);
end
end
endgenerate
给出的输入是:
x_shr = 'b0000000000000100;
y_shr = 'b0000000000000000;
z_sign是z [i]:
的符号z[0] = 'b00100000000000000000000000000000;
width = 16;
x[0] <= 'b0000000000000100;
y[0] <= 'b0;
所有声明如下
parameter width = 16;
// Inputs
input clock;
input signed [width-1:0] x_start,y_start;
reg signed [width-1:0] x [0:width-1];
reg signed [width-1:0] y [0:width-1];
reg signed [31:0] z [0:width-1];
但我得到的输出是
x_shr = 0000000000000100, y_shr = 0000000000000000
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x_shr = xxxxxxxxxxxxxxxx, y_shr = xxxxxxxxxxxxxxxx
x[ 14] = xxxxxxxxxxxxxxxx
x[ 13] = xxxxxxxxxxxxxxxx
x[ 12] = xxxxxxxxxxxxxxxx
x[ 11] = xxxxxxxxxxxxxxxx
x[ 10] = xxxxxxxxxxxxxxxx
x[ 9] = xxxxxxxxxxxxxxxx
x[ 8] = xxxxxxxxxxxxxxxx
x[ 7] = xxxxxxxxxxxxxxxx
x[ 6] = xxxxxxxxxxxxxxxx
x[ 5] = xxxxxxxxxxxxxxxx
x[ 4] = xxxxxxxxxxxxxxxx
x[ 3] = xxxxxxxxxxxxxxxx
x[ 2] = xxxxxxxxxxxxxxxx
x[ 1] = xxxxxxxxxxxxxxxx
x[ 0] = 0000000000000100
为什么我在单次迭代后得到x
?
答案 0 :(得分:1)
如果显示Z的值,则会看到Z未提供初始值。这最终会将X和Y驱动到'x'。所以,也为Z提供初始值。