2016-02-12 142 views
-1

我一直在试图实现一个简单的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 
+0

'Result'是4位宽。为什么你使用5位的案件('5'b00000')? – toolic

回答

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 

一般(级sencitive)锁存并没有建议。他们有价值,但你需要对他们很满意,否则你会得到时间和亚稳态问题。欲了解更多看到

第二个驱动器,是因为你在两个always块驾驶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.

要解决多重驱动程序错误的东西,你必须有所有assigments在Result同样总是阻止。要么移动任务,要么合并always块。

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

+0

啊,谢谢Greg! – mur7ay

0

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

由于您已经采用了2位宽的“S”,并且没有为“S”的2个选项指定“结果”的值,所以推断出Latch。

不完整的if语句或case语句可能会将 合成为一个latch。因为对于工具,你没有指定,在网络上驾驶什么以作为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 

现在,你越来越多的驱动程序错误,因为“结果”正在通过多个always块驱动。

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