-- ejemplo multiplexor 4 a 1 donde se cuenta con "4 datos de entrada", cada uno con "ancho de 5 bits", y un dato de salida, también con ancho 5 bit. (Nota: El demultiplexor [FALTA- enlazarlo a la nota del demultiplexor] selecciona en cual de varias salidas se debe presentar el único dato seleccionado desde las entradas)
--LIBRERIAS--------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
--DEFINICION DE PUERTOS DE LA ENTIDAD------------------------------------
entity MULTIPLEXOR_1 is
port( DATO_IN3: in std_logic_vector(4 downto 0); -- ancho 5 bit
DATO_IN2: in std_logic_vector(4 downto 0); -- ancho 5 bit
DATO_IN1: in std_logic_vector(4 downto 0); -- ancho 5 bit
DATO_IN0: in std_logic_vector(4 downto 0); -- ancho 5 bit
SELECTOR_DE_DATO: in std_logic_vector(1 downto 0); -- ancho 2 bit
DATO_OUT: out std_logic_vector(4 downto 0) -- ancho 5 bit
);
end entity MULTIPLEXOR_1;
--DOS OPCIONES PARA DEFINIR LA ARQUITECTURA-------------------------------
-- Utilizando sentencia CASE
architecture ar1_MULTIPLEXOR_1 of MULTIPLEXOR_1 is
begin
process(DATO_IN3,DATO_IN2,DATO_IN1,DATO_IN0,SELECTOR_DE_DATO)
begin
case (SELECTOR_DE_DATO) is
when "00" => DATO_OUT <= DATO_IN0;
when "01" => DATO_OUT <= DATO_IN1;
when "10" => DATO_OUT <= DATO_IN2;
when "11" => DATO_OUT <= DATO_IN3;
when others => DATO_OUT <= "ZZZZZ"; -- Alta impedancia
end case;
end process;
end architecture ar1_MULTIPLEXOR_1;
-- Utilizando sentencia WHEN-ELSE
architecture ar2_MULTIPLEXOR_1 of MULTIPLEXOR_1 is
begin
DATO_OUT <= DATO_IN0 when SELECTOR_DE_DATO="00" else
DATO_IN1 when SELECTOR_DE_DATO="01" else
DATO_IN2 when SELECTOR_DE_DATO="10" else
DATO_IN3 when SELECTOR_DE_DATO="11" else
"ZZZZZ";
end architecture ar2_MULTIPLEXOR_1;
-------------------------------------------------------------------------