Hi everyone,
I am looking for a way to code my constant in a "soft-coded" way instead of a "hard-coded" way.
let's say I have:
wire [31:0] constant [0:5]
I want to be able to write:
assign constant[0] <= 2*2;
instead of
assign constant[0] <= 4; or assign constant [0] <= {29'b0,4'b100};
Correct me if I am wrong, but the first would generate 2 wire of 2'b10 with a multiplier (what a waste), which may or may not be synthesizable. The later is simply the usual constant assignment everyone seems to be using.
My actual code:
real rot_rad_angle[0:5]; //I don't want this to be synthesize... maybe I am using the wrong type? Parameters cannot be used in arrays
wire [31:0] rot_cos_arr[0:5];
wire [31:0] rot_cos2_arr[0:5];
wire [31:0] rot_sin_arr[0:5];
wire [31:0] rot_sin2_arr[0:5];
wire [31:0] rot_sincos_arr[0:5];
initial
begin //transform degrees to radian, want it to be done at COMPILE/ELABORATION time and not at Runtime
rot_rad_angle[0] = 0.0 *2.0*3.14159/360.0;
rot_rad_angle[1] = 29.0 *2.0*3.14159/360.0;
rot_rad_angle[2] = 16.8 *2.0*3.14159/360.0;
rot_rad_angle[3] = 8.6 *2.0*3.14159/360.0;
rot_rad_angle[4] = 3.57633437 *2.0*3.14159/360.0;
end
genvar i;
generate
for (i=0;i<5;i=i+1)
begin
assign rot_cos_arr
= $cos(rot_rad_angle); //those function return a fixed point of the right size
assign rot_sin_arr = $sin(rot_rad_angle);
assign rot_cos2_arr = $cos2(rot_rad_angle);
assign rot_sin2_arr = $sin2(rot_rad_angle);
assign rot_sincos_arr = $sincos(rot_rad_angle);
end
endgenerate
Note that in my code, in hardware, only rot_***_arr[0:5] should actually exist as wire connected to vdd/gnd depending on their bit.
I've search the internet for days on how to do this without avail. Of course, I know it would be possible to hard-code all those constant using a script, but this is highly error prone over time (as the script is run once, and after developer may assume that the constant are correct, while they can be wrong). ie 0x89D does not say as much as (3*4*20+5)*9.
I want to use to constant to do runtime computation later one. They will be connected to a mux to select which constant, and a mult to do the actual run-time multiplication.
Thank you!