I want to create an unsigned in a function whose length is determined by the function parameters. I thought that was a legit thing to do- pretty sure I've even done it before, but maybe not- but ISE 14.7 doesn't think so (I know, I know. I have to use ISE because we're resurrecting an old system).
The purpose of the function is divide by a power of 2 and round the result. ISE doesn't like that I'm subtracting num_bits from the length of the input when declaring truncated. Is there a better way to do this?
function my_round(data_in : in unsigned; num_bits : in integer) return unsigned is
variable truncated : unsigned(data_in'left - num_bits downto 0);
begin
truncated := data_in(data_in'left downto num_bits);
if my_and_reduce(truncated) = '0' and data_in(num_bits-1) = '1' then
truncated := truncated + 1;
end if;
return truncated;
end my_round;
The error message that ISE gives me when trying to synthesize the code is "Constant value expected for expression (31 - num_bits)"
I want to create an unsigned in a function whose length is determined by the function parameters. I thought that was a legit thing to do- pretty sure I've even done it before, but maybe not- but ISE 14.7 doesn't think so (I know, I know. I have to use ISE because we're resurrecting an old system).
The purpose of the function is divide by a power of 2 and round the result. ISE doesn't like that I'm subtracting num_bits from the length of the input when declaring truncated. Is there a better way to do this?
function my_round(data_in : in unsigned; num_bits : in integer) return unsigned is
variable truncated : unsigned(data_in'left - num_bits downto 0);
begin
truncated := data_in(data_in'left downto num_bits);
if my_and_reduce(truncated) = '0' and data_in(num_bits-1) = '1' then
truncated := truncated + 1;
end if;
return truncated;
end my_round;
The error message that ISE gives me when trying to synthesize the code is "Constant value expected for expression (31 - num_bits)"
Share Improve this question edited Feb 6 at 17:09 user16145658 7771 gold badge6 silver badges13 bronze badges asked Feb 5 at 16:05 Jim ClayJim Clay 1193 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1It turned out that iSim, the Xilinx ISE simulator, did not have an issue with the function, so it appears to me that the problem is not at the language level, rather it's an ISE implementation problem.
I changed the function to the following, since I always called it with a num_bit parameter of 14, and it built fine.
function my_round(data_in : in unsigned; dummy : in integer) return unsigned is
constant num_bits : integer := 14;
variable truncated : unsigned(data_in'left - num_bits downto 0);
begin
truncated := data_in(data_in'left downto num_bits);
if my_and_reduce(truncated) = '0' and data_in(num_bits-1) = '1' then
truncated := truncated + 1;
end if;
return truncated;
end my_round;
function my_round(truncated : in unsigned; highest_cut_off_bit : in std_logic) ...
. The parameter highest_cut_off_bit must then be filled with data_in(num_bits-1) when you call the function. The checkdata_in(num_bits-1) = '1'
would then behighest_cut_off_bit='1'
. – Matthias Schweikart Commented Feb 5 at 16:28