Carry a count across three decimal digits
Online version: https://fpga.labsland.com/altera/digital-logic/lab-05/part-02/
Build a decimal counter for the three rightmost displays. One second after 099, the displays should read 100. At 999, all three return to zero. A single board clock drives three copies of the same decimal stage.
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/cascade_bcd.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
cascade_bcd. 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/cascade_bcd.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.
The starter includes a clock divider, one decimal stage and a display decoder. Complete the tens and hundreds enable connections. Use CLOCK_50 for every stage. Keep the hardware clock parameter at 50,000,000. Synthesize, upload, and read HEX2 through HEX0 from left to right.
- Get the starterDownload
cascade_bcd.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 Predict the enables in the worksheet below, then complete the design as its build steps describe. Open
cascade_bcd.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/cascade_bcd.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
Predict the enables
Make a table for 008, 009, 098, 099 and 999. For each value, decide which digits should change on the next one-second tick. Name the conditions that advance the tens and the hundreds. Distinguish a digit holding 9 between ticks from a carry that a higher digit should act on.
Build
- In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
- Create
cascade_bcd, 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.
The starter includes a clock divider, one decimal stage and a display decoder. Complete the tens and hundreds enable connections. Use CLOCK_50 for every stage. Keep the hardware clock parameter at 50,000,000. Synthesize, upload, and read HEX2 through HEX0 from left to right.
Simulate the carries
Extract the worksheet ZIP and run these commands from the folder containing activity.md.
The bench runs all 1,000 values and checks the wrap, both presets and reset priority. It gives the divider two clock cycles per tick in simulation. Keep the original divider setting for the physical board. Compare the expected and observed three-digit readings at the first mismatch. Which digit missed its carry? Repair only that stage and rerun. Where does the next mismatch occur? Fix the remaining enable, then check that the bench reaches PASS.
Verilog
iverilog -g2005 -s test_cascade_bcd -o bench starter/cascade_bcd.v simulation/test_cascade_bcd.v
vvp bench
SystemVerilog
iverilog -g2012 -s test_cascade_bcd -o bench starter/cascade_bcd.sv simulation/test_cascade_bcd.v
vvp bench
VHDL
nvc --std=2008 -a starter/cascade_bcd.vhd simulation/test_cascade_bcd.vhd
nvc --std=2008 -e test_cascade_bcd
nvc --std=2008 -r test_cascade_bcd
Test the boundaries
Press KEY0 with both switches down to clear the count. Release it and watch the units advance. Raise SW8 to load 098, then lower SW8 and record four successive readings. Repeat with SW9, which loads 998. The preset switches let you visit carry boundaries during one reservation. Keep the other preset switch down.
| Test | Prediction | First four readings | Time for three transitions |
|---|---|---|---|
| Release the 098 preset | |||
| Release the 998 preset |
While SW8 is up, hold KEY0 and read the displays. Release KEY0 while keeping SW8 up. Give the camera a few seconds to show the settled digits, then record the second reading. Which control takes priority? Explain why connecting the units carry output to a clock input would change the design. Finish with both preset switches down and press KEY0 once.
Source
Original LabsLand activity following FPGAcademy Digital Logic Lab 5, Part II. Verilog handout · VHDL handout · MIT
