I've built a multiplexer which takes 2 inputs: one array of std_logic_vector
and one std_logic_vector
to select the correct array. It should be written more generic, but I'm not sure how. The length of SEL
grows if the length of X
grows (4-bit if 16 inputs, 6-bit if 64, etc.). I'm currently using custom types as input, but this makes making the code more generic problematic.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
LIBRARY work;
USE work.type_arrays.ALL;
entity mux_16to1 is
Port ( SEL : in STD_LOGIC_VECTOR ( 3 downto 0);
X : in A16_SLV16;
Y : out STD_LOGIC_VECTOR (15 downto 0));
end mux_16to1;
architecture sel of mux_16to1 is
begin
with SEL select
Y <= X(0) when "0000",
X(1) when "0001",
X(2) when "0010",
X(3) when "0011",
X(4) when "0100",
X(5) when "0101",
X(6) when "0110",
X(7) when "0111",
X(8) when "1000",
X(9) when "1001",
X(10) when "1010",
X(11) when "1011",
X(12) when "1100",
X(13) when "1101",
X(14) when "1110",
X(15) when "1111",
"0000000000000000" when others;
end sel;
With work.type_arrays consisting of:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
PACKAGE type_arrays IS
SUBTYPE SLV16 IS std_logic_vector( 15 downto 0 );
TYPE A16_SLV16 IS ARRAY ( 0 to 15 ) OF SLV16;
TYPE A256_SLV16 IS ARRAY ( 0 to 255 ) OF SLV16;
END type_arrays;
Does anyone have a solution/idea to make it generic? I want to use this mux for 256*16-bit solutions and perhaps even 1024*24-bit as well. Writing the whole thing by hand can't be the VHDL way to do it.
The alternative is letting a generator write the code, but I'd like to prevent that if possible.