Verilog multiple drivers

前端 未结 2 1703
青春惊慌失措
青春惊慌失措 2021-01-15 03:04

I\'m trying to make BCD Counter using Verilog that will be connected to 7-segment decoder.
After I synthesize it, the error occured like this:

2条回答
  •  Happy的楠姐
    2021-01-15 03:16

    You cannot modify BCD from different always blocks. Any modification should be perfomed in only one always. Something like:

    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
    

提交回复
热议问题