使用端口映射去抖动在VHDL中设计FSM

时间:2016-03-07 16:06:46

标签: process vhdl clock fsm

我用VHDL制作了FSM,现在我想使用带有端口映射的去抖代码。 虽然我对协会有困难。实际上,我想在驱动FSM的信号中插入debouncebutton分量。

entity myFSM is
    Port ( CLK : in  STD_LOGIC;
           RST : in  STD_LOGIC;
           IN0 : in  STD_LOGIC;
           IN1 : in  STD_LOGIC;
           IN2 : in  STD_LOGIC;
           LED : out  STD_LOGIC_VECTOR (7 downto 0));
end myFSM;

architecture Behavioral of myFSM is
        type state is (A, B, C);
        signal currentS, nextS: state;

        component debouncebutton
            Port ( clk      : in std_logic;     -- connect it to the Clock of the board
           rst      : in std_logic;     -- connect it to the Reset Button of the board          
           input    : in std_logic;     -- connect it to the Push Button of the board
           output   : out std_logic     -- connect it to your circuit
          );
        end component;
begin
myFSM_comb: process (currentS, IN0, IN1, IN2)
begin
    case currentS is
        when A =>   LED <= "11111111";
                        if IN0 = '1' then nextS<=B;
                        elsif IN1 = '1' then nextS<=C;
                        else            nextS<=A;
                        end if;
        when B =>   LED <= "11000011";
                        if IN0 = '1' then nextS<=C;
                        elsif IN1 = '1' then nextS<=A;
                        else nextS<=B;
                        end if;
        when C =>   LED <= "00111100";
                        if IN0 = '1' then nextS<=A;
                        elsif IN1 = '1' then nextS<=B;
                        else nextS<=C;
                        end if;
    end case;
end process;

myFSM_synch: process(CLK,RST)
begin 
    if (RST='1')        then    currentS<=A;
    elsif (rising_edge(CLK)) then currentS<= nextS;
    end if;
end process ;

begin 

db0 : debounce
port map
(
    clk => CLK,
    rst => RST,
    input => IN0,
    output
end Behavioral;

1 个答案:

答案 0 :(得分:2)

我通过在端口声明中将IN0重命名为INP0来标记您的代码,在体系结构中声明了一个名为INO的信号,以防止更改每次出现的名称,删除无关的begin并重命名实例化从debouncedebouncebutton的组件以匹配组件声明:

library ieee;
use ieee.std_logic_1164.all;

entity myFSM is
    Port ( CLK : in  STD_LOGIC;
           RST : in  STD_LOGIC;
           INP0 : in  STD_LOGIC;  -- name changed
           IN1 : in  STD_LOGIC;
           IN2 : in  STD_LOGIC;
           LED : out  STD_LOGIC_VECTOR (7 downto 0));
end myFSM;

architecture Behavioral of myFSM is
        type state is (A, B, C);
        signal currentS, nextS: state;

        component debouncebutton
            Port ( clk      : in std_logic;     -- connect it to the Clock of the board
           rst      : in std_logic;     -- connect it to the Reset Button of the board          
           input    : in std_logic;     -- connect it to the Push Button of the board
           output   : out std_logic     -- connect it to your circuit
          );
        end component;

        signal IN0: std_logic;  --- added
begin
myFSM_comb: process (currentS, IN0, IN1, IN2)
begin
    case currentS is
        when A =>   LED <= "11111111";
                        if IN0 = '1' then nextS<=B;
                        elsif IN1 = '1' then nextS<=C;
                        else            nextS<=A;
                        end if;
        when B =>   LED <= "11000011";
                        if IN0 = '1' then nextS<=C;
                        elsif IN1 = '1' then nextS<=A;
                        else nextS<=B;
                        end if;
        when C =>   LED <= "00111100";
                        if IN0 = '1' then nextS<=A;
                        elsif IN1 = '1' then nextS<=B;
                        else nextS<=C;
                        end if;
    end case;
end process;

myFSM_synch: process(CLK,RST)
begin 
    if (RST='1')        then    currentS<=A;
    elsif (rising_edge(CLK)) then currentS<= nextS;
    end if;
end process ;

-- begin  -- syntax error you have a begin before process myFSB_comb

db0 : debouncebutton  --- was debounce, needs to match component declaration
port map (
        clk => CLK,
        rst => RST,
        input => INP0,  -- renamed input port
        output=> IN0   --  newly declared signal INO
    );

end Behavioral;

这允许新输入端口INP0input上的正式debouncebutton关联,并将正式output连接到新声明的信号IN0。< / p>

您还可以轻松地为output关联声明一个新信号,并更改名称IN0的实例,而不是myFSM的端口声明。

您修改后的代码分析。如果不为debouncebutton创建实体/体系结构对,则无法对其进行详细说明(或模拟)。