Lab7: Building with Blocks

Time Estimate2-4 Hours   Grade Impact2.5%   DueNov 4 @ 3pm   Required for Pass  

Objective
Reinforce modular design techniques by constructing, testing, and connecting multiplexers and decoders. Use the Basys 3 switches, buttons, and LEDs to make these blocks visible and interactive.

Warning
Before starting any lab, always read the entire lab description. You are working with expensive, fragile hardware. Look particularly closely at these boxes, which warn you of potential problems.


Before the Lab

Repository

Create a repository for this assignment and add your instructor and TA as collaborators.

Equipment

Please bring the following equipment to this lab:

  • Digilent Basys 3 FPGA board
  • Compatible (power-and-data) USB cable
  • Note taking mechanism (laptop, notebook, etc.)

Pre-Lab Work

This lab has pre-lab work, specified below. Pre-lab work is due within the first 30 minutes of the lab session designated for this lab (that is, 3:00pm on October 14).

Pre-Lab

This lab uses two basic components: a decoder and a multiplexer (MUX).

3-to-8 Decoder

A 3-to-8 decoder has an address input $d$, an enable input $en$, and eight output wires indexed from 0 to 7.

  • When $en = 0$, all outputs are 0.
  • When $en = 1$, the output indexed by $d$ is 1, and all other outputs are 0.

Given this behavior, show how you can make a 4-to-16 decoder (with an enable bit) by interconnecting 3-to-8 decoders, inverter(s), and AND/OR/NAND/NOR gate(s).

2-to-1 MUX

Recall that a MUX has one output $out$, two signal inputs $i_0$ and $i_1$, and a select input $sel$.

  • When $sel = 0$, $out = i_0$.
  • When $sel = 1$, $out = i_1$.

Its behavior is expressed as:

$$ out = \overline{sel},i_0 + sel,i_1 $$

Use multiple 2-to-1 MUXes and inverters to construct a 4-to-1 MUX.

Deliverable Checkpoint
Submit your pre-lab work (on Canvas or in-person).

In the Lab

You may implement blocks with structural module instances, case statements, or Boolean expressions, unless a task specifically requires a particular style. Keep the decoder and MUX in separate modules so they can be reused.

Scaffolding Going Away
You’re halfway through the course, and you have implemented a wide variety of modules in Verilog. I have full confidence in your ability to implement these modules without so much starter code. If you’re stuck, check out trustworthy resources, such as this Verilog reference(external link) , your textbook, or your instructor/TA.

Build and test some building blocks

Implement and test these modules:

  1. 2-to-1 MUX
    Inputs: i0, i1, sel. Output: out.

  2. 4-to-1 MUX
    Inputs: i0–i3, sel[1:0]. Output: out.
    Construct it from your 2-to-1 MUX module, following your pre-lab design.

  3. 3-to-8 decoder
    Inputs: d[2:0], en. Output: y[7:0].
    Confirm that the outputs are one-hot when enabled and all zero when disabled.

  4. 4-to-16 decoder
    Inputs: d[3:0], en. Output: y[15:0].
    Construct it from 3-to-8 decoders and the required gating logic. You may use a small helper module for the gating.

For each module, test all input combinations. Record any mistakes caught by your tests.

Verilog hints
Make the input and output widths explicit in each module declaration. For example, an address for a 3-to-8 decoder needs three bits, while its output needs eight. A width mismatch may compile but still produce confusing behavior.

A combinational decoder can be described with a case statement inside an always @* block, or with continuous assignments. In a case statement, assign a default value to the entire output vector before handling the enabled address cases. This avoids inferring a latch.

To make the 4-to-1 MUX from 2-to-1 MUXes, declare wires for the two intermediate results. To make the larger decoder, declare wires for each smaller decoder’s output. These intermediate wires are the connections between blocks.

For an enabled decoder, exactly one output should be 1. For example, if d = 3'b101, then y[5] should be 1. Check this property.

Deliverable Checkpoint
Demonstrate the testbench results from each of these four modules. Describe your debugging process.

Make the blocks visible on your FPGA

Connect the board I/O using the supplied constraints. Use switches for stable data and address inputs, buttons for enable or selection controls, and LEDs to display results. You may choose which available switches, buttons, and LEDs to use, but document your choices.

