1

几天前,我开始为初学者开设 VHDL 课程。

我有一个代码(下),我试图了解它显示了什么样的电路以及不同的步骤是如何运作的。我已经在互联网上环顾了一段时间,但无法真正理解它的作用?所以我想现在有人可以给我一些解释吗?:.-)

我不确定,但我认为它是一种带缓冲区的“加法器”?并且缓冲区使用 2 位(Cs-1 下降到 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;
4

1 回答 1

9

我用Sigasi HDT重命名了您的实体的输入和输出(并纠正了一些语法错误),这应该使您的实体更加清晰。我做了以下重命名:

k -> clock
ars -> asynchronous_reset
srs -> synchronous_reset
e -> enable
u -> count_up
r-> result

如果启用启用count_up为真,则结果( r ) 将在时钟上升沿递增。如果count_up为假,如果enable在时钟上升沿为真,则结果将递减。

entity asc is
   generic (resultWidth : integer := 8);
   port (clock, asynchronous_reset, synchronous_reset, enable, count_up: in std_logic;
         result: buffer std_logic_vector(resultWidth-1 downto 0)
        );
end asc;

architecture arch of asc is
begin 
  p1: process (asynchronous_reset, clock) begin
     if asynchronous_reset = '1' then
        result <= (others => '0');
     elsif (rising_edge(clock)) then
        if synchronous_reset='1' then
           result <= (others => '0');
        elsif (enable = '1' and count_up = '1') then
           result <= result + 1;
        elsif (enable = '1' and count_up = '0') then
           result <= result - 1;
        else
           result <= result;
        end if;
     end if;
  end process;
end arch;

使用此代码段时要小心:

  • 这种架构似乎正在使用已弃用的库:将 1 添加到 std_logic_vector 是什么意思?请改用签名数据类型。通过这种方式,可以预测如果减零会发生什么。
  • 此实体不会警告您溢出
于 2011-01-14T18:57:16.750 回答