Lab 7

Keep minutes, seconds and hundredths with timer interrupts

Debugger setup

CPUlator simulatorC · DE1-SoC Nios V computer, simulated in your browser. No board or sign-in needed.

  1. Get the sourceDownload main.c
  2. Open the simulatorOpen CPUlator

Turn the six rightmost displays into a clock that rolls over after an hour. The main loop displays one snapshot while a machine-timer handler advances the time every hundredth. The starter restarts too early.

In CPUlator select C in Language, open File → Open and choose main.c. Use Compile and Load (F5), then Continue (F3).

Read the running clock

Watch the six digits. Read two values at least a second apart and split each into minutes, seconds and hundredths. Find the compare interval in Machine Timer. Check that the interval agrees with the 100 MHz timer frequency.

Test a whole hour in four interrupts

In the source change INITIAL_HUNDREDTHS to 5998u. Recompile. In Disassembly, go to next_hundredth and set a breakpoint on its first instruction. Press Continue four times. Record a0 (current hundredths) and mcause on every stop. Repeat with 359998u after correcting the rollover limit.

Initial hundredths Four values of a0 Interrupt cause
5998
359998

Convert the final two values of each trace to clock readings. Explain why a breakpoint in the interrupt path advances once per tick even though main refreshes the display many times. Restore the initial count to zero.

Original LabsLand activity following FPGAcademy Computer Organization Lab 7, Part IV. FPGAcademy PDF · MIT

Run a signed maximum on a physical Nios V board