Trace a nine-state sequence detector on the LEDs
Online version: https://fpga.labsland.com/altera/digital-logic/lab-07/part-01/
Design a circuit that recognizes four consecutive equal samples, including overlapping runs. Begin in A. Name the states for successive zeros B, C, D and E, and those for successive ones F, G, H and I. Sketch the arrows out of E and I for both possible next inputs. Which states should switch on the match lamp?
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
When the bench reports PASS 2048 clock edges, use the same repaired HDL for the board.
- From the extracted worksheet folder, open
starter/one_hot_runs.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
one_hot_runs. 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/one_hot_runs.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
one_hot_runs.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 Derive the register inputs in the worksheet below, then complete the design as its build steps describe. Open
one_hot_runs.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/one_hot_runs.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
Derive the register inputs
Use a flip-flop for each state. Give A bit 0, B bit 1, through I at bit 8. Write an equation for entering B, and another for remaining in E. Compare yours with the starter. Its reset and first four zeros work, but the next sample can lose an existing match. Repair the next-state logic. Explain why keeping the terminal state matters when windows overlap.
Simulate
Extract the worksheet ZIP and run these commands from the folder containing activity.md.
The bench counts identical samples independently and predicts the state code for both encodings after each clock edge. Find the first mismatch and use the failing word to repair the starter. The first check starts in B with a one on SW1. Predict what both LED patterns should show while KEY0 is held down and which state should appear when it is released.
Verilog
iverilog -g2005 -s test_one_hot -o bench starter/one_hot_runs.v simulation/test_one_hot.v
vvp bench
SystemVerilog
iverilog -g2012 -s test_one_hot -o bench starter/one_hot_runs.sv simulation/test_one_hot.v
vvp bench
VHDL
nvc --std=2008 -a starter/one_hot_runs.vhd simulation/test_one_hot.vhd
nvc --std=2008 -e test_one_hot
nvc --std=2008 -r test_one_hot
Build
When the bench reports PASS 2048 clock edges, use the same repaired HDL for the board.
- In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
- Create
one_hot_runs, 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.
Compare the two encodings on hardware
SW0 is an active-low synchronous reset. SW1 supplies the sample. Press and release KEY0 once per sample. LED8–0 show the state, and LED9 shows a match. The design includes a second copy with the A flip-flop inverted. SW2 selects which copy you see. Changing SW2 lets you inspect the same clock edge in each encoding.
Lower SW0, then press and release KEY0. Read both encodings. Raise SW0, select zero on SW1 and clock five times. Then select one and clock five times. Switch back to zero for one more edge. For each row, write all ten LEDs as one binary word with LED9 on the left. Underline the match bit (LED9) when it lights. Read the word with SW2 low, then high, keeping KEY0 released between readings. The arrows mark the first clock edge after the input changes.
| Observation | State | SW2 low | SW2 high |
|---|---|---|---|
| Reset | |||
| Third zero | |||
| Fourth zero | |||
| Fifth zero | |||
| 0 → 1 | |||
| Fourth one | |||
| Fifth one | |||
| 1 → 0 |
Lower SW0 while a non-reset state is visible. Compare the display before and after releasing KEY0. Submit your two transition equations, the first failing simulation sample and the pair of state codes at reset. Explain why the alternate encoding changes bit 0 even in states other than A.
Original LabsLand activity following FPGAcademy Digital Logic Lab 7, Part I. Verilog handout · VHDL handout · MIT
