Goal: to implement a state machine in VHDL.
Design a finite state machine for driving three LEDs. It has two inputs, reset and x, and three outputs, which will drive three LEDs. Here’s the behavior.
If reset = 1, the FSM waits in an idle state with all LEDs off.
When reset=0:
If x = 1, the FSM cycles through lighting each LED, one at a time, in a rotating pattern left-to-right.
If x=0, the FSM lights the outer two LEDs leaving the middle one off, then lights the middle LED and turns off the outer two, alternating each clock cycle.
If x changes while reset = 0, this has no effect; the state machine will just keep repeating the same pattern until reset =1, when it goes back into the idle state. Only then will x have an effect.
Design the system, and turn in a bubble diagram, state transition diagram, state transition and output equations, and a sketch of your design.
You will enter your design as a VHDL module. You can start with this VHDL template. To see the lights blinking, you will need to slow the clock down with a Linear Feedback Shift Register (LFSR). The LFSR is written in VHDL. Finally, download the following VHDL file, representing an LFSR, and instantiate it into your VHDL code as a component, in order divide down the board oscillator frequency.
In order to debug VHDL state machine designs, it’s extremely useful to display the state vector (or state name) in the ModelSim waveform plot. If you design your system in the Xilinx environment and use a waveform testbench, the state doesn’t automatically appear in the list of signals in ModelSim. The Xilinx system instantiates your design as a component under your testbench, with the name uut (for Unit Under Test). To look at signals in your design, you have to tell ModelSim to “look inside” uut and display the internal signal names.
Here are two methods.
1. Using the ModelSim command line interface. Assume your waveform testbench is called lights_tbw
VSIM>> add wave lights_tb/uut/state
VSIM> restart
VSIM> run 2500 ns
2. Using the ModelSim GUI.
a. Under the Workspace panel (upper left), the list of instances will include lights_tbw, and below that, uut.
b. Click on uut; its internal signals will appear in the Objects pane (next one to the right.)
c. Drag the signals you want to display, e.g. state, to the waveform panel.
d. Click the Restart icon.
e. Enter a run time in the run length window (e.g. 2500 ns)
f. Click the Run icon. The waveform plot should now include your state signal.