I\'d like to set a parameter based on a parameter which is set when the module is instantiated. I have the following.
module foo #(WORDS = 8);
parameter P00
There has been quite a few questions on here recently using generates and assigns inappropriately not sure if a new tutorial has been written which is not teaching these things correctly.
Parameters or Localparams should not be defined more than once, and they are constants so can not have the value changed. I think you are also missing the parameter keyword from module foo.
module foo #(
parameter WORDS = 8
);
localparam P00 = WORD;
It is common to use as scaling factors:
module foo #(
parameter WIDTH = 8
parameter MAX_VALUE = 2**WIDTH
);
What you have defined looks like you should just be using a logic not parameter to hold the value;
I would rewrite the whole thing as:
module foo #(WORDS = 8);
logic [31:0] P00 = 33;
logic [7:0] tmp;
always @* begin
case (WORDS)
4: begin : A
tmp = 8'haa;
P00 = 4;
end
8: begin : B
tmp = 8'hbb;
P00 = 8;
end
16: begin : C
tmp = 8'hcc;
P00 = 16;
end
default: begin : D
tmp = 8'hdd;
P00 = 8;
end
endcase
end
The use of generate is unnecessary for what you are trying to achieve here.