【发布时间】:2018-09-24 11:39:54
【问题描述】:
我创建了以下具有比较匹配功能的计数器:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
entity Counter is
generic (
N : natural := 24
);
port (
-- Input counter clock
clk : in std_logic := '0';
-- Enable the counter
enable : in std_logic := '0';
-- Preload value loaded when clk is rising and load is 1
load_value : in std_logic_vector((N-1) downto 0) := (others => '0');
-- Set to 1 to load a value
load : in std_logic := '0';
-- Compare match input is compared with the counter value
compare_match_value : in std_logic_vector((N-1) downto 0) := (others => '0');
-- Is 1 when compare_match_value = counter_value
compare_match : out std_logic := '0';
output_value : out std_logic_vector((N-1) downto 0) := (others => '0')
);
end Counter;
architecture Behavioral of Counter is
signal counter_value : unsigned((N - 1) downto 0) := to_unsigned(0, N);
begin
output_value <= std_logic_vector(counter_value);
process (clk) is
begin
if rising_edge(clk) then
if enable = '1' then
if load = '1' then
counter_value <= unsigned(load_value);
else
counter_value <= counter_value + 1;
end if;
else
if load = '1' then
counter_value <= unsigned(load_value);
end if;
end if;
end if;
end process;
process (counter_value) is
begin
if unsigned(compare_match_value) = counter_value then
compare_match <= '1';
else
compare_match <= '0';
end if;
end process;
end Behavioral;
我的计数器的行为是与输入 clk 信号完全同步。始终可以禁用计数器,并将值保持在当前计数值。可以使用 load 和 load_value 信号来分配负载值。每当负载信号为高且检测到上升沿时,计数器值都会更新为 load_value。
另一个特点是比较单元在 compare_match 输出时输出高电平。模拟按预期工作,但在 spartan 3 fpga 上综合此设计时我有几个问题。
- 这是否被认为是我的计数器的好设计,因为我在 VHDL 方面仍然没有太多经验。
- 在我的设计中在进一步的逻辑中使用比较单元时是否有任何未定义的状态?正如我所见,只要 counter_value 更新,就会计算 compare_match。
- 当对 N 使用较大的数字时,我需要考虑的延迟有什么特别之处吗?
【问题讨论】: