Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

Is something like this possible ?

parameter width;
wire[width-1] a_net = (width)'b0;

I basically need a variable to control the width of the right hand side. I am planning to use this in an test bench where I just have to change the parameter width at the beginning of the file, and this parameter sets the net width in all other occurrences of 'a_net'.

If this doesn't work - is there any other workaround ?

share|improve this question

2 Answers 2

You want to match the right hand side width with the declaration width to avoid tool warnings?

First use a 1-bit wide zero constant, this will be expanded using the Verilog expansion rules, which will give you an appropriate width zero:

wire [width-1:0] a_net = 1'b0;

If that generates a simulator/synthesiser warning your tools are outside of the Verilog spec. A common way to get around this is with the replication operator, which can take a constant width:

wire [width-1:0] a_net = {width{1'b0}};
share|improve this answer
    
You need a proper rage in your example (i.e. [width-1:0]), otherwise I agree with your answer. –  Greg May 23 '13 at 19:56
    
@Greg thanks for picking up on that! –  shuckc May 30 '13 at 13:40

You can do this with parameters is you want it just in one module:

parameter width = 8;
wire [width-1:0] a_net = 0;

For more than one module it's easier to do it with a define:

`define WIDTH 8
wire [`WIDTH-1:0] a_net = 0;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.