【问题标题】:start from a specific stat in the FSM从 FSM 中的特定统计数据开始
【发布时间】:2018-12-31 18:36:56
【问题描述】:

我有一个可以正常工作的特定 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;

【问题讨论】:

  • 可怕的格式,我不会修复它。只需在重置期间分配不同的状态 if (rst = '1') then current_state ;否则...
  • @damage 不能解决我的问题!!,你认为这将如何使它从特定状态开始!!
  • 如果您想从 SO 社区获得快速且良好的解决方案,您应该使用得到的代码格式(例如缩进)。如果没有做好充分的准备,没有人会花几分钟来理解你的代码。接下来,您应该阅读状态机模式。

标签: vhdl state modelsim fsm quartus


【解决方案1】:

如果未提供初始值,则默认情况下使用该信号子类型范围的最左侧值初始化信号。在您的情况下,类型是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 决策树。
  • 您的进程的敏感度列表不完整。
  • 不要使用异步重置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    相关资源
    最近更新 更多