SystemVerilog Topic - Localparam

Let’s discuss localparam in relation to previous topics of parameters and defparam statements.

Localparam prevents the values to be overwritten (directly) from outside the module. Once the variables are declared with ‘localparam’ the values stays constant. When the module is instantiated within another module the values can’t be passed for these data types.
 

Example use of localparam: To achieve best results from the  localparam avoid using the assignments with expressions containing parameters. Examples below

LTE - 4G Wireless Technology

Digital fundamentals.

Interview Questions.

module mux (A, B, C, Ctrl, Y);

 parameter  CT = 4;
 localparam IN = 8;
 localparam OUT= 8;

input [IN-1:0] A, B, C;
input [CT-1:0] Ctrl;
output[OUT-1:0] Y;

always@(*)
begin
        case (Ctrl)
                0: Y = A;
                1: Y = B;
                2: Y = C;
                3: Y = A;
                default: Y =A;
        endcase

end
endmodule

Tutorials @fullchipdesign.com

Verilog Tutorial.

LTE Tutorial.

Memory Tutorial.

Avoid following coding style using parameters and localparam.

module mux (A, B, C, Ctrl, Y);

 parameter  SZ = 3;
 parameter  CT = 2;
 localparam IN = CT**SZ;
 localparam OUT= CT**SZ;

input [IN-1:0] A, B, C;
input [CT-1:0] Ctrl;
output[OUT-1:0] Y;

always@(*)
begin
        case (Ctrl)
                0: Y = A;
                1: Y = B;
                2: Y = C;
                3: Y = A;
                default: Y =A;
        endcase

end
endmodule
 

Hope you liked! this page. Don't forgot to access relevant previous and next sections with links below.