Close Menu
VLSI Web
  • Home
    • About Us
    • Contact Us
    • Privacy Policy
  • Digital Design
    • Digital Circuits
    • Verilog
    • VHDL
    • System Verilog
    • UVM
  • VLSI Roles
    • RTL Design
    • Design Verification
    • Physical Design
    • DFT
    • STA
  • Interviews
  • Informative
  • VLSI Forge
Instagram LinkedIn WhatsApp Telegram
Instagram LinkedIn WhatsApp Telegram
VLSI Web
  • Home
    • About Us
    • Contact Us
    • Privacy Policy
  • Digital Design
    • Digital Circuits
    • Verilog
    • VHDL
    • System Verilog
    • UVM
  • VLSI Roles
    • RTL Design
    • Design Verification
    • Physical Design
    • DFT
    • STA
  • Interviews
  • Informative
  • VLSI Forge
VLSI Web
Verilog

parameter vs localparam vs `define in Verilog

Raju GorlaBy Raju Gorla1 August 2026Updated:11 October 2026No Comments3 Mins Read
Parameters and define in Verilog
Share
Facebook Twitter LinkedIn Email Telegram WhatsApp

The short answer: Use parameter for module constants that each instance may override (widths, depths), localparam for constants that must not be overridden (state encodings, derived values), and `define only for truly global settings, because macros are plain text substitution that leaks across files in compile order. Conditional compilation (`ifdef), `include and `timescale are the other compiler directives you’ll use regularly.

Parameters are what turn a one-off module into a reusable one. Macros are useful too, but they cause some of the most confusing bugs in large projects. This post combines my older posts on parameters and defines, with the rules I follow for each.

  1. At a glance
  2. parameter
  3. localparam
  4. `define and its traps
  5. Conditional compilation and include
  6. Other directives

Table of Contents

  • Part 1: At a glance
  • Part 2: parameter
  • Part 3: localparam
  • Part 4: `define and its traps
  • Part 5: Conditional compilation and include
  • Part 6: Other directives
  • FAQ
    • What is the difference between parameter and localparam?
    • What is the difference between parameter and `define?
    • Should I use defparam?
    • How do I calculate an address width from a depth?

Part 1: At a glance

parameter, localparam, define, ifdef, include and timescale compared
Pick the narrowest tool for the job.

Part 2: parameter

module fifo #(
  parameter DW = 32,                  // data width
  parameter DEPTH = 16
) (
  input  wire          clk,
  input  wire [DW-1:0] wdata,
  ...
);
  localparam AW = $clog2(DEPTH);     // derived: not overridable
  reg [DW-1:0] mem [0:DEPTH-1];
  reg [AW-1:0] wptr, rptr;
  ...
endmodule

// override per instance
fifo #(.DW(64), .DEPTH(32)) u_rx_fifo ( ... );
  • Parameters are resolved at elaboration, so they can size ports, arrays and generate loops.
  • Override by name (#(.DW(64))), never by position.
  • defparam can also override parameters from elsewhere in the hierarchy, but it’s deprecated and hard to follow. Don’t use it.
  • Check parameter values that must be legal (DEPTH a power of two, say) with a generate-time check or a simulation assertion.

Part 3: localparam

localparam [1:0] IDLE = 2'd0,
                 RUN  = 2'd1,
                 DONE = 2'd2;
localparam CNT_MAX = CLK_HZ / BAUD - 1;   // derived from parameters

Anything derived from other parameters, and anything that would break the design if someone changed it, should be a localparam.

Part 4: `define and its traps

`define DATA_W 32
reg [`DATA_W-1:0] r;     // note the backtick when using it

`define MAX(a,b) ((a) > (b) ? (a) : (b))   // macros can take arguments
  • Global scope. A `define stays defined for every file compiled after it, so compile order changes behaviour.
  • Silent redefinition. Two IPs that both define WIDTH differently will clash, often with just a warning.
  • Plain text. Always wrap macro arguments and the whole body in parentheses.
  • Use `undef at the end of a file for macros that should stay local.

My rule: parameters for anything per-module, and `define only for project-wide switches like simulation-only features.

Part 5: Conditional compilation and include

`ifndef FIFO_DEFS_VH          // include guard
`define FIFO_DEFS_VH
  `define FIFO_DW 32
`endif

`ifdef SIMULATION
  initial $display("fifo depth = %0d", DEPTH);
`endif

Pass macros on the command line (for example +define+SIMULATION in many simulators) instead of editing files.

Part 6: Other directives

Directive Use
`timescale 1ns/1ps Time unit and precision for delays
`default_nettype none Turn undeclared nets into errors
`resetall Reset directives to defaults
`celldefine / `endcelldefine Mark library cell modules

Practise this on VLSI Forge

I built VLSI Forge so you can write RTL in your browser, run it on a real simulator and check every signal in the waveform. Free, nothing to install.

RTL Design problems · Daily challenge

Previous in my Verilog series: Tasks and functions. Next: System tasks.

FAQ

What is the difference between parameter and localparam?

Both are module constants, but a parameter can be overridden when the module is instantiated and a localparam can’t.

What is the difference between parameter and `define?

A parameter belongs to one module and can differ per instance. A `define is a global text macro that applies to everything compiled after it.

Should I use defparam?

No. It’s deprecated in SystemVerilog and makes designs hard to follow. Override parameters at instantiation.

How do I calculate an address width from a depth?

Use $clog2: localparam AW = $clog2(DEPTH);

Circuit design FPGA Programming Hardware Description Language Verilog design Verilog parameters
Share. Facebook Twitter LinkedIn Email Telegram WhatsApp
Previous ArticleTasks and Functions in Verilog: Differences, Arguments and Examples
Next Article Verilog System Tasks: $display, $monitor, $readmemh and More
Raju Gorla
  • Website

Related Posts

Verilog

Verilog Coding Guidelines for Clean, Synthesisable RTL

3 August 2026
Verilog

Verilog System Tasks: $display, $monitor, $readmemh and More

2 August 2026
Verilog

Tasks and Functions in Verilog: Differences, Arguments and Examples

31 July 2026
Add A Comment
Leave A Reply Cancel Reply

Topics
  • Digital Circuits
  • Informative
  • Interview Questions
  • Physical Design
  • RTL Design
  • STA
  • System Verilog
  • UVM
  • Verilog
Instagram LinkedIn WhatsApp Telegram
  • About
  • Contact
  • Privacy Policy
  • VLSI Forge
  • Courses
  • Feedback
© 2026 VLSI Web

Type above and press Enter to search. Press Esc to cancel.