Lab 7

Trace a nine-state sequence detector on the LEDs

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

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

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.

test_one_hot.v

test_one_hot.vhd

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.

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

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