2015-05-28 47 views
1

對矢量中的每個位執行端口映射的最佳方式是什麼?假設我有一個代表一系列按鈕的向量,並且希望使用一個跳動模塊來消除每個按鈕,我應該怎麼做?矢量中每個位的VHDL映射

現在我有以下的,但我相信應該有更好的方式

entity ButtonDebouncer is 
    Port (
     clock : in std_logic; 
     buttons : in std_logic_vector(0 to 5); 
     --{ more stuff } 
    ); 
end ButtonDebouncer; 

architecture Behavioral of ButtonDebouncer is 
    signal bufferedButtons : std_logic_vector(0 to 5) := (others => '0'); 
begin 
    c1: entity debounce port map (Clock, buttons(0), bufferedButtons(0)); 
    c2: entity debounce port map (Clock, buttons(1), bufferedButtons(1)); 
    c3: entity debounce port map (Clock, buttons(2), bufferedButtons(2)); 
    c4: entity debounce port map (Clock, buttons(3), bufferedButtons(3)); 
    c5: entity debounce port map (Clock, buttons(4), bufferedButtons(4)); 
    c6: entity debounce port map (Clock, buttons(5), bufferedButtons(5)); 

    --{ Do stuff with debounced buttons } 
end Behavioral; 

回答

2

對於產生將是一個不錯的人選建設在這裏。

entity ButtonDebouncer is 
    Port (
     clock : in std_logic; 
     buttons : in std_logic_vector(0 to 5); 
     --{ more stuff } 
    ); 
end ButtonDebouncer; 

architecture Behavioral of ButtonDebouncer is 
    signal bufferedButtons : std_logic_vector(0 to 5) := (others => '0'); 
begin 
    debouncers: for i in 0 to 5 generate 
     c1: entity debounce port map (Clock, buttons(i), bufferedButtons(i)); 
    end generate; 
    --{ Do stuff with debounced buttons } 
end Behavioral; 
+2

你甚至可以用'buttons'range'更換'0〜5'架構,避免了神奇的硬編碼值,使意圖明顯。 –

+0

太棒了,我不知道'生成' – Jableader

0

特拉維斯的解決方案是一個很好的起點。

我會更進一步,實現一個debounce模塊多位。所以你可以傳遞一個完整的按鈕矢量到這個模塊。

entity debounce is 
    generic (
    BITS : POSITIVE 
); 
    port (
    Clock : STD_LOGIC; 
    Input : STD_LOGIC_VECTOR(BITS - 1 downto 0); 
    Output : STD_LOGIC_VECTOR(BITS - 1 downto 0) 
) 
end entity; 

architecture rtl of debounce is 
    -- define 'global' signals here (per instance) 
begin 
    genDebounce : for i in 0 to BITS - 1 generate 
    -- define 'local' signals here (per debounce circuit) 
    begin 
    -- debounce circuit 
    end generate; 
end architecture; 

用法:

debButtons : entity work.debounce 
    generic map (
    BITS => buttons'length 
) 
    port map (
    Clock => Clock, 
    Input => Buttons, 
    Output => bufferedButtons 
);