Lab 5

Count to nineteen with a pushbutton

Design a counter that repeats every twenty presses. LEDR4…0 show the count in binary. LEDR9 lights for one count to warn that the next press will return the value to zero.

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

Predict the rollover

Write down the five count bits and the warning light at 18, 19 and 0. How many different values would four bits represent? Choose a width that can represent every value from zero through nineteen.

Build

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

WIDTH sets the number of counter bits and MODULUS sets the number of states. Find the comparison that drives the warning light. Correct it so the last state is visible for a whole button press. Leave WIDTH at 5 and MODULUS at 20 for the board.

Simulate two sizes

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

The testbench checks two counters with the same button inputs, one with twenty states and one with five. Run it on the starter first and note the first failing count. Then run it on your correction. A complete run checks 42 press/release pairs and reset between presses.

test_modulo_count.v

test_modulo_count.vhd

Verilog

iverilog -g2005 -s test_modulo_count -o bench starter/modulo_count.v simulation/test_modulo_count.v
vvp bench

SystemVerilog

iverilog -g2012 -s test_modulo_count -o bench starter/modulo_count.sv simulation/test_modulo_count.v
vvp bench

VHDL

nvc --std=2008 -a starter/modulo_count.vhd simulation/test_modulo_count.vhd
nvc --std=2008 -e test_modulo_count
nvc --std=2008 -r test_modulo_count

Test the board

Synthesize and upload. Press KEY0 once to reset. Each press on KEY1 should advance by one, and releasing it should leave the count unchanged. Wait until the camera shows the new count before pressing again. Pause before each of the last three presses so you can record the warning light.

Number of KEY1 presses after reset LEDR4…0 LEDR9
1
18
19
20
21

Press KEY0 while the count is nonzero and leave KEY1 alone. Explain what this observation tells you about asynchronous reset. Submit the predictions, the simulation result for each width, and your board observations.

Source

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