从FSM中的特定统计信息开始

时间:2018-12-31 18:36:57

标签: vhdl state modelsim fsm quartus

我有一个运行良好的特定FSM。但我想从FSM中的特定状态开始,我想知道是否可以使用仅在电路中发生一次的事件来做到这一点,但我却无法做到,因为我想到的所有事件都会使电路保持在相同状态

library ieee;
use ieee.std_logic_1164.all;
use work.all;

entity ELEVAR is
port(
clk, rst: in std_logic;
NF,status : in std_logic_vector(2 downto 0);
output: out std_logic_vector(2 downto 0));
end ELEVAR;

architecture struct of ELEVAR is
type state is(S,S0,S1,S2,S3,S4,S5,S6,S7,S8,HI);
signal current_state, next_state:state; 
signal output22 : std_logic_vector(2 downto 0);

begin 
    process(clk, rst)
    begin
            if(rst='1')then
                current_state<=S0;

            elsif(rising_edge(clk))then


            else
                    null;
            end if;

    end process;




    process(current_state)

    begin

            case current_state is

                when S8=>next_state<=S7;
                            output<="111";

 output22<="111";
    if (NF=output22) then
    next_state<=HI;
    output<="111";
    end if;

                when S7=>next_state<=S6;
                            output<="110";

 output22<="110";
    if (NF=output22) then
    next_state<=HI;
    output<="110";
    end if;
                when S6=>next_state<=S5;
                            output<="101";

 output22<="101";
    if (NF=output22) then
    next_state<=HI;
    output<="101";

    end if;
                when S5=>next_state<=S4;
                            output<="100";

 output22<="100";
    if (NF=output22) then
    next_state<=HI;
                output<="100";
    end if;
                when S4=>next_state<=S3;
                            output<="011";

 output22<="011";
    if (NF=output22) then
    next_state<=HI;
    output<="011";
    end if;
                when S3=>next_state<=S2;
                            output<="010";

 output22<="010";
    if (NF=output22) then
    next_state<=HI;
        output<="010";
    end if;
                when S2=>next_state<=S1;
                            output<="001";

 output22<="001";
    if (NF=output22) then
    next_state<=HI;
            output<="001";
    end if;
                when S1=>next_state<=S0;
                            output<="000";

 output22<="000";
    if (NF=output22) then
    next_state<=HI;
        output<="000";
    end if;

                 when others => next_state<=HI;
                            null;


            end case;
    end process;

  end struct;

-此代码选择我要从中开始的状态,但我不知道  ---我应该将它放在我的代码中。

   current_state<=next_state;
                elsif status = "000" then 
                current_state<=S0;
                elsif 
                status = "001" then 
                current_state<=S1;
                elsif 
                status = "010" then 
                current_state<=S2;
                elsif 
                status = "011" then 
                current_state<=S3;
                elsif 
                status = "100" then 
                current_state<=S4;
                elsif 
                status = "101" then 
                current_state<=S5;
               elsif 
                status = "110" then 
                current_state<=S6;
                elsif 
                status = "111" then 
                current_state<=S7;

1 个答案:

答案 0 :(得分:0)

如果没有提供初始值,默认情况下,

信号会使用该信号子类型范围的最左值进行初始化。在您的情况下,类型为State,最左边的值为S。因此,您的初始状态为S

您可以在声明信号时为分配一个初始值:

signal current_state : State := S4;
signal next_state    : State;

现在,初始值为S4,开始状态也为S4

请注意,FSM可以具有不同的启动和重置状态。 (并不是说它总是很聪明。)如果复位状态可以不同于初始状态,则取决于底层技术(FPGA,Xilinx,Altera,ASIC等)。


其他提示:

  • 请勿枚举S1,S2之类的标识符!
    使用正确的状态名称。
  • 如果您需要检查status中是否有多个不同的值,请使用case语句,但不要使用if / elsif决策树。
  • 您处理的敏感度列表不完整。
  • 请勿使用异步重置。