Lab 2

Convert a binary nibble to decimal

Digital Logic · Lab 2, Part II · DE1-SoC

This time SW3…0 represents one unsigned binary number. Its maximum value is fifteen. Use two displays to show its decimal value, from 00 to 15. The digit decoders from Part I are supplied. Your job is to choose the correct two digits.

Lab setup

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.

  1. Get the starterDownload binary_to_decimal.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 conversion

Draw three blocks. A comparator produces z when the input is greater than nine. A correction network converts 1010…1111 to 0000…0101. A four-bit multiplexer selects the original nibble when z is zero and the corrected value when z is one. The tens digit is z padded to four bits. Fill in the six correction rows and mark the other ten inputs as don't-cares for that network. Which two input bits distinguish 8 and 9 from the six numbers that need correction?

Download and extract the complete worksheet. Edit starter/binary_to_decimal with the extension for your HDL. Complete the comparator and correction equations with Boolean operators. Implement the multiplexer with bit masks. Keep both digit decoders and use continuous or concurrent assignments throughout the converter.

Simulate the design

Run the testbench from the extracted worksheet folder. The testbench changes the input every 10 ns and saves the waveform in conversion.vcd.

trace_tb.v

trace_tb.vhd

Verilog uses Icarus Verilog.

iverilog -g2005 -s trace_tb -o bench starter/binary_to_decimal.v simulation/trace_tb.v
vvp bench

SystemVerilog uses Icarus Verilog with SystemVerilog enabled.

iverilog -g2012 -s trace_tb -o bench starter/binary_to_decimal.sv simulation/trace_tb.v
vvp bench

VHDL uses NVC with VHDL-2008.

nvc --std=2008 -a starter/binary_to_decimal.vhd simulation/trace_tb.vhd
nvc --std=2008 -e trace_tb
nvc --std=2008 -r trace_tb --format=vcd --wave=conversion.vcd

Open conversion.vcd in a waveform viewer such as Surfer. In trace_tb → dut, add v, z, adjusted, ones_digit, HEX1 and HEX0. Read the signals between stimulus changes. At 95 ns you are observing input 9. Move the cursor to 105 ns for input 10. Identify the comparator output, the selected multiplexer input and the active-low digit output. Repeat at 155 ns, then check all sixteen input words on the board.

Run each input from 0 to 15 in functional simulation. Record v, z, adjusted, ones_digit and both HEX outputs. At 9 and 10 inspect all three blocks. At 8 explain why adjusted has no effect on the result.

Build

  1. In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
  2. Create binary_to_decimal, paste the design and set it as the top level.
  3. Choose Synthesize → Upload to FPGA. After editing the design, synthesize and upload it again to test the change on the board.

Read the board

Binary input Decimal output predicted Simulated HEX1 HEX0 Camera HEX1 HEX0
0000–0011
0100–0111
1000–1011
1100–1111

Write four two-digit readings per row. Locate HEX1 and HEX0 on the board camera. Use the four lowest switches to step through the sixteen inputs. Leave the six higher switches unchanged. If a digit looks like a letter, check whether you bypassed the decimal correction.

Hand in

Submit the six-row truth table, your comparator expression, the 9→10 simulated trace and all sixteen hardware readings. Explain why the ones digit must fall from 9 to 0 at the same transition that turns the left digit from 0 to 1.

Adapted from FPGAcademy Digital Logic 21.1, Verilog Lab 2, Part II and the VHDL edition. LabsLand wrote the programs, tests and worksheet. MIT notice