Lab 7: Useful Components

Assigned
Tuesday, May 12, 2026
Due Date
Wednesday, May 20, 2026 at 2:30 pm

Overview

Over the last six labs we've learned how to do most kinds of basic logic, but there are still more common elements that are useful for building more and more complex systems. This lab will help you get some experience with them now, and add them to your toolkit in advance of the final project.

Code for this lab

No code provided! Feel free to copy any needed files from previous labs or from lecture as a starting point.

Design Problem – CyberWar

In the last lab, we built a Tug of War game, and by now you've already crushed your roommate into submission. Now it's the hardware's turn. Your goal is to develop a computer opponent to play against, as well as a scorekeeper that can show exactly how badly it beats you…


Counters

We will replace the "winner" system from Lab 6 with counters. Develop a 3-bit counter that satisfies the following behavior:

  • Holds a 3-bit state (values 0-7).
  • Starts at (and resets to) the value 0.
  • When it receives a "win"/"count" input, it increments its current value by 1.
  • It doesn't matter what happens when you count past 7 points.

Copy your Lab 6 files and alter them so that there is a counter for each player, each of which drive a 7-segment display with the current score for that player. Whenever someone wins, you increment the appropriate player's score and then restart the game (i.e., reset the playfield). Resetting the entire game will reset the playfield and score, while winning only resets the playfield.


Linear Feedback Shift Registers (LFSRs)

To build a cyber-player, we need to create a random number generator to simulate the button presses of your opponent. In hardware, a simple way to produce pseudo-random numbers is a linear feedback shift register (LFSR). It consists of a set of ℕ D flip-flops (DFF1 to DFF), where the output of DFFi is the input of DFFi+1 (shifting bits linearly). The "randomness" comes from attaching some logical combination of the state bits (feedback) to the input of DFF1. By careful choice of the logical combination, we can get an FSM that is easy to implement but still goes through a fixed pattern of states that appears random.

In this lab, we will use the XNOR of two state bits as our input combination. An example is shown below:

Figure 1: 4-bit LFSR that shifts towards the most-significant bit with the feedback being the XNOR of the two most-significant bits.

Draw the state diagram for the LFSR shown above. This should show every possible state for the machine (16 total), with transition arrows showing the next state they will enter. Hint: a "*" can be used to label an "always" transition, meaning that regardless of the inputs, we transition to the next state.

Next, create a 9-bit LFSR in Quartus and simulate it. You can find the list of bits to XNOR together by clicking the preview image below. "n" is the number of bits in your shift register (n = 4 for figure 1). "XNOR from" indicates the state bits (numbered starting from 1) to input to your XNOR gate (this is 3 and 4 for figure 1). Following this table will generate the maximum-length LFSR state sequence. How long is the cycle of states for this LFSR (i.e., how many cycles until a state reappears)? Make sure your simulation proves this in whatever way you feel is most appropriate (be creative!). Some example options:

  • Split the waveform into multiple screenshots to make things more readable.
  • Create an extra signal that only goes high when you're in a particular state.
  • Look in the for how to use printing statements like $display.
nXNOR fromnXNOR fromnXNOR fromnXNOR from
33,24545,44,42,418787,74129129,124
44,34646,45,26,258888,87,17,16130130,127
55,34747,428989,51131131,130,84,83
66,54848,47,21,209090,89,72,71132132,103
77,64949,409191,90,8,7133133,132,82,81
88,6,5,45050,49,24,239292,91,80,79134134,77
99,55151,50,36,359393,91135135,124
1010,75252,499494,73136136,135,11,10
1111,95353,52,38,379595,84137137,116
1212,6,4,15454,53,18,179696,94,49,47138138,137,131,130
1313,4,3,15555,319797,91139139,136,134,131
1414,5,3,15656,55,35,349898,87140140,111
1515,145757,509999,97,54,52141141,140,110,109
1616,15,13,45858,39100100,63142142,121
1717,145959,58,38,37101101,100,95,94143143,142,123,122
1818,116060,59102102,101,36,35144144,143,75,74
1919,6,2,16161,60,46,45103103,94145145,93
2020,176262,61,6,5104104,103,94,93146146,145,87,86
2121,196363,62105105,89147147,146,110,109
2222,216464,63,61,60106106,91148148,121
2323,186565,47107107,105,44,42149149,148,40,39
2424,23,22,176666,65,57,56108108,77150150,97
2525,226767,66,58,57109109,108,103,102151151,148
2626,6,2,16868,59110110,109,98,97152152,151,87,86
2727,5,2,16969,67,42,40111111,101153153,152
2828,257070,69,55,54112112,110,69,67154154,152,27,25
2929,277171,65113113,104155155,154,124,123
3030,6,4,17272,66,25,19114114,113,33,32156156,155,41,40
3131,287373,48115115,114,101,100157157,156,131,130
3232,22,2,17474,73,59,58116116,115,46,45158158,157,132,131
3333,207575,74,65,64117117,115,99,97159159,128
3434,27,2,17676,75,41,40118118,85160160,159,142,141
3535,337777,76,47,46119119,111161161,143
3636,257878,77,59,58120120,113,9,2162162,161,75,74
3737,5,4,3,2,17979,70121121,103163163,162,104,103
3838,6,5,18080,79,43,42122122,121,63,62164164,163,151,150
3939,358181,77123123,121165165,164,135,134
4040,38,21,198282,79,47,44124124,87166166,165,128,127
4141,388383,82,38,37125125,124,18,17167167,161
4242,41,20,198484,71126126,125,90,89168168,166,153,151
4343,42,38,378585,84,58,57127127,126
4444,43,18,178686,85,74,73128128,126,101,99
Figure 2: LFSR taps [XAPP 052 July 7, 1996 (Version 1.1), Peter Alfke, Xilinx Inc] p5. link

Adders

In class, we developed a circuit for adding binary numbers. Implement either:

  1. a 9-bit adder with carry out
  2. or
  3. a 10-bit adder
and simulate it to show that it is working.

Since showing all input combinations for an adder of this size is unreasonable, please simulate enough to cover the situations listed below. If you are unsure what any of these mean, please ask!

  • An addition with one input being 0.
  • An addition whose result is 511.
  • An addition whose result is 0 (other than 0 + 0).
  • An example of unsigned overflow.
  • An example of positive signed overflow (pos + pos = neg).
  • An example of negative signed overflow (neg + neg = pos).

Cyber Player

Now let's implement a tunable cyber player!

  1. Read through the spec and design requirements carefully.
  2. Draft a block diagram for your cyber_war system, either from scratch or by modifying your Lab 6 block diagram.
  3. Implement the system according to your block diagram.
  4. Simulate your overall system to show proper interconnections between modules.
  5. Finalize your block diagram and submit it with your report.

Design Requirements

Slow down the system so you stand a chance by running the game off of divided_clocks[15] (about 768 Hz). If later this still feels too fast or too slow, feel free to use a nearby divided_clock output.

Generate the computer's random button presses using the following procedure:

  1. Read an unsigned binary value from SW8-SW0 (a value from 0 to 511).
  2. Using the adder you designed earlier, add the switch value to the LFSR output (another 9-bit unsigned value from 0 to 511).
  3. If and only if the sum is ≥ 512, the cyber player presses its button. Think carefully about how to determine if the result is ≥ 512 – there is a trivial implementation that will make your life easier!

The switch settings will bias how frequently the cyber player presses its button, making it tunable. Play with the switches to adjust the cyber player's mashing/pulling speed, to see how fast you can go!

Grading

Working Design

100 points for correctness, style, and testing. Include the following files in your Gradescope submission:

  • Your lab6_report.pdf
  • Your project's SystemVerilog files
  • The .map.rpt timing report file from your project's output_files directory

Bonus

Up to 10 points for developing the smallest circuit possible. Follow the same protocal as in Lab 5. Submit your unoptimized SV files to Gradescope first, before attempting to optimize, to ensure you don't lose your working version of the lab. Your final or "active" submission is what we will grade. Note that the "Resource Utilization by Entity" report will give you the sizes of each of the modules in your design, so you can focus your sizing improvement efforts accordingly.


Rubric

Grading Criteria
Points
Q1: Top-level block diagram of your system
6 pts
    ●   Explanation of modules and interconnections
4 pts
Q2: ModelSim screenshot of 3-bit counter
3 pts
    ●   Explanation of waveforms
2 pts
Q3: 4-bit LFSR state diagram
6 pts
    ●   Explanation of diagram
4 pts
Q4: ModelSim screenshot of 9-bit LFSR, with the state cycle length indicated.
3 pts
    ●   Explanation of waveforms
2 pts
Q5: ModelSim screenshot of 9- or 10-bit adder, including the 6 required situations
3 pts
    ●   Explanation of waveforms
2 pts
Q6: ModelSim screenshot of top-level module
6 pts
    ●   Explanation of waveforms
4 pts
Q7: Screenshot of Resource Utilization
8 pts
    ●   BONUS for small resource utilization
(10 pts)
Time spent
2 pts
SystemVerilog code uploaded
5 pts
LAB DEMO
40 pts
Explain your top-level block diagram.
6 pts
Demonstrate the simulation of your overall CyberWar design.
6 pts
Demonstrate your CyberWar system working on the DE1 board.
16 pts
Be prepared to answer questions on both the theoretical and practical parts of the lab.
12 pts
 
100 pts