0 votes
in Verilog by (200 points)

What are localparams in Verilog and how do I use them?

2 Answers

0 votes
by (200 points)

The localparam in Verilog is a kind of constant that is local for modules and available only inside the module in which it is declared. I use it to define some module-specific implicit parameters and settings that are for module use only and doesn't specify it's behavior for external configuration (regardless of what it actually is).

For example, I can define a global parameter of address bus width and then I derive from that value either the buffer depth or the number of registers. For any external devices it doesn't matter what it actually is inside my module.


CAPTURE_CLOCK_MUL_FACTOR - is the parameter form a module declaration

logic [CAPTURE_CNT_WIDTH-1:0] capture_cnt = {(CAPTURE_CNT_WIDTH){1'b0}};
localparam vote_pos_1 = CAPTURE_CLOCK_MUL_FACTOR / 3 - 1;
localparam vote_pos_2 = CAPTURE_CLOCK_MUL_FACTOR / 2 - 1;
localparam vote_pos_3 = CAPTURE_CLOCK_MUL_FACTOR / 2 + 1;

reg state;
localparam stHead = 1;
localparam stBody = 2;
localparam stTail = 4;
0 votes
by (200 points)

If you want to create a parameter and make sure that its value is not accidentally changed somewhere along the program, you use 'localparam'. Localparam is same as 'parameter' but unlike 'parameter', its value cannot be modified by redefinition or by the keyword defparam. However, local parameters can be assigned to parameters that can, in turn, be modified. Relevant examples are given as:

parameter Width = 8;
localparam Depth = Width*12;
localparam Size = 16;
Hardware Coder Community

© 2022 by Hardware Coder. User contributions are licensed under cc by-sa 4.0 with attribution required. Attribution means a link to the question, answer, user, etc on this site.

This site is owned and operated by Hardware Coder in McKinney, Texas.

Send Us A Message
About Us

By using this site, you agree to the following:

Privacy Policy
Terms and Conditions
DMCA Policy
Earnings Disclaimer
Legal Disclaimer