2013-04-29 83 views
1

1多路複用器,我需要用4創建XOR:1多路複用器(我知道這是一個不容易復...)XOR使用4:VHDL

我發現這個有用的例子4:1

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

entity multiplexer4_1 is 
port (
     i0 : in std_logic; 
     i1 : in std_logic; 
     i2 : in std_logic; 
     i3 : in std_logic; 
    sel : in std_logic_vector(1 downto 0); 
    bitout : out std_logic 
    ); 
end multiplexer4_1; 

architecture Behavioral of multiplexer4_1 is 
begin 

process(i0,i1,i2,i3,sel) 
begin 
case sel is 
    when "00" => bitout <= i0; 
    when "01" => bitout <= i1; 
    when "10" => bitout <= i2; 
    when others => bitout <= i3; 
end case; 
end process; 

end Behavioral; 

但我有點困惑如何告訴多路複用器輸出1時01或10是輸入和0,否則。 我可以給i0-i3分配值嗎?對不起,我是VHDL的新手

+0

多少輸入你不異或門必須有? – simon 2013-04-29 15:20:22

+0

它有2個門。 – arnoapp 2013-04-29 15:41:07

回答

1
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

entity xor4_1 is 
port (
    --i0 : in std_logic; 
    --i1 : in std_logic; 
    --i2 : in std_logic; 
    --i3 : in std_logic; 
sel : in std_logic_vector(1 downto 0); 
bitout : out std_logic 
); 
end xor4_1; 

architecture Behavioral of xor4_1 is 

signal i0 : std_logic; 
signal i1 : std_logic; 
signal i2 : std_logic; 
signal i3 : std_logic; 



begin 

process(i0,i1,i2,i3,sel) 
begin 
case sel is 
    when "00" => bitout <= i0; 
    when "01" => bitout <= i1; 
    when "10" => bitout <= i2; 
    when others => bitout <= i3; 
end case; 
end process; 

-- Now just hardcode the input bits to the appropriate values. 
-- I might be mistaken, but I'm pretty sure this is how the implementation tool 
--s actually would implement an XOR gates. 
i0 <= '0'; 
i1 <= '1'; 
i2 <= '1'; 
i3 <= '0'; 

end Behavioral; 
1

我假設你必須建立一個2輸入XOR門。一種可能性是將兩個輸入分別連接到sel(0)sel(1)。然後,您可以將恆定值連接到其餘的輸入i0i3,以便MUX4的真值表與XOR門的真值表相同。

+0

換句話說,當你實例化你的多路複用器時,分別連接'0','1','1','0'到i0,i1,i2,i3。 – EML 2013-04-29 15:36:41

+0

那麼我如何在VHDL中做到這一點?你有我的例子嗎? – arnoapp 2013-04-29 15:41:29

+0

@EML:這個問題聽起來像是我的功課。我想讓OP自己解決問題。 – simon 2013-04-29 15:47:43

1

您的MUX根據選擇信號將一個輸入連接到輸出。如果您想象選擇信號是XOR門的「輸入」,您只需確定XOR輸入(選擇信號)的每個組合的輸出應該是多少。然後連接MUX輸入,以便爲每個選擇輸入提供正確的電平。

造成這種情況的VHDL語法只是

inst: entity work.multiplexer4_1 
port map 
(
    i0 => '1'; -- or '0' 

etc.. 

    sel => xor_input_signals; 
    bitout => xor_output_signal 
);