Lab 10

Display a 16-bit count in decimal

Your processor counts in binary. Turn its value into five decimal digits and display them on HEX4–0. HEX5 stays blank. This time the starter appears to work at small values, so choose a test that can expose its mistake. You'll use Python 3 to assemble your program and your selected tool to build for the FPGA.

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 decimal_cpu.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

Predict a boundary

Before starting the processor, SW4–3 selects a test value. The settings 00, 01, 10 and 11 start at 0, 9, 99 and 65534 respectively. SW2–0 sets the delay as in Part VI. What five digits should appear after 65535? Why does a test beginning at 9 provide incomplete evidence for a 16-bit counter?

Assemble the starter

Choose Download activity and files in the setup panel. Extract the ZIP and open the folder containing activity.md. It includes the assembler, the simulation and the starter for your selected HDL.

Read decimal_counter.s. The program keeps the counter in r0. Trace how it copies that value, counts powers of ten and restores the remainder after a subtraction borrows. Run these commands on the unchanged program first.

If the assembler reports an error, correct the indicated line and assemble again before loading the memory image. A failed build leaves any previous .mif in place.

On Windows with the Python launcher, use py -3 wherever a command starts with python3.

Verilog

python3 simulation/sbasm.py simulation/decimal_counter.s decimal.mif
python3 simulation/load_program.py decimal.mif starter/decimal_cpu.v --output my_decimal_cpu.v

SystemVerilog

python3 simulation/sbasm.py simulation/decimal_counter.s decimal.mif
python3 simulation/load_program.py decimal.mif starter/decimal_cpu.sv --output my_decimal_cpu.sv

VHDL

python3 simulation/sbasm.py simulation/decimal_counter.s decimal.mif
python3 simulation/load_program.py decimal.mif starter/decimal_cpu.vhd --output my_decimal_cpu.vhd

Simulate

Extract the worksheet ZIP and run these commands from the folder containing activity.md. The simulator reads the HDL file you generated in the build step.

The accelerated bench reads the six external pin patterns and tests starts at 0, 9, 99 and 65534. It checks decimal carries, 16-bit rollover and the relative pacing.

Run the bench once before editing the assembly. It reads the digits as soon as the program finishes writing HEX0. If the first five-digit reading differs from the selected start, write both values in hexadecimal. Which bits survived the conversion? Reassemble, regenerate the HDL and run the same bench after your edit.

test_decimal.v

test_decimal.vhd

Verilog

iverilog -g2005 -s test_decimal -o bench my_decimal_cpu.v simulation/test_decimal.v
vvp bench

SystemVerilog

iverilog -g2012 -s test_decimal -o bench my_decimal_cpu.sv simulation/test_decimal.v
vvp bench

VHDL

nvc --std=2008 -a my_decimal_cpu.vhd simulation/test_decimal.vhd
nvc --std=2008 -e test_decimal
nvc --std=2008 -r test_decimal

Build

Use the HDL file you regenerated after the simulation passed. Keep the top-level name decimal_cpu.

  1. In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
  2. Create decimal_cpu, 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.

Observe the carries

Lower SW9. Set SW4–3 for the starting value and use SW2–0 = 111 to make the digits easy to read. Wait two seconds for the switches to settle. Pulse KEY0 once, then raise SW9. Record two successive stable readings. Repeat from reset for each row.

Start selection Before the carry After the carry
01
10
11, first increment
11, second increment

Test two delay settings from the same starting value. Explain which operations change the speed and which change the representation. Submit the changed instruction, the camera readings and a short trace of the division into decimal places for 100.

Based on FPGAcademy Digital Logic Lab 10. Verilog handout · VHDL handout · MIT license