Verilog hint: top-level wiring
The top-level module is the bridge between FPGA pins and your reusable blocks. Connect board inputs to module inputs and module outputs to board outputs. Avoid adding unnecessary logic to the top-level module; keep the decoder and MUX behavior in their own modules.

A. Decoder explorer

Connect three switches to the 3-to-8 decoder address, one button or switch to en, and the eight decoder outputs to eight LEDs.

Demonstrate:

  • The LED pattern for at least three different addresses.
  • The output pattern when en is off.
  • That changing the address while disabled does not light an output.

Deliverable Checkpoint
Demonstrate the working FPGA implementation.

B. MUX data selector

Connect four switches to the four 4-to-1 MUX data inputs and two switches to the select input. Display the MUX output on an LED.

Set the four data switches to different values—for example, 0, 1, 0, 1—then cycle through all four select values. Explain why the output follows the selected input and not the other three.

Verilog hint: vector slices
If your top-level switch input is a vector, you can connect individual switches or slices of it to module ports. Check that each connection has the same width as the destination port.

Deliverable Checkpoint
Demonstrate the working FPGA implementation.

C. Switch-versus-button experiment

Use a button as the MUX select input. Hold the data switches at values that make the output easy to see, then press and release the button.

Mindfully observe this experience. Does the output change only once, or can it appear to flicker while the button is pressed? Why might a physical button not behave like a perfectly clean digital signal?

Interconnect the blocks

Build at least two of the following configurations. Demonstrate each one on the board and include a block diagram in your submission.

Verilog hint: intermediate signals
Now that your model is more complex, give intermediate wires names that describe their role, such as selected_data or decoded_line. Meaningful names make it easier to compare your HDL to your block diagram.

  1. Decoder-controlled data choice
    Use decoder outputs to control which of several data values is allowed through to an LED. For example, combine a decoder output with a switch value using an AND gate, then OR the results. Show that changing the address selects which data path can affect the LED.

  2. MUX as a decoder-output viewer
    Feed selected decoder outputs into a MUX and display the MUX output on an LED. Use switches for the address and MUX select bits. Predict the output before testing at least two settings, then compare your prediction with the board.

  3. Address-to-pattern selector
    Use a decoder address to select one of several patterns made from switches or logic values. Display the selected result on one or more LEDs. Explain how the decoder and MUX contribute different jobs to the design.

  4. Your own interconnection
    Combine at least one decoder and one MUX in a useful or surprising way. State what you expect the circuit to do, draw the connections, and then demonstrate whether it behaves as expected.

Verilog hint: keep it combinational
These designs are combinational: their outputs depend on the current inputs, not on a stored value. Use continuous assignments or a combinational always @* block. If using an always block, assign every output on every possible path.

Deliverable Checkpoint
A decoder activates one output based on an address; a MUX selects one input to send to an output. They can seem like opposite operations. In your own words, explain what information each block uses and where the information goes.

Your turn

Design one small interactive feature using the Basys 3 switches, buttons, and LEDs. It must use at least one decoder and one MUX. Examples include:

  • A selectable LED indicator or status panel.
  • A switch-controlled “which input wins?” demonstration.
  • A simple pattern selector.

Your design should be simple enough to explain in a minute or two.

Test your design in simulation first. Choose a few input combinations that demonstrate both normal behavior and boundary cases—for example, the first and last addresses, and a disabled decoder.

Deliverable Checkpoint
Demonstrate your working implementation, optionally showing it off to your classmates.

Deliverables

Indicate to your instructor that you’re ready to submit your work by leaving a comment on the Feedback PR and requesting a review from @mossbiscuits. Ensure that your submission is on the main branch. Create a tag named done to mark your submission:

git tag -a done -m "Lab7 submission"
git push origin done

If you took photos, screenshots, or videos, remember to upload them to Box or OneDrive and link to them in the Feedback PR. Alternatively, you can submit these items directly on Canvas.

To receive 100 points, submissions must include evidence of the following:

  • (20) Correct and timely completion of the pre-lab work
  • (20) 5 points for each building block simulation
  • (20) 5 points for each building block implementation
  • (20) Interconnection of blocks
  • (20) Creative implementation