信号结果植入连接到多个驱动器

时间:2016-02-12 16:35:38

标签: verilog

我一直试图实施一个简单的verilog程序,但我一直遇到两个错误,我似乎找到了解决方案。我收到的两个错误是:

1. Line 21: Empty module <AddOrSubtractThenSelectAndDecodedInto7SegmentsDisplay> remains a black box. 

2. Line 40: Signal Result[3] in unit AddOrSubtractThenSelectAndDecodedInto7SegmentsDisplay is connected to following multiple drivers:

Driver 0: output signal Result[3] of instance Latch (Result[3]).
Driver 1: output signal Result[3] of instance Latch (_i000011).
Driver 0: output signal Result[2] of instance Latch (Result[2]).
Driver 1: output signal Result[2] of instance Latch (_i000012).
Driver 0: output signal Result[1] of instance Latch (Result[1]).
Driver 1: output signal Result[1] of instance Latch (_i000013).
Driver 0: output signal Result[0] of instance Latch (Result[0]).
Driver 1: output signal Result[0] of instance Latch (_i000014).
Module AddOrSubtractThenSelectAndDecodedInto7SegmentsDisplay remains a blackbox, due to errors in its contents

我在询问之前试图找到解决方案,但无法为我的问题找到合适的解决方案。所以我的问题是:为什么会发生这种情况,解决这个问题的最佳解决方案是什么?

这是我的verilog代码(没有测试台):

module AddOrSubtractThenSelectAndDecodedInto7SegmentsDisplay(A,B,S,Result,OF,Display);

// Inputs A,B,S
input [3:0] A;
input [3:0] B;
input [1:0] S;

// Outputs OF,Result,Display
output reg [6:0] Display;
output reg [3:0] Result;
output reg OF;

reg [3:0] Result_reg;

// Wires
wire [3:0] A;
wire [3:0] B;
wire [1:0] S;

always @(A,B,S) begin
    if (S == 1)
        {OF,Result} = A + B;
    else if (S == 0)
        {OF,Result} = A - B;
end 

always @(OF,Result) begin
    case (Result) 
        5'b00000: Display = 7'b1111110;//0
        5'b00001: Display = 7'b0110000;//1
        5'b00010: Display = 7'b1101101;//2
        5'b00011: Display = 7'b1111001;//3
        5'b00100: Display = 7'b0110011;//4
        5'b00101: Display = 7'b1011011;//5
        5'b00110: Display = 7'b1011111;//6
        5'b00111: Display = 7'b1110000;//7
        5'b01000: Display = 7'b1111111;//8
        5'b01001: Display = 7'b1111011;//9
        5'b01010: Display = 7'b1110111;//A
        5'b01011: Display = 7'b0011111;//B
        5'b01100: Display = 7'b1001110;//C
        5'b01101: Display = 7'b0111101;//D
        5'b01110: Display = 7'b1001111;//E
        5'b01111: Display = 7'b1000111;//F
        default: Display = 7'bx;
    endcase

     if (OF == 1)begin
        Result = 4'bx;
        Display = 7'b0011101;
    end

end

endmodule

2 个答案:

答案 0 :(得分:2)

你在这里推断一个闩锁:

always @(A,B,S) begin
    if (S == 1)
        {OF,Result} = A + B;
    else if (S == 0)
        {OF,Result} = A - B;
    // <-- inferred latch because S=2 and S=3 is not described
end 

通常不建议使用(级别敏感)锁存器。它们具有价值,但您需要对它们充满关注,否则您会遇到时机和亚稳态问题。有关详情,请参阅

第二个驱动因素是因为您在两个始终阻止的情况下驾驶Result。它在模拟器中工作,但对于合成是非法的。

always @(OF,Result) begin
  // ...

  if (OF == 1)begin
    Result = 4'bx; // <-- second driver on 'Result'. Illegal for synthesis
    Display = 7'b0011101;
  end
end

注意:将计划合成的内容分配给X值通常被认为是不好的做法。

要解决多个驱动程序错误,您必须在同一个始终阻止中拥有Result的所有分配。移动赋值或合并始终块。

注意:除非要求遵循严格的1995编码惯例,否则不应在敏感度列表中声明信号。而是使用自动敏感列表(@*@(*))在2001年添加到verilog。你有2001支持,因为1995不支持逗号作为敏感列表的信号分隔符; 1995使用or作为敏感度列表的信号分隔符。

答案 1 :(得分:0)

我已经为同一个问题写了答案。您可以登录链接: Verilog Subtraction and addition

你推断了Latch,因为你已经取了2位宽的“S”而你没有为“S”的2个选项指定“Result”的值。

  

不完整if或case声明可能是   合成成一个锁存器。因为对于工具,你没有指定什么   在网上开车以获得if / case条件的剩余部分。在这种情况下,   工具将尝试制作硬件,这将驱动以前的值   对于那些条件。为此,将推断出闩锁。

always @(A,B,S) begin
    if (S == 1)
        {OF,Result} = A + B;
    else if (S == 0)
        {OF,Result} = A - B;
    // What for S == 2 or S == 3?
    // So tool thinks, that you want to have previous value of Result
    // in both cases, and hence it needs to infer a latch for Result to
    // have the previous value.
end 

现在,您遇到了多个驱动程序错误,因为“结果”正在通过多个始终阻止。

  

“reg”变量,不能有多个驱动程序。但是“电线”可以   当然有。因此,如果一个网络有多个驱动程序,那么它必须是   “电线”类型。