Lab 5

Build a clock that rolls from 59:59.99 to zero

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

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

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.

test_clock.v

test_clock.vhd

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

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

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