如何修改VHDL计数器代码并将向量正确转换为整数?
How to modify VHDL counter code and convert vector to integer correctly?
我们应该修改 VHDL 中的代码,为我们从学校获得的计数器修改一两行,以在从 A 到 B 的范围内计数。这就是我们目前所做的。
entity counter is
generic (
B : integer := 4;
A : integer := 0
);
port (
CLK : IN std_logic;
RST : IN std_logic;
Q : OUT std_logic_vector(log2(N)-1 downto 0)
);
end cntn;
architecture run01 of counter is
signal a0 : std_logic_vector(Q'range) := (others => '0');
begin
Q <= a0;
citac: process (RST, CLK)
begin
if RST='1' then
a0 <= (others => std_logic_vector(conv_integer(A, cnt'length)));
elsif rising_edge(CLK) then
a0 <= a0 + 1;
if a0 = A then
a0 <= (others => '0');
end if;
end if;
end process;
end architecture;
到目前为止我们已经添加了这段代码
a0 <= (others => std_logic_vector(conv_integer(A, cnt'length)));
但是转换似乎有问题。有没有人知道如何解决这个问题?我是 VHDL 的新手,所以我在这方面遇到了一些困难。
使用ieee.numeric_std.all
包。然后写
a0 <= std_logic_vector(to_unsigned(A,a0'length));
我们应该修改 VHDL 中的代码,为我们从学校获得的计数器修改一两行,以在从 A 到 B 的范围内计数。这就是我们目前所做的。
entity counter is
generic (
B : integer := 4;
A : integer := 0
);
port (
CLK : IN std_logic;
RST : IN std_logic;
Q : OUT std_logic_vector(log2(N)-1 downto 0)
);
end cntn;
architecture run01 of counter is
signal a0 : std_logic_vector(Q'range) := (others => '0');
begin
Q <= a0;
citac: process (RST, CLK)
begin
if RST='1' then
a0 <= (others => std_logic_vector(conv_integer(A, cnt'length)));
elsif rising_edge(CLK) then
a0 <= a0 + 1;
if a0 = A then
a0 <= (others => '0');
end if;
end if;
end process;
end architecture;
到目前为止我们已经添加了这段代码
a0 <= (others => std_logic_vector(conv_integer(A, cnt'length)));
但是转换似乎有问题。有没有人知道如何解决这个问题?我是 VHDL 的新手,所以我在这方面遇到了一些困难。
使用ieee.numeric_std.all
包。然后写
a0 <= std_logic_vector(to_unsigned(A,a0'length));