Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VHDL multiple std_logic_vector to one large std_logic_vector

Tags:

vhdl

I have four std_logic_vectors (15 downto 0) and want to stack them into a std_logic_vector (63 downt 0) so fare I have found one way of doing it but is it the correct way or is there a more optimal and correct way to do it?

signal slv16_1,slv16_2,slv16_3,slv16_4 : std_logic_vector(15 downto 0);
signal slv64 : std_logic_vector(63 downto 0);

slv64(15 downto 0) <= slv16_1;
slv64(31 downto 16) <= slv16_2;
slv64(47 downto 32) <= slv16_3;
slv64(63 downto 48) <= slv16_4;
like image 794
Mathias Avatar asked Oct 14 '15 15:10

Mathias


Video Answer


3 Answers

An easy way to accomplish this is to use the concatenation operator &. It achieves the same thing you did above, but with less code required.

slv64 <= slv16_4 & slv16_3 & slv16_2 & slv16_1;
like image 84
Russell Avatar answered Sep 21 '22 07:09

Russell


Since the source vectors have unique names, I don't see a way to automate this. What you might be able to try is to never use the 16-bit vectors, and instead use slices of the larger 64 bit vector. So instead of an assignment like this:

slv16_1 <= "0101110000111010";

Use

slv64(15 downto 0) <= "0101110000111010";

Or instead of an entity instantiation where you connect slv16_2 like this:

output_port => slv16_2,

Use

output_port => slv64(31 downto 16),

I would really need to see more of your code to understand what might work best, but my basic answer is 'use the larger vector in the first place'.

If you can't do this for some reason, an alternative would be to declare your 16-bit vectors as an array of arrays:

type slv16_array_type is array (integer range <>) of std_logic_vector(15 downto 0);
signal slv16_array : slv16_array_type(3 downto 0);

You could then assign to the elements like this:

slv16_array(0) <= "0101";

You could combine the elements of this type with a generate loop:

slv16_combine : for i in 0 to 3 generate
  slv64((16*(i+1))-1 downto 16*i) <= slv16_array(i);
end generate;
like image 36
scary_jeff Avatar answered Sep 22 '22 07:09

scary_jeff


VHDL guide says that this one should work:

slv64 <= (slv16_4, slv16_3, slv16_2, slv16_1);
like image 38
Ivan I. Ovchinnikov Avatar answered Sep 22 '22 07:09

Ivan I. Ovchinnikov