首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于Verilog的流水线设计问题

基于Verilog的流水线设计问题
EN

Stack Overflow用户
提问于 2013-11-26 08:51:22
回答 1查看 969关注 0票数 1

我刚开始学习Verilog,因为我买了一个FPGA。由于我还没有我的FPGA,我开始了一个有点大的项目,只是看看我得到了什么。我可能已经咬掉了比我能咀嚼的更多,但我试图做一个简单的流水线CORDIC模块。我在这里模拟的问题是,值将从testbench的输入传播到uut,uut是被测试的单元,是cordic旋转器的一个实例,这些信号传播到管道的第一阶段,xpipe[0]ypipe[0]zpipe[0],然后传播到cordic_stage实例,但是这个cordic_stage实例的输出似乎没有改变xpipe[1]ypipe[1]zpipe[1]寄存器中的任何值,它们停留在zzzz。现在我肯定我的模块有100万零1件事情出了问题,但是我想自己解决它们。我想知道的是,为什么这些值没有将cordic_stage生成到管道数组中的下一个元素,以及如何修复它。下面是我的代码:

代码语言:javascript
复制
module cordic_stage #(
    parameter ANGLE_WIDTH = 16,
    parameter VALUE_WIDTH = 8,
    parameter STAGE_I = 0
    )(
    input clk,
    input [VALUE_WIDTH-1:0] xin,
    input [VALUE_WIDTH-1:0] yin,
    input [ANGLE_WIDTH-1:0] zin,
    output reg [VALUE_WIDTH-1:0] xout,
    output reg [VALUE_WIDTH-1:0] yout,
    output reg [ANGLE_WIDTH-1:0] zout
    );
    parameter DELTA = 1 << (ANGLE_WIDTH - 2);
    always @(posedge clk) begin
        if (zin[ANGLE_WIDTH-1]) begin
            xout <= xin + (yin >> STAGE_I); // These assignments to outputs are WORKING
            yout <= yout - (xin >> STAGE_I);
            zout <= zin + (DELTA >> STAGE_I);
        end else begin
            xout <= xin - (yin >> STAGE_I);
            yout <= yout + (xin >> STAGE_I);
            zout <= zin - (DELTA >> STAGE_I);
        end
    end
endmodule

module cordic_rotator #(
    parameter ANGLE_WIDTH = 16,
    parameter VALUE_WIDTH = 8
    )(
    input clk,
    input [ANGLE_WIDTH-1:0] angle,
    input [VALUE_WIDTH-1:0] xin,
    input [VALUE_WIDTH-1:0] yin,
    output [VALUE_WIDTH-1:0] xout,
    output [VALUE_WIDTH-1:0] yout
    );
    reg [VALUE_WIDTH-1:0] xpipe [ANGLE_WIDTH:0]; // The second element in these pipelines arrays at index 1 never gets changed, so that it NOT WORKING
    reg [VALUE_WIDTH-1:0] ypipe [ANGLE_WIDTH:0];
    reg [ANGLE_WIDTH-2:0] zpipe [ANGLE_WIDTH:0];
    always @(*) begin
        xpipe[0] <= angle[ANGLE_WIDTH-1] ? -xin : xin; // These assignments to the first element in the pipeline are WORKING
        ypipe[0] <= angle[ANGLE_WIDTH-1] ? -yin : yin;
        zpipe[0] <= angle[ANGLE_WIDTH-2:0];
    end
    genvar i;
    generate
        for (i = 0; i < ANGLE_WIDTH; i = i + 1) begin: stages
            cordic_stage #(ANGLE_WIDTH-1, VALUE_WIDTH, i) stage(clk, xpipe[i], ypipe[i], zpipe[i], xpipe[i+1], ypipe[i+1], zpipe[i+1]); // Values are being passed from the first stage in the pipeline at index zero to the first cordic_stage module, so that is WORKING
        end
    endgenerate 
endmodule

module cordic_rotator_testbench;

    // Inputs
    reg clk;
    reg [3:0] angle;
    reg [3:0] xin;
    reg [3:0] yin;

    // Outputs
    wire [3:0] xout;
    wire [3:0] yout;

    // Instantiate the Unit Under Test (UUT)
    cordic_rotator #(4,4) uut (
        .clk(clk), 
        .angle(angle), 
        .xin(xin), 
        .yin(yin), 
        .xout(xout), 
        .yout(yout)
    );

    initial begin
        // Initialize Inputs
        clk = 0;
        angle = 0;
        xin = 0;
        yin = 0;

        // Wait 100 ns for global reset to finish
        #100;

        // Add stimulus here

        assign angle = 2; // These lines are also WORKING
        assign xin = 8;
        assign yin = 0;

    end

    always #5 clk = !clk; 

endmodule
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-26 17:56:03

您正在直接从模块的输出线驱动寄存器xpipe,我认为这将是语法错误,因为寄存器类型应该只在过程块中驱动。

您可能会尝试将xyz管道类型从reg更改为连线,因为连接类型应该由模块输出驱动。

OP的补充: cordic_rotator中的代码被更改为电线类型,这解决了问题。

代码语言:javascript
复制
wire [VALUE_WIDTH-1:0] xpipe [ANGLE_WIDTH:0];
wire [VALUE_WIDTH-1:0] ypipe [ANGLE_WIDTH:0];
wire [ANGLE_WIDTH-2:0] zpipe [ANGLE_WIDTH:0];
assign xpipe[0] = angle[ANGLE_WIDTH-1] ? -xin : xin;
assign ypipe[0] = angle[ANGLE_WIDTH-1] ? -yin : yin;
assign zpipe[0] = angle[ANGLE_WIDTH-2:0];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20212245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档