VHDL Simple 12按钮键盘在模拟中不起作用

时间:2016-11-11 10:52:05

标签: vhdl modelsim

我写了一个非常轻的边缘检测器,它是按钮的接口:

    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;

    entity Button is
        port ( clk :         in STD_LOGIC ;
                 signal_in : in STD_LOGIC;
              output :   out STD_LOGIC);
    end Button;

    architecture EdgeDetector of Button is
        signal signal_d:STD_LOGIC;
        begin

        process(clk)
        begin
            if clk= '1' and clk'event then
                signal_d<=signal_in;
          end if;
        end process;

         output<= (not signal_d) and signal_in; 
    end EdgeDetector;

通过使用modelsim进行测试,似乎存在正确的行为:即使按下按钮的时间较长,输出也只会持续一个时钟周期。

上一个实体是一个更大的实体中使用的组件,它是键盘:它负责输出4位输出以描述按下了哪个按钮。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity Keyboard is
    port ( ck_in :      in STD_LOGIC := '0';
             data_in :  in STD_LOGIC_VECTOR (11 downto 0) := (others=>'-');
             data_out : out STD_LOGIC_VECTOR (3 downto 0));
end Keyboard;

architecture rtl of Keyboard is
    signal NUM : STD_LOGIC_VECTOR (11 downto 0) := (others=>'-');   
begin   

num_0 : entity work.Button port map(ck_in,data_in(0),NUM(0));
num_1 : entity work.Button port map(ck_in,data_in(1),NUM(1));
num_2 : entity work.Button port map(ck_in,data_in(2),NUM(2));
num_3 : entity work.Button port map(ck_in,data_in(3),NUM(3));
num_4 : entity work.Button port map(ck_in,data_in(4),NUM(4));
num_5 : entity work.Button port map(ck_in,data_in(5),NUM(5));
num_6 : entity work.Button port map(ck_in,data_in(6),NUM(6));
num_7 : entity work.Button port map(ck_in,data_in(7),NUM(7));
num_8 : entity work.Button port map(ck_in,data_in(8),NUM(8));
num_9 : entity work.Button port map(ck_in,data_in(9),NUM(9));
num_on : entity work.Button port map(ck_in,data_in(10),NUM(10));
num_off : entity work.Button port map(ck_in,data_in(11),NUM(11));           

with NUM select
    data_out <= "0000" when "000000000001", --0
                   "0001" when "000000000010", --1
                    "0010" when "000000000100", --2
                    "0011" when "000000001000", --3
                    "0100" when "000000010000", --4
                    "0101" when "000000100000", --5
                    "0110" when "000001000000", --6
                    "0111" when "000010000000", --7
                    "1000" when "000100000000", --8
                    "1001" when "001000000000", --9
                    "1010" when "010000000000", --ON
                    "1100" when "100000000000", --OFF
                    "----" when others;
end rtl;

但是当我尝试检查键盘实体的正确行为时,Button似乎以错误的方式工作。事实上,一旦data_in为“000000000001”,NUM就是“00000000000X”(我不知道为什么“X”而不是“1”)并且data_out没有变化。经过一个时钟周期后,保持相同的data_in,NUM变为“000000000000”,当然data_out始终为“----”。

仅在第一个设置时发生这种情况,因为系统中的下一个data_in按预期工作。

所以问题是:为什么在开始按钮时给出正确的data_in会在输出中给出一个位= X的1个实例?

0 个答案:

没有答案