Time an hour with a polled machine timer
Online version: https://fpga.labsland.com/altera/computer-organization/lab-06/part-04/
Debugger setup
CPUlator simulatorC · DE1-SoC Nios V computer, simulated in your browser. No board or sign-in needed.
- Get the sourceDownload
main.c - Open the simulatorOpen CPUlator
Build a stopwatch in C for the simulated DE1-SoC Computer. Its six digits show minutes, seconds and hundredths. A button release pauses or resumes the stopwatch. You will look for two different boundaries: the end of one minute and the end of an hour.
Set the interval
The processor's machine timer advances at 100 MHz. Calculate the ticks in one hundredth of a second and the hundredths in one hour. In CPUlator choose C in Language, then File → Open and select main.c. Find TICKS_PER_UPDATE, INITIAL_HUNDREDTHS and HUNDREDTHS_PER_HOUR. Which constant would make the clock restart after every minute?
Run and pause
Choose Compile and Load (F5), then Continue (F3). Read the six rightmost digits in Seven-segment displays. Press and release KEY0 in Push buttons. Record two readings a second apart. Press and release KEY3 and collect a third reading after a second. Why does resuming ignore the time spent paused?
Catch both rollovers
Set INITIAL_HUNDREDTHS to 5998u and rebuild. In Disassembly, go to the function show and put a breakpoint on its first instruction. Continue four times. Each stop occurs before the display update. Read a0, the function argument, as an unsigned number. Convert each count into MM:SS.DD.
| Start count | Four arguments to show | Which digit pair changes? |
|---|---|---|
| 5998 | ||
| 359998 |
Correct the wrap constant and repeat both trials. The 5998 trial should cross a minute; the 359998 trial should cross an hour. Restore the initial count to zero before submitting. Include both traces and explain why continuously comparing the timer for exact equality could miss an update.
Original LabsLand activity following FPGAcademy Computer Organization Lab 6, Part IV. FPGAcademy PDF · MIT
