几天前我开始为初学者开设VHDL课程 .
我有一个代码(下),我试图了解它显示的电路类型以及不同步骤的运行方式 . 我现在已经在互联网上看了一段时间,但不能真正理解它的作用?所以我认为现在有人可能会给我一些解释吗? :.-)
我不确定,但我认为它是一种带有缓冲区的“加法器”?缓冲区正在使用2位(Cs-1 downto 0)但是我不知道Cs的含义......实际上这段代码中有很多东西我不明白 .
如果有人花些时间帮助我理解单词中的代码,我将非常感激 .
entity asc is
generic (CS : integer := 8)
port (k, ars, srs, e, u: in std_logic;
r: buffer std_logic_vector(Cs-1 downto 0));
end asc;
architecture arch of asc is
begin
p1: process (ars, k) begin
if ars = ‘1’ then
r <= (others => ‘0’);
elsif (k’event and k=’1’) then
if srs=’1’ then
r <= (others) => ‘0’);
elsif (e = ‘1’ and u = ‘1’) then
r <= r + 1;
elsif (e = ‘1’ and u = ‘0’) then
r <= r - 1;
else
r <= r;
end if;
end if;
end process;
end arch;
1 回答
我用Sigasi HDT重命名了你的实体的输入和输出(并纠正了一些语法错误),这应该会使你的实体更加清晰 . 我做了以下重命名:
如果置位且 count_up 为真,则 result ( r )将在时钟上升沿递增 . 如果 count_up 为假,则在时钟上升沿 enable 为真时结果将递减 .
使用此代码段时要小心:
这个体系结构似乎使用了不推荐使用的库:在std_logic_vector中添加1意味着什么?请改用signed数据类型 . 通过这种方式可以预测,如果减少零会发生什么 .
此实体不会警告您溢出