Build a counter from toggle flip-flops
Online version: https://fpga.labsland.com/altera/digital-logic/lab-04/part-01/
Build an eight-bit synchronous counter, then inspect a four-bit version in Quartus. You will need Quartus Prime Lite with Cyclone V support and access to the LabsLand DE1-SoC bitstream uploader. You can do the prediction and simulation before reserving a board.
Lab setup
Quartus Prime Lite 24.1 · Verilog · DE1-SoC
Physical DE1-SoCCyclone V · 5CSEMA5F31C6 · camera, switches and buttons in the browser
This activity requires Quartus RTL Viewer. Use desktop Quartus to compare the schematics, then test your bitstream on the remote board.
Build
Download the worksheet ZIP for your HDL and Quartus release. Open project/toggle_counter.qpf. The starter propagates the enable incorrectly between stages. Repair it and run the simulation below. Compile with Processing → Start Compilation. In Compilation Report → Fitter → Resource Section record the register and ALM counts. Include the display logic in your interpretation of the fit.
In the same worksheet ZIP open comparison-project/toggle_four.qpf. Apply the same repair, compile, and open Tools → Netlist Viewers → RTL Viewer. Trace the common clock and the enable path to each of the four registers. Which signals feed the toggle input of the highest stage? Keep a screenshot with that path marked.
- Install Quartus Prime Lite with Cyclone V supportSkip this if it is already installed.
- Download the activityDownload worksheet and both Quartus projects Includes the worksheet, the Quartus project, a second project for comparison and the simulation files.
- Complete the design and compileStart with Predict the carry in the worksheet below, then complete the design as its build steps describe. Open
toggle_counter.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/toggle_counter.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 · Quartus 24.1 · VHDL · Quartus 24.1 · SystemVerilog · Quartus 24.1
Worksheet and Quartus project (.zip) for offline work or printing
Predict the carry
All eight flip-flops share one clock. Write the condition that makes bit 0 toggle. Write the conditions for bits 1 and 2, and use them to predict which bits change at 03 → 04 and 0F → 10. Look for that pattern in the generated stages of toggle_counter.
Build
Download the worksheet ZIP for your HDL and Quartus release. Open project/toggle_counter.qpf. The starter propagates the enable incorrectly between stages. Repair it and run the simulation below. Compile with Processing → Start Compilation. In Compilation Report → Fitter → Resource Section record the register and ALM counts. Include the display logic in your interpretation of the fit.
In the same worksheet ZIP open comparison-project/toggle_four.qpf. Apply the same repair, compile, and open Tools → Netlist Viewers → RTL Viewer. Trace the common clock and the enable path to each of the four registers. Which signals feed the toggle input of the highest stage? Keep a screenshot with that path marked.
Simulate
Extract the complete worksheet ZIP. In the folder containing activity.md, run the commands below with Icarus Verilog for Verilog or SystemVerilog, or NVC for VHDL. The bench checks every count through rollover, then holds and clears the counter.
Verilog
iverilog -g2005 -s test_toggle_counter -o bench project/toggle_counter.v simulation/test_toggle_counter.v
vvp bench
SystemVerilog
iverilog -g2012 -s test_toggle_counter -o bench project/toggle_counter.sv simulation/test_toggle_counter.v
vvp bench
VHDL
nvc --std=2008 -a project/toggle_counter.vhd simulation/test_toggle_counter.vhd
nvc --std=2008 -e test_toggle_counter
nvc --std=2008 -r test_toggle_counter
Run the four-bit comparison from the same folder.
Verilog
iverilog -g2005 -s test_toggle_four -o bench comparison-project/toggle_four.v simulation/test_toggle_four.v
vvp bench
SystemVerilog
iverilog -g2012 -s test_toggle_four -o bench comparison-project/toggle_four.sv simulation/test_toggle_four.v
vvp bench
VHDL
nvc --std=2008 -a comparison-project/toggle_four.vhd simulation/test_toggle_four.vhd
nvc --std=2008 -e test_toggle_four
nvc --std=2008 -r test_toggle_four
Test the bitstream
Upload output_files/toggle_counter.sof from the eight-bit project to the remote board. SW0 is active-low synchronous clear. SW1 enables counting. KEY0 supplies the clock. Press and release once with SW0 down. Raise both switches and step slowly, waiting for the camera to settle after each release. The right-hand display is the low nibble.
| Action | Predicted HEX1–0 | Observed |
|---|---|---|
| Count through 0E, 0F and the next step | ||
| Lower SW1 and pulse KEY0 | ||
| Lower SW0 without pulsing KEY0 | ||
| Pulse KEY0 with SW0 down |
Compare the four-bit and eight-bit fitted resources. Explain why the change in ALMs need not equal the change in register count. Submit your trace, the marked RTL view and two adjacent readings across a carry.
FPGAcademy · Digital Logic · Lab 4 · I. VERILOG · VHDL · MIT
