Skip to content

Lab 3: Music Player
Part D: FPGA Prototype V1

Lab 3 will give you experience designing, implementing, testing, and prototyping combinational and sequential logic using the Verilog hardware description language. The lab will continue to leverage concepts from Topic 2: Combinational Logic, Topic 3: Boolean Algebra, and Topic 4: Combinational Building Blocks but will also leverage concepts from Topic 6: Sequential Logic, Topic 7: Finite-State Machines, and Topic 8: Sequential Building Blocks. More specifically, the lab will give students experience with: latches, flip-flops, and registers; Moore and Mealy FSMs; and counters. The lab will continue to reinforce three key abstraction principles: modularity, hierarchy, and regularity.

You will be implementing a music player that takes as input a song selection (via the switches) and a start song signal (via a push button). The music player will then play the chosen song by generating a square wave at appropriate note frequencies suitable for use with a piezoelectric buzzer. An idle signal is displayed using an LED so that the user knows when the player is ready to play a new song. The music player will make use of the adders and muxes from Lab 2. The song selection and the current note are both displayed using seven-segment displays from Lab 1. This lab also serves as a transition from lower-level gate-level (GL) modeling to higher-level register-transfer-level (RTL) modeling. Some of parts of your design will use explicit GL modeling, while other parts of your design will use RTL modeling. Students will have a chance to appreciate how RTL modeling can improve productivity but with less control over the final hardware implementation. The lab includes six parts:

  • Part A: Counters

    • Due 10/15 @ 11:59pm via GitHub
    • Students should work on Part A before, during, and after your assigned lab section during the week of 10/5
    • Pre-lab survey on Canvas is (roughly) due by end of lab section during the week of 10/5
  • Part B: Breadboard, FPGA, and Simulation

    • Due week of 10/5 during assigned lab section
    • Even though completed with a partner, every student must turn in their own paper check-off sheet in their lab section!
  • Part C: Music Player

    • Due 10/22 @ 11:59pm via GitHub
    • It is ok if students need a little more time to complete the music player and clock divider as long as they are pushed to GitHub by 10/25 @ 11:59pm
    • Plan to work on Part C after fall break and during the week of 10/19
  • Part D: FPGA Prototype v1

    • Due week of 10/19 during assigned lab section
    • This part will focus on prototyping the code developed in Part A
    • Even though completed with a partner, every student must turn in their own paper check-off sheet in their lab section!
  • Part E: FPGA Prototype v2

    • Due week of 10/26 during assigned lab section
    • This part will focus on prototyping the code developed in Part C
    • Even though completed with a partner, every student must turn in their own paper check-off sheet in their lab section!
  • Part F: Datasheets and Report

    • Due week of 10/26, three days after lab section @ 11:59pm via Canvas
    • Post-lab survey on Canvas is due at the same time as the report

This handout assumes that you have read and understand the course tutorials and that you have attended the discussion sections. This handout assumes you have successfully completed Part A, meaning your counter is working in simulation.

What do we do if Part A is not done?

We assume students have completed Part A. If your counter is not passing your own tests you need to get it working before starting Part D. If your counter is passing your own tests but not passing the staff tests, then we recommend going ahead and getting started on Part D. You might still be able to get your counter FPGA prototype to work.

Here are the steps to get started:

  • Step 1. Find your lab partner
  • Step 2. Find a free workstation
  • Step 3. Ask the TAs for a lab check-off sheet (each student needs their own check-off sheet)

For each lab check-off task you must raise your hand and have a TA come to check-off your work. The TA will ask you the questions included as part of the lab check-off task and the assess your understanding using the following rubric: mastery; accomplished; emerging; beginning. If the TA and students together feel the students have not mastered the lab check-off task, the students are encouraged to take a few minutes and try again.

When the lab handout requires you to collect data or save a screenshot, place it in the corresponding location in your group's Lab 3 datasheet. These datasheets will be used to organize important information for the modules you are evaluating in lab. We provide you a template for your datasheets here:

