Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17249 Discussions

Verilog Constants/Paremters accross Verilog Files?

Altera_Forum
Honored Contributor II
3,542 Views

Hi Guys, 

 

I'm teaching myself verilog atm, (i've done small VHDL before). 

 

My question is: 

how can i define and share constants accross .v files? 

 

For instance in C: Say you want to define a constant "SIZE" to be value "5"; and you use this definition accross many files. To do so you put it in a .h file and# include that .h where needed. 

 

is there a verilog practice that does a similar thing? 

Some brief googling i couldn't see a way, so if there isn't what is best practice for that?
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
1,934 Views

The Verilog preprocessor has an `include statement for this purpose.

0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

It is possible to do so. As fvm (http://www.alteraforum.com/forum/member.php?u=3117) sad the `include statement could be used. To define a global constant you can use the `define statement into a separate verilog file and than include it where needed in your code. Here is an example: 

 

included_file.v: 

`ifndef INCLUDED_FILE `define SIZE 8'd5 `endif Best regards, 

VT
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

Thanks guys, much appreciated. this lead me to google and i found a good pdf on the topic, here's he link for others to see; 

http://v2kparse.sourceforge.net/includes.pdf
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

It might also be worth looking into packages. Although the `include is easy, I've found it more difficult to debug, as the file is read in "behind the scenes" and so it's hard to figure out what's going on. I think packages are more formal. (I also prefer formally passing the parameter in alongside the ports whenever possible). I think you can get by with both, and I don't do enough coding to really have a good handle, but would be curious if others had an opinion on the best way to handle this?

0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

 

--- Quote Start ---  

It might also be worth looking into packages. 

--- Quote End ---  

 

This would be the standard means in VHDL designs. I'm not quite sure which Verilog element you're adressing with "packages". As far as I'm aware of, there's no suitable Verilog option besides included file constants and module parameters passed through the hierarchies.
0 Kudos
Reply