Feed a processor from synchronous instruction memory
Online version: https://fpga.labsland.com/altera/digital-logic/lab-09/part-02/
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
LabsLand Online Editor · DE1-SoC
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.
Build
- From the extracted worksheet folder, open
starter/rom_cpu.qpfin the selected release of Quartus Prime Lite with Cyclone V support. The project-only download has the QPF at its root. - Edit the HDL file for
rom_cpu. If the exercise generates a new HDL file, copy its contents into that same project file. - Choose Processing → Start Compilation. Check the Fitter report for device 5CSEMA5F31C6.
- In the LabsLand bitstream upload lab, choose Standard and upload
output_files/rom_cpu.sof. Wait for programming confirmation before using the controls. - If your course uses a LabsLand classroom, the upload opens a firmware library instead: check that your SOF is selected and choose Enter board with selected firmware.
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.
- Get the starterDownload
rom_cpu.v - Open the LabsLand Online EditorOpen the lab Choose DE1-SoC · Verilog when you open the lab. LabsLand asks you to sign in. Use the access your course or institution provides.
- Follow the worksheetPredict first, then build, read the board and hand in. The build steps are below.
- Install Quartus Prime Lite with Cyclone V supportSkip this if it is already installed.
- Download the activityDownload worksheet and Quartus project Includes the worksheet, the Quartus project and the simulation files.
- Complete the design and compileStart with Prepare a program in the worksheet below, then complete the design as its build steps describe. Open
rom_cpu.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/rom_cpu.sof. - Upload the bitstream to LabsLandUpload bitstream LabsLand asks you to sign in. Use the access your course or institution provides.
Already compiled? Upload your .sof directly
Starter files · Verilog · VHDL · SystemVerilog
Worksheet and starter (.zip) for offline work or printing
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
- In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
- Create
rom_cpu, paste the design and set it as the top level. - 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.
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