Create a copy of this template for your own use by choosing File > Make a copy. Share this spreadsheet with your partner so you can work together on your datasheets. You do not need to have your datasheets completely finished by the end of Part D, but you do need to have the completed and submitted on Canvas for Part F.

What do we do if the TAs are busy?

Students must maintain a sense of urgency throughout the three hour lab section. When you get to a lab check-off task, raise your hand for 2-3 minutes. If no TA is available you must keep going; if nothing else read ahead and make a plan for the next section of the lab handout. If you do nothing and wait 20-30mins with your hand raised for a TA then you will not be able to finish all of Part D. You must be strategic. Keep moving through the handout and bring over a TA when they are free to possibly look at multiple lab check-off tasks. If you are truly stuck and no TA is available, ask your neighbors. We need to all work together to make sure every student can complete Part D. There are no extensions and students cannot complete Part D at any other time except during their assigned lab section.

Lab Check-Off Task 1: Setup Lab Kit

The TAs will pass out an ECE 2300 Lab Kit to each group. The TAs will record the kit number on your check-off sheet. For this lab, you will receive the FPGA board and a USB cable. Use the USB cable to plug the FPGA board into the workstation.

1. Simulate Counters

Before starting to work on an FPGA prototype, you must make sure you have a working Verilog hardware design that has been thoroughly tested in simulation. One student should start VS Code on the workstation, log into the ecelinux servers, source the setup script, and make sure their group repository is up to date.

% source setup-ece2300.sh
% cd ${HOME}/ece2300/groupXX
% git pull
% tree

Where XX is your group number. Now run all of the tests from a clean build to ensure your design is fully functional.

% cd ${HOME}/ece2300/groupXX
% trash build
% mkdir build
% cd build
% ../configure
% make check-lab3a

We now need to get the files for your design from ecelinux onto the workstation. This requires multiple steps.

  • Step 1. Click Microsoft Edge on the desktop to open a web-browser on the workstation to log into GitHub and then find your repository

  • Step 2. Start PowerShell by clicking the Start menu then searching for Windows PowerShell

  • Step 3. Use the following command to change to your home directory on the workstation in the lab (where netid is your Cornell NetID)

% cd C:\Users\netid
  • Step 4. Clone your repo onto the workstation by using this command in PowerShell (where netid is your Cornell NetID, notice we are using https!):
% git clone https://github.com/cornell-ece2300/groupXX

If your group repo already exists then you need to instead do a pull!

% cd groupXX
% git pull
  • Step 5. In the Connect to GitHub pop-up, click Sign in with your browser

  • Step 6. You may be asked for your GitHub username again and you may be asked to authorize the Git Credential Manager; click authorize git-ecosystem

  • Step 7. Verify that you have successfully cloned your repo by changing into your repo and using tree on the workstation:

% cd groupXX
% tree

Lab Check-Off Task 2: Verify Design in Simulation

Show a TA that your hardware designs are passing all of your test benches on ecelinux.

2. Setup Quartus Project

Click Quartus (Quartus Prime 18.1) on the desktop to start Quartus. Important: Ensure that the Quartus Version is 18.1 and not 23.1. Then, click Run the Quartus Prime software. You might need to try starting Quartus twice. Setup a new Quartus project using the New Project Wizard:

  • Directory, Name, Top-Level Entity
    • You must enter the working directory as follows with your NetID!
    • Working directory: C:\Users\netid\lab3d
    • Name of this project: lab3d
    • Name of top-level design entity: lab3d
    • Click Next
  • Directory does not exist. Do you want to create it?
    • Click yes
  • Project Type
    • Choose Empty Project
    • Click Next
  • Add Files
    • Click User Libraries...
    • Click triple dots to the right of Project library name
    • Click on This PC, then navigate to your cloned repo by choosing Windows (C:) > Users > netid > groupXX where XX is your group number
    • Click Select Folder
    • Click Add
    • Click OK
    • Click triple dots to right of File name
    • Click on This PC, then navigate to your cloned repo by choosing Windows (C:) > Users > netid > groupXX > lab3 where XX is your group number
    • Shift-click on every Verilog hardware design file (do not include any files in the test or sim subdirectories)
    • Click Open
    • Click Next
  • Family, Device, and Board Settings
    • Click Board tab
    • Family: Cyclone V
    • Select DE0-CV Development Board
    • Make sure Create top-level design file is checked
    • Click Next
  • EDA Tool Settings
    • Click Next
  • Summary
    • Click Finish

As in Lab 2, you must use the following steps to ensure Quartus knows your design includes RTL modeling:

  • Choose Assignments > Settings from the menu
  • Select the category Compiler Settings > Verilog HDL Input
  • Under Verilog version click SystemVerilog
  • Click OK

3. Synthesize and Analyze Counters

We will start by synthesizing and analyzing the two different counter implementations. Once we better understand the tradeoffs in these implementations, we can make high-level conclusions about their tradeoffs.

If you did not draw a block diagram in Part A, then you must draw a diagram now. Save this diagram since you will be annotating it later in the lab.

Lab Check-Off Task 3: Discuss Gate-Level Counter Block Diagram

Show a TA your GL counter block diagram and the corresponding Verilog code side-by-side. The TA will ask you to connect the block diagram to the Verilog code. Explain how loading a new value works. Explain how the enable signal for both registers and the done signal are implemented. Predict where the critical path will go using the block diagram.

3.1. Synthesize and Analyze GL Counter

To synthesize and analyze the GL Counter in isolation use the following steps:

  • Find the Project Navigator pane
  • Click on Hierarchy to display the drop-down list
  • Choose Files and select the Counter_16b_GL.v file
  • Right click on the file and choose Select as Top-Level Entity
  • Click on Files to display the drop-down list again
  • Choose Hierarchy and confirm that Counter_16b_GL is shown as the only entity

As in Part B, we need to create a timing constraint file which now also needs to inform the tools that there is a clock signal as part of our design. Identifying the clock signal will enable the tools work to ensure that our design has no setup or hold time violations. Similar to Part B, when finished, the design will either "meet timing" (i.e., the actual critical path delay is less than the constraint and there are no hold time violations) or "not meet timing" (i.e., the actual critical path delay is greater than the constraint or there are hold time violations).

Here are the steps to create a timing constraint file:

  • Choose File > New from the menu
  • Click Synopsys Design Constraints File
  • Click OK
  • Enter the constraints shown below
  • Click File > Save from the menu
  • Name the file timing.sdc
  • Save the file in the lab3d directory

We will use the following initial constraints:

# in2out paths start at an input port and end at an output port
set_max_delay -from [all_inputs] -to [all_outputs] 20
set_min_delay -from [all_inputs] -to [all_outputs] 0

# ff2ff paths start at a flip-flop and end at a flip-flop
create_clock -name clk -period 20 [get_ports {clk}]

# in2ff paths start at an input port and end at a flip-flop
set_input_delay  -add_delay -clock clk -max 0 [all_inputs]
set_input_delay  -add_delay -clock clk -min 0 [all_inputs]

# ff2out paths start at a flip-flop and end at an output port
set_output_delay -add_delay -clock clk -max 0 [all_outputs]
set_output_delay -add_delay -clock clk -min 0 [all_outputs]

These constraints constrain four kinds of paths:

  • in2out paths start at an input port and end at an output port

    • These paths must have a maximum delay of 20ns
    • These paths must have a minimum delay of 0ns (i.e, the hold time is 0ns)
  • ff2ff paths start at a flip-flop and end at a flip-flop

    • These paths must have a maximum delay of 20ns (i.e., the clock period is 20ns)
    • The hold time constraint is provided by the timing parameters for the actual flip-flops as opposed to being in the timing constraint file
  • in2ff paths start at an input port and end at a flip-flop

    • These paths must have a maximum delay of 20ns (i.e., the setup time is 0ns)
    • There is an additional 0ns of propagation delay outside this module to get to the input port
    • There is an additional 0ns of contamination delay outside this module to get to the input port
  • ff2out paths start at a flip-flop and end at an output port

    • These paths must have a maximum delay of 20ns (i.e., the setup time is 0ns)
    • These paths must have a minimum delay of 0ns (i.e, the hold time is 0ns)

