This question explains how to use Verilog parameters to combine constants from different modules at compile time. I am wondering if it is also possible to use conditional statements to modify parameter values at compile time.
Specifically, if the calculated total of the parameter values exceeds some maxLength, I want the parameter to 'wrap around' maxLength and be left with the remainder instead.
Pseudo-code example:
module toplevel {
defparam myPole.offset = 95;
pole myPole();
}
module pole {
parameter offset = 0; // default value, overwritten by 95
localparam x = 1;
localparam y = 2;
localparam z = 3;
localparam maxLength = 100;
localparam transitionConst = x + y + z + offset; // total is 101, this works as expected
if(transitionConst > maxLength){
transitionConst = transistionConst - maxLength;
} // transitionConst should wrap around 100, and be left with 1
}
I looked at compiler directive tutorials at asic-world.com and TestBench.in, but the only if statements they describe are ifdefs. So, I suspect that Verilog does not support generic compile-time conditional statements. Is there a different approach I could use to accomplish this?
(P.S. I've seen Verilog Q&A on both EE.SE as well as StackOverflow. Which is the more appropriate community?)
defparam
. It is strongly discouraged and the standardization body would loved to drop it if they could. \$\endgroup\$