Lab 8

Store and retrieve a nibble from 32 addresses

Build a memory from an HDL array of 32 four-bit words. You will write distinct values to addresses that differ by just their most significant bit. The last read value stays on the right-hand display while you prepare the next operation.

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

Build

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

SW8–4 select the address, SW3–0 supply a nibble, and SW9 selects write (high) or read (low). KEY0 performs the operation when released. HEX5–4 show the address in hexadecimal, HEX2 shows the input data and HEX0 shows the last completed read. HEX3 and HEX1 are blank. Work out how many flip-flops a simple register implementation would need for the stored bits alone.

Simulate

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

The testbench writes and reads every possible nibble at each of the 32 addresses. Before each read clock it checks that changing switches leaves the last result in place.

test_ram.v

test_ram.vhd

Verilog

iverilog -g2005 -s test_ram -o bench starter/inferred_ram.v simulation/test_ram.v
vvp bench

SystemVerilog

iverilog -g2012 -s test_ram -o bench starter/inferred_ram.sv simulation/test_ram.v
vvp bench

VHDL

nvc --std=2008 -a starter/inferred_ram.vhd simulation/test_ram.vhd
nvc --std=2008 -e test_ram
nvc --std=2008 -r test_ram

With the original starter, record the first address that fails. After you repair the read index, run the same commands again. Look for PASS 512 writes and 512 reads, address and data displays, registered hold.

Probe two addresses that look alike

Build the unchanged starter and program the DE1-SoC. Write A to address 00. Turn writing off, change the input nibble to F, and release KEY0 once. Then write B to address 10. Switch back to read mode with address 10 selected. Read HEX0 before and after the next key release. Changing the data switches in read mode should affect HEX2 immediately.

Hex address Value written Readback before repair Readback after repair
00 A
10 B
0F C
1F 3

Write the remaining two words from the table. Read all four addresses in a different order and fill in the before-repair column. Which address bit distinguishes each pair? Find where the read index loses that bit. After the repair, rerun the simulation, rebuild and program the board through the same workflow. Write all four words again before you fill in the after-repair column. Set up a write of 5 at 00 but turn off SW9 again before any KEY0 release. Test whether the previous word remains. Now perform that write and show which other addresses retained their contents. An unwritten location has no specified value in this exercise.

Original LabsLand activity following FPGAcademy Digital Logic Lab 8, Part III. Verilog handout · VHDL handout · MIT