Recognize four equal samples with two shift registers
Online version: https://fpga.labsland.com/altera/digital-logic/lab-07/part-03/
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
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/history_detector.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
history_detector. 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/history_detector.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.
- Get the starterDownload
history_detector.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 Simulate in the worksheet below, then complete the design as its build steps describe. Open
history_detector.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/history_detector.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
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.
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
- In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
- Create
history_detector, 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.
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
