Lab 7

Recognize four equal samples with two shift registers

You are building a detector that lights LED9 on the fourth successive zero or one. A fifth identical input should keep the light on. Two four-bit shift registers make the last four samples visible. Each press and release of KEY0 records one input.

SW0 is an active-low synchronous reset. SW1 supplies the data bit. LED3–0 show recent ones, LED7–4 show recent zeros, and LED8 stays dark to separate the result lamp. Within each group the newest sample is on the right. Predict which register bit first lights after a reset followed by one high sample.

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

Simulate

Extract the worksheet ZIP. Run the testbench below with the supplied starter. Record the first failing input and bit position. Inspect the expression for found: which four stored bits must agree before the ones history qualifies? Edit the starter and rerun the same commands. Continue when the simulator prints PASS 256 eight-sample inputs and all 2048 clock edges.

The testbench applies every eight-symbol sequence. It counts consecutive identical symbols independently and checks both histories, reset and the result lamp.

test_history.v

test_history.vhd

Verilog

iverilog -g2005 -s test_history -o bench starter/history_detector.v simulation/test_history.v
vvp bench

SystemVerilog

iverilog -g2012 -s test_history -o bench starter/history_detector.sv simulation/test_history.v
vvp bench

VHDL

nvc --std=2008 -a starter/history_detector.vhd simulation/test_history.vhd
nvc --std=2008 -e test_history
nvc --std=2008 -r test_history

Build

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

Read both histories

On the programmed board, lower SW0 and press and release KEY0 once to reset. Raise SW0 and SW1 without pressing KEY0. Read the LEDs, then record five high samples and five low samples. Finish with 1, 0, 1, 0. Read LED9 on the third, fourth and fifth samples of each run. Which release first produces a match?

Point in the sequence Zeros (LED7–4) Ones (LED3–0) Match (LED9)
Input high before the first release
Third, fourth and fifth one
First, fourth and fifth zero
After the alternating tail

Lower SW0 and read the LEDs before and after the next KEY0 release. Raise SW0, leave SW1 low and record the first zero of the new sequence. Explain why the two histories become complementary only after four valid samples. Propose a design with a single history and a way to suppress premature matches after reset.

Original LabsLand activity following FPGAcademy Digital Logic Lab 7, Part III. verilog PDF · vhdl PDF · MIT