FSM_FF: process (CLK, RESET) begin if RESET = ’1’ then STATE <= START; elsif CLK’event and CLK = ’1’ then case STATE is when START => if X = GO_MID then STATE <= MIDDLE; end if; when MIDDLE => if X = GO_STOP then STATE <= STOP; end if; when STOP => if X = GO_START then STATE <= START; end if; when others => STATE <= START; end case; end if; end process FSM_FF;
Three different notations of a simple state machine are shown in the picture.
The graphic on the top depicts the automaton as an abstract block diagram which contains only the relevant blocks and signals of interest.
The first block (oval) represents the logic of the automaton and the second block (rectangle) the storing elements. In the bottom graphic, the automaton is described by a so called bubble diagram.
The circles mark the different states of the automaton. If the condition connected to the corresponding transition (arrow) evaluates to ’true’ at the time the active clock edge occurs, the automaton will change its state. This is a synchronous behavior.
Here the asynchronous reset is the only exception to this behavior. At the time the reset signal gets active, the automat changes to the reset state START immediately.
In the VHDL source code the automaton is described in one clocked process. The first IF branch contains the reset sequence. In the second branch, the ELSE branch, the rest of the automaton is described. In the CASE statement which models the state transitions, the current state of the automaton is detected and it is examined whether input values are present that lead to a change of the state.
FSM_FF: process (CLK, RESET) begin if RESET = ’1’ then STATE <= START; elsif CLK = ’1’ and CLK’event then STATE <= NEXT_STATE; end if; end process FSM_FF; FSM_LOGIC: process (STATE, X) begin NEXT_STATE <= STATE; case STATE is when START => if X=GO_MID then NEXT_STATE <= MIDDLE; end if; when MIDDLE => ... when others => NEXT_STATE <= START; end case; end process FSM_LOGIC;
Now, the same automaton is used to show an implementation based on two VHDL processes.
The signal NEXT_STATE is examined explicitly this time.
It is inserted in the block diagram between the logic and the storing elements. In the bubble diagram no changes have to be made at this point, as the behavior remains the same.
The VHDL source code contains two processes.
The logic for the NEXT_STATE calculation is described in a separate process.
The result is a clocked process describing the storing elements and another purely combinational process describing the logic.
In the CASE statement, again, the current state is checked and the input values are examined. If the state has to change, then NEXT_STATE and STATE will differ. With the next occurrence of the active clock edge, this new state will be taken over as the current state.
Two State Processes error easier to detect | One State Process error difficult to detect in a big FSM or big waveform |
Automaton descriptions with either one or two separated processes were shown previously. Depending on the own liking and experiences, either one of the two versions is preferred by desingers. Generally there are different advantages and disadvantages: