Multiply two four-bit numbers with an array of adders
Online version: https://fpga.labsland.com/altera/digital-logic/lab-06/part-03/
Set A on switches SW7 through SW4 and B on SW3 through SW0. Each group represents one hexadecimal digit. Your circuit will show their product on the two leftmost displays. A single hexadecimal digit represents values up to 15. What is the largest product, and how many binary digits does it need?
Lab setup
LabsLand Online Editor · DE1-SoC
Physical DE1-SoCCyclone V · 5CSEMA5F31C6 · camera, switches and buttons in the browser
Run the simulation on your computer with Icarus Verilog (Verilog or SystemVerilog) or NVC (VHDL). Then build your design and test it on the remote DE1-SoC.
Build
- From the extracted worksheet folder, open
starter/array_product.qpfin the selected release of Quartus Prime Lite with Cyclone V support. The project-only download has the QPF at its root. - Edit the HDL file for
array_product. If the exercise generates a new HDL file, copy its contents into that same project file. - Choose Processing → Start Compilation. Check the Fitter report for device 5CSEMA5F31C6.
- In the LabsLand bitstream upload lab, choose Standard and upload
output_files/array_product.sof. Wait for programming confirmation before using the controls. - If your course uses a LabsLand classroom, the upload opens a firmware library instead: check that your SOF is selected and choose Enter board with selected firmware.
Locate the row selected by bit 2 of B. When A is 3, that row should contribute either 0 or 12. Draw its eight columns and fix the alignment of the partial product before it enters the row of full adders. Keep the sum and carry wiring. Use the same rule for all four rows.
- Get the starterDownload
array_product.v - Open the LabsLand Online EditorOpen the lab Choose DE1-SoC · Verilog when you open the lab. LabsLand asks you to sign in. Use the access your course or institution provides.
- Follow the worksheetPredict first, then build, read the board and hand in. The build steps are below.
- Install Quartus Prime Lite with Cyclone V supportSkip this if it is already installed.
- Download the activityDownload worksheet and Quartus project Includes the worksheet, the Quartus project and the simulation files.
- Complete the design and compileComplete the design as Build in the worksheet below describes. Open
array_product.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/array_product.sof. - Upload the bitstream to LabsLandUpload bitstream LabsLand asks you to sign in. Use the access your course or institution provides.
Already compiled? Upload your .sof directly
Starter files · Verilog · VHDL · SystemVerilog
Worksheet and starter (.zip) for offline work or printing
Build
- In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
- Create
array_product, paste the design and set it as the top level. - Choose Synthesize → Upload to FPGA. After editing the design, synthesize and upload it again to test the change on the board.
Locate the row selected by bit 2 of B. When A is 3, that row should contribute either 0 or 12. Draw its eight columns and fix the alignment of the partial product before it enters the row of full adders. Keep the sum and carry wiring. Use the same rule for all four rows.
Check all inputs
Extract the worksheet ZIP and run these commands from the folder containing activity.md.
The testbench checks all six display outputs against arithmetic multiplication for all 1,024 switch settings. Try the starter, record the first pair that fails, and repeat after aligning the rows.
Verilog
iverilog -g2005 -s test_array -o bench starter/array_product.v simulation/test_array.v
vvp bench
SystemVerilog
iverilog -g2012 -s test_array -o bench starter/array_product.sv simulation/test_array.v
vvp bench
VHDL
nvc --std=2008 -a starter/array_product.vhd simulation/test_array.vhd
nvc --std=2008 -e test_array
nvc --std=2008 -r test_array
Read your multiplier
Upload your repaired design and set the input pairs from the table. Look at HEX5 and HEX4 for the product, HEX2 for A and HEX0 for B. HEX3 and HEX1 separate the readings. Hexadecimal b and d appear in lowercase on the physical displays.
| A | B | Predicted product (hex) | Product on HEX5…4 |
|---|---|---|---|
| 3 | 1 | ||
| 3 | 2 | ||
| 3 | 6 | ||
| b | C | ||
| C | b | ||
| F | F |
For 3 × 6, identify the two rows that contribute. Swap the inputs of b × C and compare both the displayed product and your sketch of the active rows. Try changing SW8 and SW9 while the other switches stay still. Submit the table, one observed carry into the upper digit, and your sketch.
Original LabsLand activity following FPGAcademy Digital Logic Lab 6, Part III. Verilog handout · VHDL handout · MIT
