2017-10-08 100 views
0

我剛開始學習vhdl代碼,並且我編寫了一個D型異步觸發器的代碼。我應該如何修改我的代碼,使其具有第二個D型輸入,第二個輸入是從第一個輸出輸入的。VHDL,D型異步觸發器

library ieee; 
use ieee.std_logic_1164.all; 

entity FLIPFLOP is 
port ( 
    clk : in std_logic ; 
    clr : in std_logic ; 
    D : in std_logic ; 
    Q : out std_logic 
); 
end FLIPFLOP; 

architecture behav of FLIPFLOP is 
begin 
process (clk,clr,D) 
begin 
if clr = '1' then 
Q<= '0'; 
elsif rising_edge (clk) then 
Q<= D; 
end if; 
end process; 
end behav; 
+1

在過程敏感性列表中不需要D.參見[VHDL D型異步觸發器](https://electronics.stackexchange.com/questions/333403/vhdl-d-type-asynch-flip-flop)。它被稱爲移位寄存器。參見[VHDL中移位寄存器的結構設計](https://stackoverflow.com/questions/37082327/structural-design-of-shift-register-in-vhdl)和[用VHDL設計移位寄存器](https:/例如,/stackoverflow.com/questions/29840819/design-a-shift-register-in-vhdl)。 – user1155120

+1

'process(clk,clr)variable reg:std_logic_vector(1 downto 0); begin if clk ='1'then reg:=「00」; elsif rising_edge(clk)then reg:= D&reg(1);萬一; Q <= reg(0);末端過程; 「如果這不是你想要的,它表明你的問題不清楚,它符合你的所有標準。兩個觸發器分別是reg(1)和reg(0)。變量reg也可能是一個信號,要求在另一個進程中進行Q分配(例如在併發信號分配中詳細描述爲進程聲明)。 – user1155120

回答

0

我認爲你需要寫它使用您DFF架構的頂層VHDL文件:

entity top is 
port (
    clk: in std_logic; 
    clr: in std_logic; 
    some_input_signal: in std_logic; 
    some_output_signal: out std_logic 
); 
end top; 

architecture rtl of top is 
    signal x: std_logic; 
begin 
    e1: entity work.FLIPFLOP 
    port map (
    clk => clk, 
    clr => clr, 
    D => some_input_signal, 
    Q => x); 

    e2: entity work.FLIPFLOP 
    port map (
    clk => clk, 
    clr => clr, 
    D => x, 
    Q => some_output_signal); 
end; 

X是由第一DFF outputed和inputed到第二DFF的信號。