Lab 10

Give the processor six display registers

The CPU has one write bus. How can six displays each remember a different digit? You'll add a memory-mapped peripheral to the processor from Part III, then use an assembly program to write one display at a time.

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 display_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

Sketch the port

Allocate one 7-bit register to each of the word addresses 0x2000 through 0x2005. In your diagram, show which address bits select the peripheral, which select one digit, and where the write enable enters. A software pattern uses 1 for a lit segment. A physical HEX pin uses 0 for a lit segment. Mark the single place where the polarity changes. What must addresses 0x2006 and 0x2007 do?

Test the address decoder

Download the complete activity for your HDL and extract it. Run the bench once with the unchanged starter. Which selector first leaves a display blank when you expected a digit?

Extract the worksheet ZIP and run these commands from the folder containing activity.md.

The bench tries every ordered pair of the eight selectors. It checks all six pin patterns after reset, writes, unused addresses and switch changes during a halt.

test_display.v

test_display.vhd

Verilog

iverilog -g2005 -s test_display -o bench starter/display_cpu.v simulation/test_display.v
vvp bench

SystemVerilog

iverilog -g2012 -s test_display -o bench starter/display_cpu.sv simulation/test_display.v
vvp bench

VHDL

nvc --std=2008 -a starter/display_cpu.vhd simulation/test_display.vhd
nvc --std=2008 -e test_display
nvc --std=2008 -r test_display

Find the display write enable in the starter HDL. HEX0 accepts a write, but the other five registers ignore theirs. Repair the decoder so each valid address updates only its own register. Keep addresses 0x2006 and 0x2007 harmless. Run the same commands again and look for PASS all 64 ordered address pairs, retention, halt and reset.

Build

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

Write the digits

Lower SW9 and pulse KEY0 once. Look at all six digits on the live camera. With the processor stopped, set SW2–0 to the next selector. Raise SW9 to let the program write, then lower it before changing the selector. Changing several switches while running can briefly write an intermediate address.

Selector sequence Predict HEX5 through HEX0; use a dash for blank Observed
Reset, then 4
Then 1, then 7
Then 0, then 5
Then 6, then 2, then 3
Reset while stopped
Select 3 and run again

Explain how the visit to address 0x2007 distinguishes an unused address from an alias. Include a camera observation that proves a digit retained its earlier value while a different digit was written.

Read the assembly

In display_digits.s, find the two additions using the same selector. Explain why one address points to RAM and the other to a display register. Which instruction actually changes a digit? For an optional experiment, change the fourth pattern word (selector 3) from 0x4F to 0x40. Sketch the segments you expect to light. Run these commands from the worksheet folder, keeping your decoder repair in the starter file.

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/display_digits.s digits.mif
python3 simulation/load_program.py digits.mif starter/display_cpu.v --output my_display_cpu.v

SystemVerilog

python3 simulation/sbasm.py simulation/display_digits.s digits.mif
python3 simulation/load_program.py digits.mif starter/display_cpu.sv --output my_display_cpu.sv

VHDL

python3 simulation/sbasm.py simulation/display_digits.s digits.mif
python3 simulation/load_program.py digits.mif starter/display_cpu.vhd --output my_display_cpu.vhd

Copy the generated HDL back into the same design file you just tested. Repeat the build and upload steps, reset with SW9 low, select 3 and raise SW9. Sketch HEX3 and label the blank digits “off”. Which segment lights on HEX3? Lower SW9, select 1, then raise SW9 and check whether HEX3 retains its new pattern.

Submit your address diagram, observations and a short explanation of the active-low outputs.

Adapted from the FPGAcademy processor exercise. Verilog handout · VHDL handout · MIT license