2013-12-17 117 views
1

我正在嘗試使用Verilog將BCD計數器連接到7段解碼器。
後,我合成它,發生錯誤是這樣的:

Multi-source in Unit <BCDcountmod> on signal <BCD0<3>>; this signal is connected to multiple drivers.> **還有更多.....

***任何解決方案*
這裏是我的代碼如下Verilog多個驅動程序

module BCDcountmod(
    input Clock, Clear, up, down, 
    output [3:0] BCD1_1, BCD0_0); 
reg [3:0] BCD1, BCD0; 
//reg [3:0] BCD1_1, BCD0_0; 
always @(posedge Clock) begin 
    if (Clear) begin 
    BCD1 <= 0; 
    BCD0 <= 0; 
    end 
end 


always @(posedge up) begin 
     if (BCD0 == 4'b1001) begin 
     BCD0 <= 0; 
     if (BCD1 == 4'b1001) 
      BCD1 <= 0; 
     else 
      BCD1 <= BCD1 + 1; 
     end 
     else 
     BCD0 <= BCD0 + 1; 
    end 


always @(posedge down) begin 
     if (BCD0 == 4'b0000) begin 
     BCD0 <= 4'b1001; 
     if (BCD1 == 4'b1001) 
      BCD1 <= 4'b1001; 
     else 
      BCD1 <= BCD1 - 1; 
     end 
     else 
     BCD0 <= BCD0 - 1; 
    end 

assign BCD1_1 = BCD1; 
assign BCD0_0 = BCD0; 

endmodule 
+0

看起來像以下副本:http://electronics.stackexchange.com/questions/93932/connected-to-multiple-drivers-problem-verilog – Greg

回答

0

只需添加到mcleod_ideafix的回答你有這樣的塊:

always @(posedge Clock) begin 
    if (Clear) begin 
    BCD1 <= 0; 
    BCD0 <= 0; 
    end 
end 

這意味着同步清零,我不知道如果這是你的意圖是通常你會異步爲您設計ASIC設計中的觸發器,或爲FPGA設置初始狀態。

對於觸發器使用異步主動高清

always @(posedge clock or posedge clear) begin 
    if (clear) begin 
    BCD1 <= 'b0; //NB: defined widths 
    BCD0 <= 'b0; 
    end 
    else 
    // normal logic 
    end 
end 

更典型的使用低電平有效復位:

always @(posedge clock or negedge clear_n) begin 
    if (~clear_n) begin 
    BCD1 <= 'b0; //NB: defined widths 
    BCD0 <= 'b0; 
    end 
    else 
    if (up == 1'b1) begin 
     // up logic 
    end 
    else if (down == 1'b1) begin 
     // down logic 
    end 
    else begin 
     // nothing to see here 
    end 
    end 
end 

做的比較與== 1'b1意味着你會得到一個如果LHS(左側)比1比特寬,則不會出現奇怪的行爲。

我還注意到,您有:

output [3:0] BCD1_1, BCD0_0); 
reg [3:0] BCD1, BCD0; 
assign BCD1_1 = BCD1; 
assign BCD0_0 = BCD0; 

你只需要做到以下幾點有REG的爲輸出:

output reg [3:0] BCD1, BCD0 

雖然我發現下面的更清楚:

output reg [3:0] BCD1, 
output reg [3:0] BCD0 
+1

SO的BCD1減計數器也有一個錯誤。如果(BCD1 == 4'b1001)BCD1 <= 4'b1001;'應該是'如果(BCD1 == 4'b0000)BCD1 <= 4'b1001; – Greg

4

您不能從always塊中修改BCD。任何修改只能在一個always中執行。喜歡的東西:

module BCDcountmod(
    input Clock, Clear, up, down, 
    output [3:0] BCD1_1, BCD0_0); 
    reg [3:0] BCD1, BCD0; 
//reg [3:0] BCD1_1, BCD0_0; 

    assign BCD1_1 = BCD1; 
    assign BCD0_0 = BCD0; 

    always @(posedge Clock) begin 
    //---- IS IT CLEAR? -------------- 
    if (Clear) begin 
     BCD1 <= 0; 
     BCD0 <= 0; 
    end 
    //---- IS IT UP? -------------- 
    else if (up) then begin 
     if (BCD0 == 4'b1001) begin 
     BCD0 <= 0; 
     if (BCD1 == 4'b1001) 
      BCD1 <= 0; 
     else 
      BCD1 <= BCD1 + 1; 
     end 
    end 
    //---- IS IT DOWN? -------------- 
    else if (down) begin 
     if (BCD0 == 4'b0000) begin 
     BCD0 <= 4'b1001; 
     if (BCD1 == 4'b1001) 
      BCD1 <= 4'b1001; 
     else 
      BCD1 <= BCD1 - 1; 
     end 
     else 
     BCD0 <= BCD0 - 1; 
    end 
    end 
endmodule 
相關問題