Lab 2

Add two decimal digits with gates

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

Physical DE1-SoCCyclone V · 5CSEMA5F31C6 · camera, switches and buttons in the browser

  1. Get the starterDownload bcd_gates.v
  2. Open the LabsLand Online EditorOpen the lab LabsLand asks you to sign in. Use the access your course or institution provides.
  3. Follow the worksheetPredict first, then build, read the board and hand in. The build steps are below.

Starter files · Verilog · VHDL · SystemVerilog

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