Search code examples
verilog

How can I use $value$plusargs?


I'd like to use $value$plusargs as in the below code:

module top();
...
reg data;
real READ_FREQ

initial begin
if (!$value$plusargs("READ_FREQ=%0F", READ_FREQ))
 READ_FREQ = 197;
end

parameter wclk = 300;
parameter rclk = READ_FREQ;

always #(rclk/2.0) i_rclk = ~i_rclk;

...
endmodule

But, when I compile the code, I get this error:

irun: *E,VLGERR: An error occurred during parsing.  Review the log file for errors with the code *E and fix those identified problems to proceed.  Exiting with code (status 1).

irun(64): 12.10-p001: (c) Copyright 1995-2012 Cadence Design Systems, Inc.
file: ./top.v
parameter       rclk      = READ_FREQ;
                                         |
ncvlog: *E,NOTPAR (./top.v,197|41): Illegal operand for constant expression [4(IEEE)].

How can I use $value$plusargs?


Solution

  • You cannot assign a run-time variable to a parameter. Parameters can only be assigned during compile (default values) and elaboration (override values). $value$plusargs is executed at run-time, it also cannot assign a parameter.

    You haven't demonstrated where you need to use rclk other than the period value of i_rclk. You could modify your code to the following to get a the intended effect.

    real READ_FREQ;
    
    initial begin
      if (!$value$plusargs("READ_FREQ=%0F", READ_FREQ)) begin
        READ_FREQ = 197;
      end
      forever #(READ_FREQ/2.0) i_rclk = ~i_rclk;
    end