The following diagram illustrates all four kinds of paths:

Now use the following steps to synthesize your design.

  • Choose Processing > Start Compilation from the menu
  • Wait 1-2 minutes for synthesis to complete

We will not be sweeping the clock constraint but instead we will only analyze the critical path with the 20ns critical path delay constraint. Your GL counter will likely not meet timing. Quartus is designed to recognize specific RTL patterns as "real" flip-flops, but it is not designed to recognize a gate-level DFF as a "real" flip-flop. This means Quartus cannot accurately analyze the setup and hold time constraints for our GL counter. Real-world FPGA designs always use RTL modeling for sequential logic and would never gate-level modeling for sequential logic. However, we can still use Quartus to accurately analyze the area and critical path of our gate-level counter and this enables a rigorous comparative analysis with our RTL counter.

How do I fix "can't open Verilog Design File" errors?

This probably means you did not setup the user library correctly, so Quartus cannot find the files you are including using the include Verilog preprocessor directive. You can use the following steps to fix this:

  • Choose Assignments > Settings from the menu
  • Select the category Libraries
  • Click triple dots to the right of Project library name
  • Click on This PC, then navigate to your cloned repo by choosing Windows (C:) > Users > netid > groupXX where XX is your group number
  • Click Select Folder
  • Click Add
  • Click OK
  • Choose Processing > Start Compilation from the menu to see if this fixes the issue

How do I fix "Verilog HDL syntax" errors?

This might be because you did not configure Quartus to use SystemVerilog! You can use the following steps to ensure Quartus knows your design includes RTL modeling:

  • Choose Assignments > Settings from the menu
  • Select the category Compiler Settings > Verilog HDL Input
  • Under Verilog version click SystemVerilog
  • Click OK

Now let's look at the RTL viewer, technology map viewer, and chip planner.

  • RTL Viewer
    • Choose Tools > Netlist Viewer > RTL Viewer from the menu
    • Drill down in the hierarchy to see the netlist for the counter
    • Does the RTL viewer match your expectations?
    • Choose File > Close from menu to close the RTL viewer
  • Technology Map Viewer
    • Choose Tools > Netlist Viewer > Technology Map Viewer (Post-Fitting)
    • Drill down into the adder in your counter all the way to see the implementation of the full adder
    • Does the technology viewer match your expectations?
    • Choose File > Close from the menu to close the technology map viewer
  • Chip Planner
    • Choose Tools > Chip Planner from the menu
    • Identify where the logic used to implement your design is located in the FPGA
    • Save a screenshot of the Chip Planner (just the rectangular view of the FPGA) using WindowsKEY+SHIFT+S for your datasheet
    • Choose File > Close from the menu to close the chip planner

The next step is to analyze the area of your design.

  • Choose Processing -> Compilation Report from the menu
  • Under Table of Contents choose Fitter > Resource Section > Resource Usage Summary
  • Record the number of logic gates (i.e., combinational ALUT usage for logic) in the Area section of the datasheet.
  • Record the number of flip-flops (i.e., each dedicated logic registers in the report is one flip-flop) in the Area section of the datasheet.

The final step is to find the critical path of your design. We will analyze timing for the Slow 1100mV 85C Model which is the default choice in the Timing Analyzer.

  • Choose Tools > Timing Analyzer from the menu
  • Double-click Update Timing Netlist
  • Choose Reports > Custom Reports > Report Timing from the menu
  • Report Timing
    • Clocks - From clock: clk
    • Clocks - To clock: clk
    • Targets - From: [get_registers *]
    • Targets - To: [get_registers *]
    • Report number of paths: 100
    • Detail level: Path Only (click Set Default)
    • Click Report Timing

