AN05 FSM With State Machine Editor 2
AN05 FSM With State Machine Editor 2
Abstract
This articles introduces the reader to the concepts of finite state machines and their rapid implementation using
Quartus state machine editor.
1 Department of Electronic and Computer Engineering, School of Electrical Engineering, Faculty of Engineering
*Corresponding author: [email protected]
Mealy
Mealy
output
Present outputs
logic
Next state
Inputs State
state
Next Next register
Inputs State Output logic Moore
state state Moore
Next register Present logic Mealy output
logic outputs
state state outputs logic
Clk
Clk
Figure 3. FSM with both Moore and Mealy outputs.
Figure 2. Basic Mealy type state machine.
Finite state machines are modeled by state diagrams
State Register which describe the state changes that happen as inputs are
The state register is simply a few flip-flops which store the received.
present state. The present state is the value of the flip-flop
at any given time while the next state is the value after re-
ceiving a clock edge. A FSM with n flip-flops has 2n differ-
ent states. The number of states is limited or finite, thus
the name finite state machine. For example, an FSM with 2
flip-flops are limited to 4 states because they can only have
4 values: 00, 01, 10 and 11.
Finite State Machines with Quartus State Machine Editor — 2/10
Reset
Reset
D'N'
S0
S0
D'N
N
D'N'
S5 D
S5 D
D'N
N
D'N' D S10
D S10
N+D
N+D
S15
S15 1
[R]
[R]
Figure 6. Enhanced state diagram for vending machine.
Figure 5. The state diagram for vending machine.
You can skip Step 2 and 3. You can always add or delete
states during Step 8.
4. From the toolbar, select the State Machine Wizard 6. In the Inputs tab, click once on the <New> cell.
tool.
Confirm editing of an existing design then click
OK .
Figure 12. Confirm edit of current state machine. 7. In the Outputs tab, click on the <New> cell and add
the output R.
5. In dialog box that appears, choose the General tab.
Make sure the bottom checkbox is checked. This al-
lows you to simplify the state diagram by not showing
arrows pointing back to the source state.
9. The Transitions tab define state-to-state transitions. 11. All information have been entered. Click OK ! We
Enter the transitions to get the table in Figure 18. should get Figure 20.
Figure 19. Actions tab defines state machine outputs. Figure 23. Choose any language you like.
13. After the HDL file is generated, add the file to the 5. Simulation
project.
In order to simulate the design, we will enter the input sim-
ulation waveform.
14. Set the state machine file as the top-level entity. Note:
you can do this step any time after creating a new
state machine file but it must be before compiling the
HDL file.
Figure 30. Set end time to 800 ns. 9. We will be brought back at the
Insert Node or Bus box
as shown in Figure 33, click OK .
7. Click Node Finder.. . A pop-up box will appear as
shown in Figure 32. Figure 34. Waveform after inserting nodes.
11. Click on the clock signal, then the Overwrite Clock 14. Click run functional simulation icon on the toolbar.
tool. Next, set the clock period to 40 ns. If the simulation is successful, a new window will ap-
pear showing the result of simulated waveforms.
6. Mealy-type Vending Machine 4. In the States tab, enter the following states.
The Mealy type vending machines solves the same task us-
ing only three states (Figure 39). This section of the appli-
cation note only points the differences. Unless otherwise
mentioned, use the same settings as the Moore machine.
Reset
S0
D'N
S10
3. In the Outputs tab, enter the R as output. Make sure 6. In the Actions tab, enter the following states.
the output is registered.
Figure 40. Mealy output must be registered. Figure 43. Mealy actions.
7. Clicking OK aftering entering all the information References
above gives the following state diagram.
[1] Randy H. Katz and Gaetano Borriello. Contemporary
Logic Design. 2nd ed. Pearson, 2004.
[2] Designing State Machines for FPGAs. Application Note
130. Actel Corporation. Sept. 1997. URL: https://www.
microsemi.com/document-portal/doc_view/130043-
state-machine-an.
11. Compile.
Moore vs Mealy
This summary assumes the reader knows the difference
between Mealy and Moore outputs.
Moore outputs are locked to the state. When asserted,
Moore outputs are high as long as the FSM is in the partic-
ular state regardless of input changes. In Actions tab of the
State Machine Wizard, enter 1 in the Output Value column.
Refer Figure 19.
Mealy outputs asserted when certain conditions are met
in a state. In Actions tab of the State Machine Wizard, en-
ter the required Boolean expression in the Output Value
column. Refer Figure 43.
Mealy outputs are glitchy. To make the outputs easier to
analyze, set Mealy outputs as Registered in the Outputs tab
in the State Machine Wizard. If you do not set it as registered,
you must understand the effects of propagation delay, setup
time and hold time of flip-flops to predict when the outputs
are valid.