我在vhdl中有一个向量temp,如果向量达到最大count_limit,我希望向量等于零。向量的大小是通用的..我该怎么做?
GENERIC ( SIZE : INTEGER := 8);
constant count_limit : std_logic_vector(SIZE - 1 downto 0) := ( others => '1'); -- max value
signal temp: std_logic_vector(SIZE - 1 downto 0);
-- here i want to check if temp was equal to the max vaue then i want temp to be zero
-- here is what i did but thats not correct !
temp <= ( others => '0');
答案 0 :(得分:0)
在我看来,您想要做的是这样:
--inside declaration part of the architecture
signal temp : unsigned(SIZE-1 downto 0);
constant count_limit : unsigned(SIZE - 1 downto 0) := ( others => '1');
--in the body
clocked_count: process(clk) begin
if rising_edge(clk) then
if temp < count_limit then
temp <= temp +1;
else temp <= (others => '0');
end if;
end if;
end
以上过程将在每个时钟周期增加temp的值,只要它保存(最后)的值小于count_limit。当达到count_limit时,temp被清零。仅当您将信号声明为无符号时,比较才起作用,因为这样就不会对位向量表示什么有任何歧义。