Jingxuan Cai
Jingxuan Cai

Reputation: 11

The Multiple Driver error when writing always_ff

I want to create a clock cycle counter in a state machine and change the state every two clock cycles, so I write:

module control(
  output reg[2:0]DiceValue,
  input Clock, nReset, [1:0]Ran 
  );

timeunit 1ns; timeprecision 10ps;
logic clock_count = 0;
logic present_stage, next_stage;

always_ff @ (posedge Clock, negedge nReset)
  begin
    if (!nReset)
      begin
      present_stage <= 1;
      next_stage <= 1;
      clock_count <= 0;
      end
    else
      begin
      clock_count <= clock_count+1;
      end
      if (clock_count == 1)
        begin
        clock_count <= 0;
        present_stage <= next_stage;
        end
  end

And it reports an error:

Multiple drivers to always_ff output variable clock_count detected.

Why does it happen? Any suggestions about this error?

Upvotes: 1

Views: 1131

Answers (1)

toolic
toolic

Reputation: 62037

When you declare clock_count, you also assign it to 0, but the compiler considers that a violation. Since you use an asynchronous reset to also set the signal in the always_ff block, I see no reason for you to initialize to a value when you declare it.

I recommend fixing this compile error by changing:

logic clock_count = 0;

to:

logic clock_count;

The VCS simulator (available on EDA Playground) gives more information:

Error-[ICPD_INIT] Illegal combination of drivers
  Illegal combination of procedural drivers
  Variable "clock_count" is driven by an invalid combination of procedural 
  drivers. Variables written on left-hand of "always_ff" cannot be written to 
  by any other processes, including other "always_ff" processes.
  This variable is declared at <line number>: logic clock_count;
  The first driver is at : always_ff @(posedge Clock or negedge 
  nReset) begin
  if (!nReset) begin
   ...
  The second driver is at <line number>: clock_count = 0;
  Use '-ignore initializer_driver_checks' to suppress this error

If for some reason, you feel the need to keep the declare/initialization as-is, you could use the always keyword instead of always_ff. This also avoids the error, but I prefer the 1st solution I proposed.

Upvotes: 1

Related Questions