Loops 向量中每个位的VHDL映射
为向量中的每一位执行端口映射的最佳方法是什么?假设我有一个表示一系列按钮的向量,并希望使用bebounce模块对每个按钮进行去抖动,我应该如何进行呢 现在我有以下几点,但我相信应该有更好的方法Loops 向量中每个位的VHDL映射,loops,dictionary,entity,port,vhdl,Loops,Dictionary,Entity,Port,Vhdl,为向量中的每一位执行端口映射的最佳方法是什么?假设我有一个表示一系列按钮的向量,并希望使用bebounce模块对每个按钮进行去抖动,我应该如何进行呢 现在我有以下几点,但我相信应该有更好的方法 entity ButtonDebouncer is Port ( clock : in std_logic; buttons : in std_logic_vector(0 to 5); --{ more stuff } ); end But
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;
因为generate是一个很好的候选构造
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;
特拉维斯的解决方案是一个很好的起点 我将更进一步,为多个位实现一个
去盎司
模块。所以你可以把一个完整的按钮向量传递给这个模块
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
);
你甚至可以用
按钮的范围
替换体系结构中的0到5
,以避免神奇的硬编码值,并明确意图。太棒了,我不知道“生成”