As mentioned above, your GL counter will not meet timing. Quartus does not understand that your gate-level flip-flop is actually a sequential logic gate (check the number of flip-flops in your datasheet to confirm this). So Quartus cannot determine if the design meets the setup time and hold time constraints. However we can still use Quartus to analyze the critical path. As we learned in Lab 3B, we will use the following conventions when analyzing the critical path based on FPGA timing reports. The FPGA timing report will have three parts:

  • The clock part of the data arrival path. This is the delay from the clock pin to the flip-flop at the start of the path. We will ignore this part in this class!

  • The data part of the data arrival path. This is the actual propagation path delay from one flip-flop to another flip-flop. This is the part you need to report on in this class!

  • The clock part of the data required path. This is the delay from the clock pin to the flip-flop at the end of the path. We will ignore this part in this class!

The following timing report illustrates these three parts along with how to divide the critical path (i.e., the data arrival path) into:

  • Clock-to-q propagation delay (\(t_{pd,cq}\))
  • Combinational logic propagation delay (\(t_{pd,comb}\))
  • Setup time (\(t_{setup}\))

Use the timing report to update the Timing section of the datasheet with the critical path delay. The only data you should enter in the Timing section for the GL counter is the critical path delay! Then use the following steps to update the Critical Path section of the datasheet.

  • Select the complete Data Arrival Path, including all columns, rows, values, and netnames, and copy it to the clipboard
  • Paste the copied Data Arrival Path into the Critical Path section of your datasheet where it says paste here

Draw the critical path on your block-level diagram. Annotate the clock-to-q delay, the propagation delay of each block along the critical path, and the setup time on your block level diagram.

Update Datasheet for Gate-Level Counter

Make sure the module name, designers, group number, chip planner, area, timing, and critical path sections of your datasheet are finished. Do not copy/paste screenshots into the datasheet. Use Insert > Insert image in Cell from the menubar to insert screenshots. The block diagram in the datasheet will be the annotated block diagram for your counter. You can update the interface, functionality, block diagram, and waveform sections later as you prepare your datasheets for submission in Part F.

Lab Check-Off Task 4: Discuss Gate-Level Counter

Show a TA the progress you have made on your datasheet for the gate-level counter. Explain why there are no flip-flops. Show a TA the critical path on your block diagram and clearly show how the delays in the timing report correspond to the delays annotated on the block diagram. Is this the critical path you expected?

3.2. Synthesize and Analyze RTL Counter

Use the same process to synthesize and analyze the flat RTL counter in isolation. We will only be analyzing the flat RTL counter! Remember to change that hardware module to be the top-level entity using the following steps:

  • Find the Project Navigator pane
  • Click on Hierarchy to display the drop-down list
  • Choose Files and select the Counter_16b_flat_RTL.v file
  • Right click on the file and choose Select as Top-Level Entity
  • Click on Files to display the drop-down list again
  • Choose Hierarchy and confirm that Counter_16b_flat_RTL is shown as the only entity

Now let's look at the RTL viewer, technology map viewer, and chip planner.

  • RTL Viewer
    • Choose Tools > Netlist Viewer > RTL Viewer from the menu
    • Drill down in the hierarchy to see the netlist for the counter
    • Does the RTL viewer match your expectations?
    • Choose File > Close from menu to close the RTL viewer
  • Technology Map Viewer
    • Choose Tools > Netlist Viewer > Technology Map Viewer (Post-Fitting)
    • Does the technology viewer match your expectations?
    • Choose File > Close from the menu to close the technology map viewer
  • Chip Planner
    • Choose Tools > Chip Planner from the menu
    • Identify where the logic used to implement your design is located in the FPGA
    • Save a screenshot of the Chip Planner (just the rectangular view of the FPGA) using WindowsKEY+SHIFT+S for your datasheet
    • Choose File > Close from the menu to close the chip planner

