2016-04-26 89 views
-1

我已经写了下面的代码来使用Cordic算法生成正弦角。以下是生成给定角度的x,y,z坐标的代码的一部分。Verilog代码生成'不关心'迭代

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

作为输出的“x”表示未知值,未初始化或具有多个冲突驱动程序。 – Morgan

+0

是的,这是真的,但我检查,没有额外的驱动程序 – klbm9999

+0

在生成中使用延迟看起来不正确。 – Morgan

回答

1

如果显示Z值,那么你会看到Z没有被提供一个初始值。这最终会使X和Y变成'x'。所以,给Z也提供一个初始值。

+0

但z初始化为'z [0] ='b00100000000000000000000000000000;'所以z [i]的其余部分应该自己计算正确吗?另外x和y被初始化,我将编辑帖子以包含该信息 – klbm9999

+0

'atan_table'如何?你能以时间戳0,10,20,25的时间间隔输出x,y和z的值吗? – Sourabh