【问题标题】:Verilog. Setting output as input in a ripple adderVerilog。将输出设置为纹波加法器中的输入
【发布时间】:2019-02-24 18:55:29
【问题描述】:

我不久前开始使用 Verilog,并且在我的波纹加法器中遇到了一些条件语句。我有一个 6 位波纹加法器(有效),但我想添加一个额外的功能。 我有一个 2 位变量,称为“转换器”;

if changer == 00, then display input1
if changer == 01, then display input2
else display the summation result.

这就是我所拥有的。

`timescale 1ns/10ps

module SixBitRippleAdder(
    input [5:0] x, //Input 1
    input [5:0] y, //Input 2
    input sel, //Add or subtract switch
    input [1:0] changer, //Condition switch
    output overflow,
    output [5:0] sum
    );

    reg [5:0] w;
    wire [5:0] c_out; //Used for carries

    //6 bit adder by adding instantiating 6 1 bit adders
    FullAdder bit1(.a(x[0]), .b(y[0] ^ sel), .s(sum[0]), .cin(sel), .cout(c_out[0]));
    FullAdder bit2(.a(x[1]), .b(y[1] ^ sel), .s(sum[1]), .cin(c_out[0]), .cout(c_out[1]));
    FullAdder bit3(.a(x[2]), .b(y[2] ^ sel), .s(sum[2]), .cin(c_out[1]), .cout(c_out[2]));
    FullAdder bit4(.a(x[3]), .b(y[3] ^ sel), .s(sum[3]), .cin(c_out[2]), .cout(c_out[3]));
    FullAdder bit5(.a(x[4]), .b(y[4] ^ sel), .s(sum[4]), .cin(c_out[3]), .cout(c_out[4]));
    FullAdder bit6(.a(x[5]), .b(y[5] ^ sel), .s(sum[5]), .cin(c_out[4]), .cout(c_out[5]));

    assign overflow = c_out[5] ^ c_out[4];

    //Issue is with these conditions
    always @*
        begin
            if(changer == 2'b00)
                w = x;
            else if(changer == 2'b01)
                w = y;
            else
                w = sum;
        end

    assign sum = w;

endmodule

我正在尝试对此进行综合,但我的 always 块出现错误。错误是“多个驱动程序网络”

非常感谢

【问题讨论】:

  • 您的全加器驱动器sumassign sum = w; 也是如此。您需要为从全加器到选择器的中间信号使用不同的信号名称,或者为输出使用不同的名称。

标签: verilog fpga vivado synthesis


【解决方案1】:

我猜你只需要一个不同的变量,这将是求和的结果:

wire [5:0] sumTmp;

然后

FullAdder bit1(.a(x[0]), .b(y[0] ^ sel), .s(sumTmp[0]), .cin(sel), .cout(c_out[0]));
                                            ^^^^^^^^^
    ...

及以后:

always @*
    begin
        if(changer == 2'b00)
            w = x;
        else if(changer == 2'b01)
            w = y;
        else
            w = sumTmp;
    end

assign sum = w;

【讨论】:

  • 酷。这似乎行得通。在我确定“w”应该是什么之后,有没有办法确定“总和”是什么?只是出于好奇。
  • @E.Chengsum 将被分配w 的值,因此它们将具有相同的值。您可以使用任何波形查看器或使用 $display、$monitor、... 来检查这些值。
猜你喜欢
  • 1970-01-01
  • 2022-01-13
  • 1970-01-01
  • 1970-01-01
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多