开发者

VHDL explanation in words

开发者 https://www.devze.com 2023-02-04 01:39 出处:网络
I started with VHDL course for beginners a few days ago. I’ve got a code (under) and I’m trying to understand what kind of circuit it shows and how the different steps are functioning.

I started with VHDL course for beginners a few days ago.

I’ve got a code (under) and I’m trying to understand what kind of circuit it shows and how the different steps are functioning. I’ve been looking around fore a while now in the Internet but can’t really understand what it does? So I thought someone who now this might give me some explanations’? :.-)

I`m not sure but I think it is a type of an “adder” with a buffer? And the buffer is working with 2 bits (Cs-1 downto 0) however I don’t know what Cs means….in fact there is a lot of things in this code I don’t un开发者_JAVA技巧derstand.

I would really appreciate if some one would take some time to help me understand the code in words.

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;


I renamed the inputs and outputs of your entity with Sigasi HDT (and corrected some syntax errors) which should make a lot more clear your entity does. I did following renames:

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

If enable is asserted and count_up is true, the result (r) will be incremented on a rising clock edge. If count_up is false, the result will be decremented if enable is true on a rising clock edge.

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;

Be careful when using this code snippet:

  • This architecture seems to be using deprecated libraries: what does adding 1 to a std_logic_vector mean? Please use the signed datatype instead. This way it is predictable what will happen if you decrement zero.
  • This entity will not warn you for overflow
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号