Go ahead and open up the Technology Map Viewer again. Make sure you can see the entire design by right clicking in the technology map viewer and choose Goto Top Level. Spend time looking at the Technology Map Viewer and try to figure out how the blocks in the Technology Map Viewer connect to your Verilog implementation. Hint: Zoom in on the technology mapper viewer and look at what the different blocks are named. If several blocks are named something related to comparator then they are likely implementing the comparator. If several blocks are named something related to adder then they are likely implementing the adder. The registers should be two green boxes. Again, look at the names to try and figure out which register maps to which green box. Note that sometimes Quartus will embed a mux into a register so consider looking closely at the ports to the register or zooming into see what is inside the register.

Save a screenshot of the Technology Map Viewer using WindowsKEY+SHIFT+S for your datasheet. Annotate this screen shot by circling what logic implements:

  • (1) The storage element that keeps track of the current count
  • (2) The storage element that keeps track of the finish value
  • (3) The logic that increments the count
  • (4) The logic that determines what should be the next stored count
  • (5) The logic that determines whether the counter is done

Clearly label each circle with a number from 1-5 which corresponds to the above list.

The next step is to analyze the area of your design.

  • Choose Processing -> Compilation Report from the menu
  • Under Table of Contents choose Fitter > Resource Section > Resource Usage Summary
  • Record the number of logic gates (i.e., combinational ALUT usage for logic) in the Area section of the datasheet.
  • Record the number of flip-flops (i.e., each dedicated logic registers in the report is one flip-flop) in the Area section of the datasheet.

The final step is to find the critical path of your design. We will analyze timing for the Slow 1100mV 85C Model which is the default choice in the Timing Analyzer.

  • Choose Tools > Timing Analyzer from the menu
  • Double-click Update Timing Netlist
  • Choose Reports > Custom Reports > Report Timing from the menu
  • Report Timing
    • Clocks - From clock: clk
    • Clocks - To clock: clk
    • Targets - From: [get_registers *]
    • Targets - To: [get_registers *]
    • Report number of paths: 100
    • Detail level: Path Only (click Set Default)
    • Click Report Timing

Your RTL counter should meet timing. Quartus definitely understands that an RTL flip-flop is a "real" sequential logic gate. Now that we are looking at an RTL design we can do a more rigorous timing analysis. The following timing report illustrates how to find the key timing parameters.

  • Clock period (\(T_C\))
  • Clock-to-q propagation delay (\(t_{pd,cq}\))
  • Combinational logic propagation delay (\(t_{pd,comb}\))
  • Setup time (\(t_{setup}\))
  • Clock skew (\(t_{skew}\))
  • Setup slac (\(t_{setup,slack}\))

In the above example, we can see the following values for these timing parameters:

  • \(T_{C} = 20ns\)
  • \(t_{pd,cq} = 0ns\)
  • \(t_{pd,comb} = 1.005ns\)
  • \(t_{setup} = 5.214ns\)
  • \(t_{skew} = 0.486ns\)
  • \(t_{setup,slack} = 13.987\)

From lecture, we know the setup time constraint is as follows:

\[T_{C} \ge t_{pd,cq} + t_{pd,comb} + t_{pd,setup} - t_{skew}\]

And we know the setup slack is defined as:

\[t_{setup,slack} = T_{C} - (t_{pd,cq} + t_{pd,comb} + t_{pd,setup} - t_{skew})\]

However, if we do the math we will find that the right-hand side of the above equation is 14.267ns which does not equal the given setup slack of 13.987. The reason why is the FPGA tools are using a more complex delay model which includes clock uncertainty. Clock uncertainty models clock jitter where the clock period is not perfectly 20ns and can vary from cycle to cycle. The more complex setup time constraint is as follows:

\[T_{C} \ge t_{pd,cq} + t_{pd,comb} + t_{pd,setup} - t_{skew} - t_{uncertainty}\]

And the setup slack is defined as:

\[t_{setup,slack} = T_{C} - (t_{pd,cq} + t_{pd,comb} + t_{pd,setup} - t_{skew} - t_{uncertainty})\]

If you look in the above timing report you can see the clock uncertainty is -0.280ns. Our equation should now produce the same setup slack that is in the timing report of 13.987ns.

