UCR EE/CS120B: Digital Systems
Lab 6: FSM+D Design
I. Introduction
The purpose of this lab is to implement a finite state machine plus datapath (FSM+D) in VHDL to calculate the Greatest Common Divisor (GCD) of 2 numbers.
The design of the GCD calculator should be divided into 2 parts - a controller and a datapath. The controller is an FSM which issues commands to the datapath based on the current state and the external inputs. This can be a behavioral description similar to Lab 4. The datapath contains a netlist of functional units like multiplexors, registers, subtractors and a comparator, and hence this design is structural similar to Lab 3. The controller basically steps through different states based on the comparison of the 2 numbers x and y. If x = y, we have finished computing the GCD, and we go to the final state and assert the data output line, and reset the FSM back to state 0. The Datapath does the actual GCD computation. It has the following components:
The algorithm for calculating the GCD of x and y is as follows:
while (x != y) {
if (x < y)
y = y – x
else
x = x – y
}
output x
II. Implementation
Please refer to the figure given below for an example of how the design might be captured. However, your state machine can have a different number of states and different arcs, including loops. The datapath is not exactly what you need and needs to be modified accordingly. Write a testbench and verify your results.
Sample Structure of the Controller and Datapath
III. Downloading
Once you have verified your results using Aldec HDL, check out an XS40 board from the T.A. Download your code and verify your results.