This notebook will show how to use the Finite State Machine (FSM) Generator to generate a state machine. The FSM we will build is a Gray code counter. The counter has three state bits and can count up or down through eight states. The counter outputs are Gray coded, meaning that there is only a single-bit transition between the output vector of any state and its next states.
In [1]:
from pynq.overlays.logictools import LogicToolsOverlay
logictools_olay = LogicToolsOverlay('logictools.bit')
In [2]:
fsm_spec = {'inputs': [('reset','D0'), ('direction','D1')],
'outputs': [('bit2','D3'), ('bit1','D4'), ('bit0','D5')],
'states': ['S0', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7'],
'transitions': [['01', 'S0', 'S1', '000'],
['00', 'S0', 'S7', '000'],
['01', 'S1', 'S2', '001'],
['00', 'S1', 'S0', '001'],
['01', 'S2', 'S3', '011'],
['00', 'S2', 'S1', '011'],
['01', 'S3', 'S4', '010'],
['00', 'S3', 'S2', '010'],
['01', 'S4', 'S5', '110'],
['00', 'S4', 'S3', '110'],
['01', 'S5', 'S6', '111'],
['00', 'S5', 'S4', '111'],
['01', 'S6', 'S7', '101'],
['00', 'S6', 'S5', '101'],
['01', 'S7', 'S0', '100'],
['00', 'S7', 'S6', '100'],
['1-', '*', 'S0', '']]}
Notes on the FSM specification format
In [3]:
fsm_generator = logictools_olay.fsm_generator
Setup to use trace analyzer
In this notebook trace analyzer is used to check if the inputs and outputs of the FSM.
Users can choose whether to use the trace analyzer by calling the trace()
method.
In [4]:
fsm_generator.trace()
In [5]:
fsm_generator.setup(fsm_spec)
Display the FSM state diagram
This method should only be called after the generator has been properly set up.
In [6]:
fsm_generator.show_state_diagram()
Set up the FSM inputs on the PYNQ board
Notes:
In [7]:
fsm_generator.run()
fsm_generator.show_waveform()
In [8]:
fsm_generator.stop()