- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Verilog preprocessor has an `include statement for this purpose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page