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 Constant Numbers

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
Hi everyone

I have a silly question but I haven't found the solution anywhere else, so I hope you guys can help me.

How can some one implement a constant number without having to waste registers with it? For example, I want to add a variable "var" with a constant "c":

reg [15:0] var;

sum=var+c;


Is there a way to define the constant "c" through a "wire" with bits connected to VCC or GND, depending on the value. Usually I can do this on schematic when using Xilinx ISE but I dont know how to do it in Verilog.

Thanks
 

Use a parameter?

reg [15:0] var;

parameter c=123;
sum=var+c;
 
or in verilog2001, a localparam.

verilog offers 3 "constant" types:
`define MY_CONST 123
This replaces `MY_CONST with 123. It generally isn't preferred, as the value of `MY_CONST can persist between files based on compile order. This can lead to unexpected behavior.

parameter MY_CONST = 123;
This creates a constant similar to VHDL's generic. This value can be overridden at instantiation using #(.MY_CONST(456))

localparam MY_CONST = 123;
This creates a constant that cannot be changed. Using localparam is useful because it makes it clear that the parameter is not meant to be changed at instantiation.
 
or in verilog2001, a localparam.

verilog offers 3 "constant" types:
`define MY_CONST 123
This replaces `MY_CONST with 123. It generally isn't preferred, as the value of `MY_CONST can persist between files based on compile order. This can lead to unexpected behavior.

parameter MY_CONST = 123;
This creates a constant similar to VHDL's generic. This value can be overridden at instantiation using #(.MY_CONST(456))

localparam MY_CONST = 123;
This creates a constant that cannot be changed. Using localparam is useful because it makes it clear that the parameter is not meant to be changed at instantiation.

Very usefull thanks

Now I have another question: Is it possible to initialize a constant as a vector, so that I can store several coefficients in one single vector instead of separate constants?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top