• VHDL之FSM


    1  Intro

      The figure shows the block diagram of a single-phase state machine. The lower section contains sequential logic (flip-flops), while the upper section contains combinational logic.

      The combinational section has two inputs, pr_state (present state) and external input. It has also two outputs, nx_state (next state) and external output. The sequential section has three inputs (clock, reset, and nx_state), and one output (pr_state). Since all flip-flops are in this part of the system, clock and reset must be connected to it.

      If the output of the machine depends not only on the present state but also on the current input, then it is called a Mealy machine. Otherwise, if it depends only on the current state, it is called a Moore machine. Examples of both will be shown later.

      

    2  Design style (recommended)

      1)  Sequential  

    1  process (reset, clock)
    2  begin
    3   if (reset = '1') then
    4     pr_state <= state0;
    5   elsif (clock'event and clock = '1') then
    6     pr_state <= nx_state;
    7  end if;
    8  end process; 

      It consists of an asynchronous reset, which determines the initial state of the system (state0), followed by the synchronous storage of nx_state (at the positive transition of clock), which will produce pr_state at the lower section’s output (figure 8.1).

      One good thing is that the design of the lower section is basically standard. Another advantage is that the number of registers is minimum.

      

      2)  Combinational

      

     1 process (input, pr_state)
     2 begin
     3   case pr_state is
     4     when state0 =>
     5       if (input = ...) then
     6         output <= <value>;
     7         nx_state <= state1;
     8       else ...
     9       end if;
    10     when state1 =>
    11       if (input = ...) then
    12         output <= <value>;
    13         nx_state <= state2;
    14       else ...
    15       end if;
    16     when state2 =>
    17       if (input = ...) then
    18         output <= <value>;
    19         nx_state <= state2;
    20       else ...
    21       end if;
    22     ...
    23   end case;
    24 end process;

      As can be seen, this code is also very simple, and does two things:

       (a) assign the output value

       (b) establish the next state.

    3  VHDL template 

     1 library ieee;
     2 use ieee.std_logic_1164.all;
     3 -----------------------------------------------------
     4 entity <entity_name> is
     5     port( input            : in <data_type>;
     6           reset, clock    : in std_logic;
     7           output        : out <data_type>);
     8 end <entity_name>;
     9 -----------------------------------------------------
    10 architecture <arch_name> of <entity_name> is
    11     type state is (state0, state1, state2, state3, ...);
    12     signal pr_state, nx_state: state;
    13     
    14 begin
    15 ---------- Sequential  ------------------------
    16 process (reset, clock)
    17 begin
    18     if (reset='1') then
    19         pr_state <= state0;
    20     elsif (clock'event and clock='1') then
    21         pr_state <= nx_state;
    22     end if;
    23 end process;
    24 ---------- Combinational ------------------------
    25 process (input, pr_state)
    26 begin
    27     case pr_state is
    28         when state0 =>
    29             if (input = ...) then
    30                 output <= <value>;
    31                 nx_state <= state1;
    32             else ...
    33             end if;
    34         when state1 =>
    35             if (input = ...) then
    36                 output <= <value>;
    37                 nx_state <= state2;
    38             else ...
    39             end if;
    40         when state2 =>
    41             if (input = ...) then
    42                 output <= <value>;
    43                 nx_state <= state3;
    44             else ...
    45             end if;
    46         ...
    47     end case;
    48 end process;
    49 
    50 end <arch_name>;
  • 相关阅读:
    「干货分享」我所在团队的竞品分析模板--附下载
    框架用多了真的会死人的,spring-cloud全家桶与mybitais 集成完整示例(附下载)
    聊聊区块链,虽然我不挖矿!
    从厕所排队引发的产品设计方案思考
    基于spring-boot和docker-java实现对docker容器的动态管理和监控[附完整源码下载]
    Spring-boot原理(附带实现一个spring-boot-starter实例和代码下载)
    Zookeeper+websocket实现对分布式服务器的实时监控(附源码下载)
    「干货分享」模块化编程和maven配置实践一则
    【干货分享】大话团队的GIT分支策略进化史
    项目协作管理平台-teambition和tapd--深度体验
  • 原文地址:https://www.cnblogs.com/mengdie/p/4564341.html
Copyright © 2020-2023  润新知