Identify the clock cycle constraint, critical path delay, clock skew, and clock uncertainty and record these timing parameters in the Timing section of your datasheet. The datasheet will calculate the slack. Confirm that the slack in your datasheet matches the slack in the timing report.

Then use the following steps to update the Critical Path section of the datasheet.

  • Select the complete Data Arrival Path, including all columns, rows, values, and netnames, and copy it to the clipboard
  • Paste the copied Data Arrival Path into the Critical Path section of your datasheet where it says paste here

Update Datasheet for RTL Counter

Make sure the module name, designers, group number, chip planner, area, timing, and critical path sections of your datasheet are finished. Do not copy/paste screenshots into the datasheet. Use Insert > Insert image in Cell from the menubar to insert screenshots. The block diagram in the datasheet will be the annotated screenshot from the technology map viewer for your counter. You can update the interface, functionality, block diagram, and waveform sections later as you prepare your datasheets for submission in Part F.

Lab Check-Off Task 5: Discuss RTL Counter

Show a TA the progress you have made on your datasheet for the RTL counter. Justify why the number of flip-flops makes sense. Show a TA your technology map screen shot annotated with Verilog code snippets. Explain to the TA the connection between the Verilog code and the actual low-level logic gates. Are we convinced that RTL modeling does indeed turn into low-level logic gates?

4. Counter FPGA Prototype

We now have a fully verified Verilog hardware design, and we have finished a rigorous comparative analysis of the area and timing of both a GL and RTL counter. The last step is to integrate, synthesize, and configure the FPGA with our RTL design and demonstrate the final FPGA prototype!

4.1. Integrate

We need to change the top-level entity to be DE0_CV_golden_top.v using the following steps:

  • Find the Project Navigator pane
  • Click on Hierarchy to display the drop-down list
  • Choose Files and select the DE0_CV_golden_top.v file
  • Right click on the file and choose Select as Top-Level Entity
  • Click on Files to display the drop-down list again
  • Choose Hierarchy and confirm that DE0_CV_golden_top is shown as the only entity

The New Project Wizard creates a top-level Verilog module for us which has ports for all of the switches, LEDs, seven-segment displays, and pins on the FPGA development board. We need to instantiate Counter_16b_flat_RTL in this top-level Verilog module along with three instances of DisplayOpt_GL and connect the ports. Students are responsible for figuring out the appropriate top-level port connections to meet the following specification.

  • rst should be connected to the reset button on the board
  • The first button is for clk
  • The second button is for load
  • The left five switches are for start
  • The right five switches are for finish
  • The first LED is for done
  • The two seven-segment displays on the left are for start
  • The two seven-segment displays in the middle are for finish
  • The two seven-segment displays on the right are for count

You should ensure your counter is always enabled and that the counter always increments by 1.

Reset button and push buttons are active low!

In previous labs, we learned that the push buttons on the FPGA board are active low. This means when not pressed they produce a logic one, and when pressed they produce a logic zero. The FPGA's reset button (which is connected to the RESET_N port) is also active low. You must take this into account when you connect your top-level ports!

We provide you a suitable template below for your top-level implementation below. Replace every TODO with the correct connection to the top-level pins on the FPGA.

//----------------------------------------------------------------------
// Setup Quartus
//----------------------------------------------------------------------
// A typo can result in using an undeclared wire, but this is usually
// just a warning. The following makes using undeclared wires an error.

