2位计数器,带复位-不变输出问题

时间:2018-10-28 16:02:11

标签: vhdl simulation fpga

这是我要回答的问题。

  

设计并模拟一个2位计数器,该计数器在复位后计数为“ 00”,   与时钟上升同步“ 01”,“ 10”,“ 11”,“ 00”,“ 01 ...”   边缘。

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

这是我的代码:

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;

1 个答案:

答案 0 :(得分:1)

问题是由于您在所有情况下都分配了temp <= unsigned(a) + 1,并且由于a在信号00下是恒定的,因此您仅输出01,而仅丢弃{{ 1}},然后将a和temp初始化为temp <= unsigned(temp) + 1

作为一个改进点,如mkrieger1所建议,最好将00定义为temp,因为您希望对其应用unsigned。同样,您还需要在将+的值重新分配回temp时再次将z转换回std逻辑向量,或者也使z unsigned。 / p>

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