Add two decimal digits with gates
Online version: https://fpga.labsland.com/altera/digital-logic/lab-02/part-04/
Two students can look at the same board and read the sum in different number systems. LEDR4…0 show the raw binary sum. HEX1 and HEX0 show the same number in decimal. HEX5 shows X on SW7…4, HEX3 shows Y on SW3…0, and SW8 supplies the carry-in.
Lab setup
LabsLand Online Editor · DE1-SoC
Physical DE1-SoCCyclone V · 5CSEMA5F31C6 · camera, switches and buttons in the browser
Build in Quartus and upload the bitstream
Download and extract the Quartus project for your HDL. Open bcd_gates.qpf in Quartus Prime Lite with the Cyclone V device package. Edit the bcd_gates design. Build the binary full-adder chain, decimal correction and invalid-input flag using gates. Use your sketch to identify the signals for the physical tests.
Choose Processing → Start Compilation. Verify that the fitter completed for 5CSEMA5F31C6. In the DE1-SoC binary upload lab, choose Standard, upload output_files/bcd_gates.sof and wait for the programming confirmation. Locate the LED or HEX labels on the board camera before taking your readings.
If your course uses a LabsLand classroom, the upload opens a firmware library instead. Choose Browse files, wait until the SOF is selected, then choose Enter board with selected firmware.
- Get the starterDownload
bcd_gates.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 and the Quartus project.
- Complete the design and compileStart with Design the circuit in the worksheet below, then complete the design as its build steps describe. Open
bcd_gates.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/bcd_gates.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
Design the circuit
The circuit already contains a four-stage ripple adder. Find its four sum bits and final carry. Design a signal that is high whenever the raw five-bit result is at least ten. Use Boolean gates to correct the low nibble to a decimal ones digit. Consider both 10–15 and 16–19. The left decimal digit can only be zero or one. Keep the two input displays and the invalid-input indicator connected.
Build
Download the starter in your HDL. In the DE1-SoC Online Editor, choose Standard and set bcd_gates as the top level. Synthesize, upload the program and wait for the physical board camera.
Test the board
| X | Y | Carry-in | Predicted LEDs and decimal digits | Camera reading |
|---|---|---|---|---|
| 0 | 0 | 0 | ||
| 5 | 4 | 0 | ||
| 5 | 4 | 1 | ||
| 9 | 7 | 0 | ||
| 9 | 9 | 1 |
Set X to binary 1010 with Y zero. Then set X zero and Y to 1100. Record LEDR9 in each case. Decimal results are specified only when both inputs are valid digits. Return all switches to zero before leaving.
Hand in
Submit your decimal-carry equation, an annotated trace for 9 + 9 + 1 and the camera observations. Explain why checking the carry out of bit 3 alone misses a decimal carry.
Adapted from FPGAcademy Digital Logic 21.1 · Lab 2, IV · Verilog, VHDL. Original LabsLand programs, tests and worksheet. MIT