`default_nettype none

//----------------------------------------------------------------------
// Prepare input values
//----------------------------------------------------------------------
// We need to zero extend the five-bit value we get from the switches
// to a 16-bit value for use with the counter. You need to connect
// sw_start and sw_finish to the appropriate top-level ports.

logic [4:0] sw_start;
assign sw_start = __TODO__;

logic [15:0] start;
assign start = { 11'b0, sw_start };

logic [4:0] sw_finish;
assign sw_finish = __TODO__;

logic [15:0] finish;
assign finish = { 11'b0, sw_finish };

//----------------------------------------------------------------------
// Instantiate the counter
//----------------------------------------------------------------------
// You need to connect up to the appropriate top-level port.

logic [15:0] count;

Counter_16b_flat_RTL counter
(
  .clk    (__TODO__),
  .rst    (__TODO__),
  .en     (__TODO__),
  .load   (__TODO__),
  .start  (start),
  .incr   (__TODO__),
  .finish (finish),
  .count  (count),
  .done   (__TODO__)
);

//----------------------------------------------------------------------
// Seven segment displays
//----------------------------------------------------------------------
// You need to connect the outputs of the displays to the appropriate
// top-level ports.

DisplayOpt_GL display_start
(
  .in       (start),
  .seg_tens (__TODO__),
  .seg_ones (__TODO__)
);

DisplayOpt_GL display_finish
(
  .in       (finish),
  .seg_tens (__TODO__),
  .seg_ones (__TODO__)
);

DisplayOpt_GL display_count
(
  .in       (count[4:0]),
  .seg_tens (__TODO__),
  .seg_ones (__TODO__)
);

Use the following steps when you are ready to integrate the counter.

  • Double-click on DE0_CV_golden_top
  • Instantiate the template shown above
  • Fill in the connections to the top-level ports
  • Be sure to use `include "lab1/DisplayOpt_GL.v" at the top
  • Choose File > Save from the menu

Lab Check-Off Task 6: Discuss Counter Integration

Show a TA your top-level integration. Discuss how you connected your counter's ports to either constant values or the FPGA's switches, push buttons, LEDs, and seven-segment displays.

3.4. Synthesize

We need to update our timing constraint file as follows:

# Constrain paths that start at an input port and end at an output port
set_max_delay -from [all_inputs] -to [all_outputs] 20
set_min_delay -from [all_inputs] -to [all_outputs] 0

# Constrain paths that start at a flip-flop and end at a flip-flop
create_clock -name clk -period 20 [get_ports {KEY[0]}]

# Constrain paths that start at an input port and end at a flip-flop
set_input_delay  -add_delay -clock clk -max 0 [all_inputs]
set_input_delay  -add_delay -clock clk -min 0 [all_inputs]

# Constrain paths that start at a flip-flop and end at an output port
set_output_delay -add_delay -clock clk -max 0 [all_outputs]
set_output_delay -add_delay -clock clk -min 0 [all_outputs]

The key difference is that we are specifying that the first push button (i.e., KEY[0]) will be used as the clock for the counter. From here, choose Processing > Start Compilation from the menu to synthesize your design.

3.5. Configure

Now we are finally ready to configure the FPGA for our counter demo!

  • Choose Tools > Programmer from the menu
  • Click Hardware Setup
  • Currently selected hardware: USB-Blaster [USB-0]
  • Click Close
  • Click Start

Test out your counter. Load in different start and finish values. Press the first push button to toggle the clock. Try resetting the counter. Ensure the displayed count and done signal correspond to your expectations.

Now we want to make sure the counter interactive simulator is working on ecelinux. Try using the counter interactive simulator with different start and finish values.

% cd ${HOME}/ece2300/groupXX/build
% make counter-sim
% ./counter-sim +start-switches=00000 +finish-switches=01000
% ./counter-sim +start-switches=00011 +finish-switches=01000

Try out your counter simulator for a few values, and make sure that the FPGA behaves identically.

Lab Check-Off Task 7: Demonstrate the RTL Counter

First, show a TA the counter interactive simulator, demonstrating its functionality. The TA will give you a switch configuration. You should first predict what your counter will do, then demonstrate it in simulation. Then demonstrate that your counter on the FPGA produces identical results for the same stimulus. Additionally, demonstrate that your counter can load new start and finish values at any time. Clearly explain to the TA why the counter prototype is different from the calculator prototype in Lab 2; explain how the counter prototype illustrates sequential logic.

Lab Check-Off Task 8: Turn in Lab Kit

When you are finished with your demo, pack up your ECE 2300 Lab Kit. Return the FPGA board and USB cable to a TA who will then record the kit number on your check-off sheet, initial the final check-off, and then collect your check-off sheet.