Lab 3: FSM for 4-bit Up/Down Counter

Starts: Week 6 (Sep 29-Oct 03)
Demo Due: Week 7 (Oct 03-Oct 10)
Code Due: Friday, Oct 10, 11:59PM
Points: 75

Pre-Lab Assignment

Create and state diagram for the 4-bit Up/Down Counter design described below. (15 points)

Files

Lab Overview

In this lab, you will build a two implementations for a 4-bit Up/Down Counter and interface the up/down counter with your binary to 7-segment LED decoder designed in Lab 2. The initial 4-bit up/down counter design has four inputs, Clk, Rst, Enable, UpDown, and a 4-bit output Cnt, represented by the four outputs Cnt3, Cnt2, Cnt1, Cnt0. If Rst is 1, the counter should reset its count value to zero (0000). Otherwise, if Enable is 1, on every clock cycle the counter should count up by one when UpDown is 1 or count down by one when UpDown is 0. Upon reaching the minimum (0) or maximum (15) count, the counter value should wraparound. In other words, when counting up, the counter should wraparound to 0 after 15, and when counting down, the counter should wraparound to 15 after 0. If Enable is 0, the counter should keep its present value.

In order to download your initial 4-bit up/down counter implementation to the Spartan-3E FPGA board, you will need to interface your counter with the binary to 7-segment LED decoder designed in Lab 2. Furthermore, the 50MHz clock integrated within the Spartan-3E FPGA board operates too quickly to be able to view the counter output on the 7-segment LED display. As such, you must also interface with the clock divider component provided with this lab. The clock divider, ClkDiv, has two inputs, Clk and Rst, and one output, ClkOut. Given the 50 MHz clock provided by the Spartan-3E FPGA board, the ClkDiv component will generate a 1 Hz clock on its output, ClkOut. This 1 Hz clock can then be connected to the input of your 4-bit counter. The resulting counter will count up or down once every second if enabled.

The figure to the above right provides an overview of the connections that will be used to implement your 4-bit Up/Down Counter on the Spartan-3E FPGA board. The overall counter implementation will have a single Clk input provided by the 50 MHz oscillator integrated on the Spartan-3E FPGA Board, two reset inputs – one for the clock divider (DivRst) and one for your 4-bit Up/Down Counter (Rst), and Enable and UpDown inputs connected to your 4-bit Up/Down Counter. The implementation will also interface with your binary to 7-segment LED display using the outputs to the individual segment of the 7-segment LED display. The following is a partial .ucf file providing the connection details for the new inputs and outputs needed for the 4-bit Up/Down Counter (you will need complete the .ucf file to properly connect to the 7-segment LED display):

NET "Clk" LOC = "C9";
NET "Rst" LOC = "K17" | PULLDOWN;
NET "DivRst" LOC = "D18" | PULLDOWN;

NET "Enable" LOC = "N17";
NET "UpDown" LOC = "H18";

# Enter additional connections below


Lab Procedure

  1. Behaviorally design the 4-bit Up/Down Counter as a Finite State Machine (FSM). You FSM design should consist of two always procedures. The first always procedure, should implement the state register. The second always procedure should implement the FSM control logic. In the design of the FSM control logic, you must use a case statement to describe the combinational behavior associated with each state. (20 points)
  2. Create a testbench to test your design for correct functionality. Your testbench should be self checking using if statements and the $display task to report any errors during simulation. At a minimum, the self checking testbench should test the following cases (20 points):
    • Check that counter counts up and down correctly (5 points)
    • Check for correct wraparound functionality for counting up and down (5 points)
    • Check for correct reset behavior from non-zero count value (5 points)
    • Check for correct enable behavior (5 points)
  3. Create a new top-level component that structurally connects your 4-bit Up/Down Counter with the clock divider, ClkDiv, and your binary to 7-segment LED decoder. Complete the provided .ucf file and synthesize your 4-bit Up/Down Counter. Download and test your design on the Spartan-3E FPGA board for correct functionality. At a minimum, you should test the same cases as your self checking testbench. (20 points)

ECE 274

Labs

Previous Offerings

edit SideBar