VHDL – How to Initialize Array with Variable Length in VHDL

vhdl

I want to initialize an array with length dependent on a signal I set earlier (as can be seen in the code below), unfortunately I can't quite get the datatypes to line up and am having a hard time finding documentation on this.

signal count : unsigned(31 downto 0) := 4;

type my_array is array (0 to count) of std_logic_vector(255 downto 0);
signal my_signals : my_array;

I've tried switching unsigned to integer and natural, yet I keep getting the error only scalar types may be constrained by range
. How would you resolve this?

Best Answer

The type definition requires a constant to define the range. This is used during simulator compilation or during synthesis. It is fixed once the circuit, real or simulated, is operating.

Signals can change and are therefore not constant. Their value changes during circuit operation.

So the two are incompatible. Use a constant.

Your question doesn't describe why you want to do such a thing so I can't advise better solutions to it.