带复位功能的 2 位计数器 - 不变的输出问题

2-bit counter with reset - non-changing output issue

这是我要回答的问题。

Design and simulate a 2-bit counter which after a reset counts “00”, “01”,“10”, “11”, “00”, “01 ...” synchronously to the clock rising edges.

我的代码将 z 输出递增一次,然后当我在 Vivado 2017.2 中模拟它时停止在 01!我的代码有什么问题?我需要测试台吗?如果是这样,我怎么知道我需要一个测试平台来模拟代码?

这是我的代码:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;

entity twoc is
Port (reset : in std_logic;
ck : in std_logic;
 z : out std_logic_vector(1 downto 0));
end twoc;

architecture Behavioral of twoc is
signal a : std_logic_vector(1 downto 0):= "00";
signal temp : std_logic_vector(1 downto 0);
begin 
process(ck)

begin
if ck='1' and ck'event then
    if reset ='1' then
    temp<="00";
    else
    temp <=std_logic_vector(unsigned(a)+1);
    end if;
end if;
end process;
z <= temp;
end Behavioral;

问题是由于您对所有情况都分配了 temp <= unsigned(a) + 1,并且由于 a 对于信号 00 是常量,您只输出 01,只需删除a 并使用 temp <= unsigned(temp) + 1 并将温度初始化为 00.

作为一个改进点,正如 mkrieger1 所建议的那样,最好将 temp 定义为 unsigned,因为您希望在其上应用 +。此外,在将 temp 的值重新分配给 z 时,您还需要将 temp 再次转换回标准逻辑向量,或者同时使 z unsigned

signal temp : unsigned(1 downto 0) := "00";