Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Verilog constants with parameterized bit width

Status
Not open for further replies.

fcfusion

Full Member level 4
Joined
Mar 6, 2010
Messages
203
Helped
43
Reputation
86
Reaction score
24
Trophy points
1,298
Activity points
2,826
Hello everyone

I have a question regarding constant assigments with parameterized bit width. For example, i want to initialize a register with a constant value 10 . If i wish to use a fixed bit width all I have to do is:

reg [7:0] whatever;

always @(posedge)
begin
whatever <= 8'd10;
end


Now, if I want to define the registers with different bit widths, according to my needs I can simply do:

parameter Nbits = 16;

reg [Nbits-1:0] whatever;

However I do not know how to assign the value to the register, because of the " 8'd " expression.


whatever <= 8'd10; //???????


How can I subsitute this expression for something that can be easily changed through parameters without resulting in synthesis warnings?

Thank you
 

Code:
parameter Nbits = 16;

reg [Nbits-1:0] whatever;

whatever <= {1'b1, (Nbits-1) {1'b0}}; // something like this
gives you the same as:

Code:
reg [15:0] whatever;

whatever <= 16'b1000000000000000;
hope that helps

edit

DOH!

I am blind. I didn't see the 'd' there. you are assigning decimal value of 10. Hah, only 10 types of people right? Those that misread binary related questions and those that don't.

Anyway, you could just dispense with the width.

Code:
whatever <= 10;

or you can pad it with zeroes like this:

Code:
whatever <= {(Nbits-4) 1'b0, 4'd10};

depending on what you want....
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top