2014-02-20 25 views
0

我想使用多路複用器爲一些邏輯建模兩個D觸發器。當多路複用器選擇DFF D1(B = 0)時,我希望三個MSB具有「000」的靜態輸出,當多路複用器選擇DFF D2(B = 1)時,三個LSB應該固定爲「111」。如何使用多路複用邏輯爲兩個D觸發器建模

這是我的代碼 - 我最初在下面輸入時沒有檢查明顯的語法錯誤。我不知道如何解決我的問題:

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

entity dff_mux is 
Port (D1, D2 : in STD_LOGIC_VECTOR(11 DOWNTO 0); 
     clk : in STD_LOGIC; 
     rst : IN STD_LOGIC; 
     B : in STD_LOGIC; 
    data : out STD_LOGIC_VECTOR(11 DOWNTO 0)); 
end dff_mux; 

architecture Behavioral of dff_mux is 

signal Q1, Q2 : std_logic_vector(11 downto 0); 

begin 

process(clk,rst) 
begin 
    if (rst = '1') then 

     Q1<="000000000000"; 

    elsif (clk'event and clk='1') then 

     if (B = '0') then 

      -- I want to fix thee MSB to "000" 
      -- other bits shall retain their input value 
      D1(11) <= '0'; 
      D1(10) <= '0'; 
      D1(9) <= '0'; 
      Q1 <= D1; 

     elsif (B = '1') then 

      -- fix three LSB to "111" 
      -- other bits retain their input value 
      D2(2) <= '1'; 
      D2(1) <= '1'; 
      D2(0) <= '1'; 
      Q2 <= D2; 

     end if; 

    end if; 

end process; 

-- MUX description: select D1 when B = 0, else select D2 when B = 1 

MUX : process(B) 
begin 

    data <= Q1 when (B = '0') else 
      Q2; 

end process MUX; 

end Behavioral; 

在此先感謝任何人可以幫助我。

回答

1

你的VHDL設計描述中有很多錯誤。兩個過程語句驅動相同的信號(Q1Q2)。第二個進程有三個錯誤(沒有進程聲明標籤,而在關閉中指定了標籤,併發信號分配聲明中順序信號分配聲明是合適的)。看來第二個流程聲明應該被全部刪除。

如果意圖在Q1Q2寄存器的輸入上具有多路複用器,則第一個進程不起作用。您無法將值分配給塊內的正式輸入。

你應該分配B選擇值Q1Q2直接的過程語句內(內clkelsif)。

您對D(11)的分配有缺陷(使用==而不是<=)。

如果您只將一個值分配給特定信號(例如最長的靜態前綴D1D2),它不是多路複用器。請注意,所提供的Q2沒有重置值。

沒有指定地點的數據。

如果你正在爲課堂工作做這件事,那麼在沒有學習VHDL的情況下提供答案的人幾乎沒有什麼好處。如果你正在認真地學習VHDL,你需要更多的和逐步的構建練習。

如果我理解你正在嘗試做正確,將是這個樣子:

architecture Behavioral of basculeD is 
-- signal Q1, Q2 : std_logic_vector(11 downto 0); 
begin 

-- process(clk,rst) 
-- begin 
-- if (rst='1') then Q1<="000000000000"; 
-- elsif (clk'event and clk='1') then 
-- if (B='0') then 
-- D1(11) =='0'; -- i want to fix the 3MSB of D1 in the "000" ... 
-- D1(10) <='0'; 
-- D1(9) <='0'; 
-- Q1<= D1; 
-- elsif (B='1') then 
-- D2(2)<= '1'; -- the 3LSB are fixed to 111 , and defaut value ... 
-- D2(1)<='1'; 
-- D2(0)<='1'; 
-- Q2<=D2; 
-- end if; 
-- end if; 
-- end process; 

-- description MUX : select D1 when B=0, else select D2 when B= 1 
-- process(B) 
-- begin 
-- Q1 <= D1 when B='0' else 
-- Q2<=D2 when B='1' ; 
-- end process MUX; 

MUXED_REG: 
    process (clk,rst) 
    begin 
     if rst = '1' then 
      data <= (others => '0'); -- equivalent to "000000000000" 
     elsif clk'event and clk = '1' then 
     -- the actual multiplexer: 
      if B = '0' then 
       data <= ("000" & D1(8 downto 0)); 
      else -- B = '1', or other values 
       data <= (D2(11 downto 3) & "111"); 
      end if; 
     end if; 
    end process; 
end Behavioral; 

你當然可以保留的中介信號,說Q和地方數據的上述使用它,用併發信號分配從Qdata(輸出)。

使用上述體系結構代替您的分析。

隨着測試平臺:

library ieee; 
use ieee.std_logic_1164.all; 

entity basculeD_test is 
end entity; 

architecture test of basculeD_test is 
    component basculeD is 
     port ( 
      d1, d2: in std_logic_vector(11 downto 0); 
      clk:  in std_logic; 
      rst:  in std_logic; 
      b:  in std_logic; 
      data: out std_logic_vector(11 downto 0) 
     ); 
    end component; 

    signal d1:  std_logic_vector(11 downto 0) := (others => '1'); 
    signal d2:  std_logic_vector(11 downto 0) := (others => '0'); 
    signal clk:  std_logic := '0'; 
    signal rst:  std_logic := '1'; 
    signal b:  std_logic := '0'; 
    signal data: std_logic_vector(11 downto 0); 

begin 

CLOCK: 
    process 
    begin 
     wait for 10 ns; 
     clk <= not clk; 
     if Now > 100 ns then 
      wait; 
     end if; 
    end process; 

RESET: 
    process 
    begin 
     wait for 31 ns; 
     rst <= '0'; 
     wait; 
    end process; 

DUT: 
    basculeD 
     port map (
      d1 => d1, 
      d2 => d2, 
      clk => clk, 
      rst => rst, 
      b => b, 
      data => data 
     ); 

STIMULUS: 
    process 
    begin 
     wait for 65 ns; 
     b <= '1'; 
     wait; 
    end process; 

end architecture; 

並使用basculeD更換架構與MUXED_REG過程:

david_koontz @的Macbook:ghdl -a basculeD.vhdl
david_koontz @的Macbook: ghdl -e basculeD_test
david_koontz @Macbook:ghdl -r basculeD_test --wave = basculeD_test.ghw
david_koontz @Macbook:o筆basculeD_test.gtkw(以前保存的保存文件)

給出:

Test bench execution of basculeD_test

當然還有你是從複試圖單獨的存儲完全它說,你可以使用Q1可能性,作爲寄存器(並且僅需要9位)的Q2,獨立的多路複用器(如原始basculeDarchitecture中所暗示的)允許B在經修改的Q1Q2之間引導寄存器值在o輸出data

這將是這個樣子:

architecture Behavioral of basculeD is 
    signal Q1: std_logic_vector(8 downto 0); 
    signal Q2: std_logic_vector(11 downto 3); 
begin 
REGS: 
process (clk, rst) 
begin 
    if rst = '1' then 
     Q1 <= (others => '0'); 
     Q2 <= (others => '0');  
    elsif clk'event and clk = '1' then 
     Q1 <= D1 (8 downto 0); 
     Q2 <= D2(11 downto 3); 
    end if; 
end process; 

MUX: 
process (B,Q1,Q2) 
begin 
    if B = '0' then 
     data <= ("000" & Q1); 
    else 
     data <= (Q2 & "111"); 
    end if; 
end process; 

,給你這樣的事情:

basculeD_test with separate MUX

VHDL是爲了傳達設計規範給讀者,這是比較容易當使用一些約定進行大小寫時(VHDL不區分大小寫,除了擴展標識符)和縮進。

+0

只是一個簡單的提示:在VHDL 2008中,當和選擇語句作爲順序語句添加時。其餘答案是大! – FRob

+0

@FRob - 是的,條件波形和選定的信號分配已添加到-2008年的順序信號分配語句中。請讓我們知道1076-2008得到普遍支持,特別是合成。 – user1155120

+0

Synplify可以做到這一點,Quartus也是如此。賽靈思可能會等到VHDL-2026 tho;) – FRob

0

歡迎來到StackOverflow!首先,這是一個英語問題&答案網站。請將全部全部轉換成英文,即basculeD => D觸發器等。另外,儘量在沒有太多拼寫錯誤(拼寫檢查!)或語法錯誤的情況下儘可能描述您的問題。這將幫助其他人瞭解你並有效地幫助你。

無論如何,你的主要問題是,你有輸入端口D1和D2,你嘗試寫入他們。相反,你應該只需要你需要的任何位,並忽略其他位。

,而不是試圖寫入輸入,這是不可能的,你應該試試這個:

Q2 <= D2(11 downto 3) & "111"; 

此語句從D2採用位11至3,並將其分配給位11至Q2的3。 Q2的位2至0被分配一個常數值「1​​11」。

您應該記住,您不能「重寫」輸入端口值。您的最後一個過程也可以重寫爲並行語句。

此外,您的設計是獨特的,您需要單獨存儲修改後的值。

考慮這個:

D1 = x「00A」; D2 = x「00B」,B ='0',clk->上升沿

現在,Q1 = x「00A」,Q2 = x「???」,data = Q1 = x「00A」, B ='0',clk ='1'

現在,Q1 = x「00A」,Q2 = x「???」,data = Q2 = x「???」,B ='1',當你想在B ='1'和B ='0'之間切換時,你至少需要兩個時鐘週期來切換你的輸出,因爲Q1 resp Q2將保存舊的(可能未初始化的)值。

您的設計可能不會做你想做的事。如果你想要一個多路複用器,去一個多路複用器。如果你想要一個觸發器,建立一個觸發器。

process(clk,rst) 
begin 

    if (rst = '1') then 

     data <= (others => '0'); 

    elsif (clk'event and clk='1') then 

     if (B = '1') then 

      -- Select D2 
      data <= D2(11 downto 3) & "111"; 

     else 

      -- Select D1 
      data <= "000" & D1(8 downto 0); 

     end if; 

    end if; 

end process; 

您可能還想考慮重置是否真的合適以及同步重置是否更有利。

+0

感謝喲下一次我會盡我所能描述我的問題,謝謝你的寶貴幫助 – user3212448