2017-04-17 57 views
1

當所有輸入爲xclk = 1時,它應該輸出Qpl的值,但它不會。下面的代碼有什麼問題;VHDL設計意外的結果

LIBRARY IEEE; 
USE IEEE.STD_LOGIC_1164.ALL; 
--This is a D Flip-Flop with Synchronous Reset,Set and Clock Enable(posedge clk). 
--Note that the reset input has the highest priority,Set being the next highest 
--priority and clock enable having the lowest priority. 
ENTITY syn IS 
    PORT (
     Q : OUT std_logic; -- Data output 
     CLK : IN std_logic; -- Clock input 
     Qpl : IN std_logic; 
     RESET : IN std_logic; -- Synchronous reset input 
     D : IN std_logic; -- Data input 
     SET : IN std_logic -- Synchronous set input 
    ); 
END syn; 
ARCHITECTURE Behavioral OF syn IS --architecture of the circuit. 
BEGIN 
    --"begin" statement for architecture. 
    PROCESS (CLK) --process with sensitivity list. 
    BEGIN 
     --"begin" statment for the process. 
     IF (CLK'EVENT AND CLK = '1') THEN --This makes the process synchronous(with clock) 
      IF (RESET = '1') THEN 
       Q <= '0'; 
      ELSE 
       IF (SET = '1') THEN 
        Q <= D; 
       ELSE 
        Q <= Qpl; 
       END IF; 
      END IF; 
     END IF; 
    END PROCESS; --end of process statement. 
END Behavioral; 

下圖顯示了上述設計的波形和所需的操作要求; waveform

+0

請注意'SET'不適用於應用'D'。像「復位」將寄存器設置爲「0」,「設置」通常將寄存器設置爲「1」。通常的名稱是「加載」或「啓用」。我認爲「負載」是最好的選擇。 – JHBonarius

回答

1

從波形圖,似乎一切正常正常的,當輸入信號變爲SETU,if條件不能評價,因此輸出Q也變爲這樣,即U。您可以看到SET0,輸出Q正確得到Qpl的值。

enter image description here

對不起,粗拉,但你可以在圓圈時鐘的上升邊看邊SET0Q得到預期的Qpl值。 SET信號變爲U只有後,輸出Q也失去了在下一個時鐘上升時它的價值,也成爲U

+0

所以我的代碼也是正確的問題嗎?(在波形圖像之上) –

+0

除了'Qpl'部分,你沒有設置它,並且邏輯有錯誤。它不應該是一個輸入信號,而應該是一個本地存儲的值 - >你應該有一個變量'Qtemp',並且在你保留該值的同時保持'Q'的值,檢查[this](http:/ /stackoverflow.com/a/14593941/3641067) –

+0

大概這將會是很多要問,但我不知道如何實現這些東西到我的code.I真的是新的這種代碼語言我不知道該怎麼做甚至與你的幫助 –

1

你的代碼和註釋不同。正如表格/圖表一樣。一個D觸發器/寄存器是一個非常簡單的組件。例如:

entity dff is 
    port (
     clk : in std_logic; 
     rst : in std_logic; 
     set : in std_logic; 
     load : in std_logic; 
     d : in std_logic; 
     q : out std_logic 
    ); 

architecture rtl of dff is 
begin 
    dff_proc : process(clk) 
    begin 
     if rising_edge(clk) then 
      if rst='1' then 
       q <= '0'; 
      elsif set='1' then 
       q <= '1'; 
      elsif load='1' then 
       q <= d; 
      end if; 
     end if; 
    end process; 
end architecture;