I am trying to write a simple module to output a 14-bit number based on the value of four input signals. My attempt is shown below.
module select_size(
input a,
input b,
input c,
input d,
output [13:0] size
);
if (a) begin
assign size = 14'h2222;
end
else begin
if (b) begin
assign size = 14'h1111;
end
else begin
if (c) begin
assign size = 14'h0777;
end
else begin
assign size = 14'h0333;
end
end
end
endmodule
Upon compilation, I receive the following error:
ERROR:HDLCompiler:44 – Line 67: c is not a constant
I don’t understand why that particular if-statement isn’t working if the other two preceding it are. I have tried changing the condition to
if (c == 1) begin
but to no avail.
Does anybody know how to solve this error? Thank you!
Two problems:
1) You need to put
ifstatements inside analwaysblock.If you use verilog-2001, you can use
Otherwise specify all the inputs in the sensitivity list:
2) Constant assignments are not allowed inside if statements.
Remove the
assignkeyword from any statements inside theifblock:You will also have to declare size as a
regtype.However my preference would be to rewrite the entire module with conditional operator, I find it much preferrable to read. This following module achieves the same result: