Lab 9

Feed a processor from synchronous instruction memory

You have two clocks. One presents the next word from a 32 × 16 ROM. The other steps the processor. Predict what happens if you pulse the processor clock twice without advancing the memory. Then predict what happens if you advance the memory while Run is low.

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

Prepare a program

Read program.mif. Addresses and words are hexadecimal. Write the first six addresses and identify which register each instruction changes. At addresses 06–1F, 0000 copies r0 to itself. Select one immediate operand to change and predict the final r7.

Build

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

The starter can execute the first instruction but then skips a ROM address. Use the independent memory clock to find the faulty step. Repair it and synthesize. This version uses a portable, synchronously read ROM. The original handout also explains how to generate a ROM in the Quartus IP Catalog.

Simulate

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

Start with the original program. The bench checks all 32 addresses, wraps back to zero, and reads all eight registers after each instruction. After word 05 it prints the two bytes of r7 as a single hexadecimal value. Compare it with your prediction and the two bytes you read on the board.

test_rom.v

test_rom.vhd

Verilog

iverilog -g2005 -s test_rom -o bench starter/rom_cpu.v simulation/test_rom.v
vvp bench

SystemVerilog

iverilog -g2012 -s test_rom -o bench starter/rom_cpu.sv simulation/test_rom.v
vvp bench

VHDL

nvc --std=2008 -a starter/rom_cpu.vhd simulation/test_rom.vhd
nvc --std=2008 -e test_rom
nvc --std=2008 -r test_rom

Run the six words

Lower SW0 to clear both circuits, then raise it. Leave SW9 low. Pulse KEY0 once to load address 00. With SW4 up, read its low byte on LED7–0, then raise SW8 to read its high byte. Lower SW4, select the destination register on SW7–5, and lower SW8. Raise SW9 and pulse KEY1 once to fetch. Lower SW9. Pulse KEY1 once more for move or move-top and three more times for add or subtract. LED9 indicates that the next processor edge writes the result. LED8 mirrors Run. Pulse KEY0 once for the next word and repeat.

Address Instruction word Destination Value before Value after
00 r2
01 r5
02 r2
03 r2
04 r4
05 r7

Read and record both bytes of r7 for the original program.

Change one instruction

Save your address-counter repair in the HDL file inside starter/. Change the immediate you selected in program.mif. From the folder containing activity.md, run the ROM loader on your repaired design.

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

Verilog

python3 simulation/prepare_rom.py simulation/program.mif starter/rom_cpu.v --output my_rom_cpu.v

SystemVerilog

python3 simulation/prepare_rom.py simulation/program.mif starter/rom_cpu.sv --output my_rom_cpu.sv

VHDL

python3 simulation/prepare_rom.py simulation/program.mif starter/rom_cpu.vhd --output my_rom_cpu.vhd

In the testbench you used above, change the entry in words at the address you edited to your predicted instruction word. Rerun the simulation commands with your generated HDL file in place of the starter file. Compare the new r7 value with your prediction.

Copy the generated HDL into the same top-level design you used for the first run and compile it again. Upload the new build to the DE1-SoC, reset the memory and processor with SW0 and repeat the six words. Hand in the changed MIF line, both r7 values read from the board, and one example showing how the two clocks act independently.

Original LabsLand materials following FPGAcademy Digital Logic Lab 9, Part II. Verilog handout · VHDL handout · MIT