Pause a C interrupt-driven LED counter
Online version: https://fpga.labsland.com/altera/computer-organization/lab-07/part-02/
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
A machine timer asks for a count every quarter second. A pushbutton interrupt toggles a run flag. The starter handles both interrupts, yet pressing a button leaves the LEDs counting.
In CPUlator select C in Language, open File → Open and choose main.c. Use Compile and Load (F5), then Continue (F3).
Separate counting from display
Trace count, running and period from the handler into main. Convert 25,000,000 ticks at 100 MHz to seconds. Repair the timer branch so ticks honor the run flag. Keep the timer armed even while the count is paused.
Test a pause that lasts several ticks
Read five consecutive LED words. Press and release KEY0, record the word, wait more than one second, and read it again. Release KEY3 and observe the next change. In Machine Timer inspect mtimecmp. Repeat with the unmodified starter if your readings match in both states.
| Event | LED word | Did the timer keep requesting updates? |
|---|---|---|
| Before KEY0 | ||
| Just after KEY0 | ||
| One second later | ||
| After KEY3 |
Explain why the timer interrupt can still fire while the visible count is held. Include one observed transition and the period calculation.
Original LabsLand activity following FPGAcademy Computer Organization Lab 7, Part II. FPGAcademy PDF · MIT
