Build a clock that rolls from 59:59.99 to zero
Online version: https://fpga.labsland.com/altera/digital-logic/lab-05/part-03/
Make six displays show minutes, seconds and hundredths of a second. Trace which digits change at 12:39.99 and at 59:59.99. Why do the two tens digits for minutes and seconds have a different last state from the other digits?
The starter lets the seconds count through 60. Run the starter in the simulator, then find the terminal count for the tens of seconds and correct the carry into minutes. Keep TICKS at 500,000 for the 50 MHz board clock. Calculate how many input edges occur in one hundredth of a second.
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/hundredth_clock.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
hundredth_clock. 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/hundredth_clock.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
hundredth_clock.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 Simulate the carries in the worksheet below, then complete the design as its build steps describe. Open
hundredth_clock.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/hundredth_clock.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
Simulate the carries
Extract the worksheet ZIP and run these commands from the folder containing activity.md.
The testbench models four input edges per hundredth to make the experiment quick. Run it on the starter, record the first failing rollover and repeat after your correction. The test tries an invalid tens digit and an invalid units digit separately. It checks both sides of 59:59.99, another 6,205 time steps, and the pause and restart controls on KEY0 and SW8.
Verilog
iverilog -g2005 -s test_clock -o bench starter/hundredth_clock.v simulation/test_clock.v
vvp bench
SystemVerilog
iverilog -g2012 -s test_clock -o bench starter/hundredth_clock.sv simulation/test_clock.v
vvp bench
VHDL
nvc --std=2008 -a starter/hundredth_clock.vhd simulation/test_clock.vhd
nvc --std=2008 -e test_clock
nvc --std=2008 -r test_clock
Build
- In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
- Create
hundredth_clock, 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.
Set and read the clock
On the programmed board, read HEX5…0 as three pairs, MM SS hh. Enter the minutes as two binary-coded decimal digits. SW7…4 set the tens and SW3…0 set the units. Press KEY1 to load them. With SW9 down this changes only the minutes. Hold KEY0 to pause and release it to continue.
SW8 lets you leave the clock paused while changing other controls. SW9 helps you reach the final hundredths in one reservation. When SW9 is up, a valid KEY1 load also sets seconds and hundredths to 59.98.
| Test | Controls | Camera reading |
|---|---|---|
| Start near the boundary | Raise SW8 and SW9, set the minute switches to 0101 1001, then press KEY1 | |
| Change minutes only | Leave SW8 up, lower SW9, set 0100 0010, press KEY1 | |
| Test the tens digit | Enter 0110 0010 (62) and press KEY1 | |
| Test the units digit | Enter 0100 1010 (4 and hexadecimal A) and press KEY1 | |
| Cross the boundary | Repeat the first row, lower SW9, then lower SW8 | |
| Pause and resume | Hold KEY0 for two seconds, record two readings, release and read again | |
| Pause with SW8 | Raise SW8. Read all six digits twice, two seconds apart. Lower SW8 and check that time advances. |
Which earlier reading should both invalid presets preserve? Explain what each one tests. Record the last state in the simulator and your first stable camera reading after the rollover. The hundredths can change between camera frames. Explain how your observations establish rollover and pause. Leave both SW8 and SW9 down when finished.
Source
Original LabsLand activity following FPGAcademy Digital Logic Lab 5, Part III. Verilog handout · VHDL handout · MIT
