3
\$\begingroup\$

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 ?

Martin Thompson
8,6491 gold badge26 silver badges45 bronze badges
asked May 23, 2013 at 5:22
\$\endgroup\$

2 Answers 2

5
\$\begingroup\$

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}};
answered May 23, 2013 at 8:55
\$\endgroup\$
0
0
\$\begingroup\$

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;
answered May 23, 2013 at 8:33
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.