On Tue, 4 Nov 2008 21:24:22 -0800 (PST), sandeep wrote:
>Consider following size constant -- "temp = 10'd28".
>Now I want to replace 10 with parameter TEN = 10;
>i.e temp = TEN'd28.
>But compiler is giving error for above expression. It is allowing me
>to use `define TEN 10
>and `TEN'd28.
>I donot know my complain is valid or not but it is stupid thing. I
>donot want to use `define construct instead my pref is parameter
>construct.
>Is there any way I can use parameter and write temp = {parameter'd28}
Since Verilog-2001 it has been legal to size parameters explicitly.
parameter SIZE = 10;
parameter [SIZE-1:0] temp = 28;
Now you know for sure that temp is exactly SIZE bits wide,
and you can use it in concatenations etc.
As others have said, the bit-wdith in sized numbers like 8'b1 must
be a simple literal number, and cannot be a parameter. For some
constants it's possible to use replication:
parameter temp = {SIZE{1'b0}};
However, I would question why you ever need to do this. What
will you do with the sized constant? As soon as you copy it
into some other variable, it takes on the size of the target
variable:
parameter SIZE = 10;
parameter n = 28; // there is no need for this to be 10 bits wide
reg [SIZE-1:0] target;
initial begin
...
target = n; // this is legal even though "n" is 32 bits
...
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
[email protected]
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.