Change an interrupt-driven counter’s speed
Online version: https://fpga.labsland.com/altera/computer-organization/lab-05/part-03/
Debugger setup
CPUlator simulatorRISC-V · DE1-SoC Nios V computer, simulated in your browser. No board or sign-in needed.
- Get the sourceDownload
interrupt_rate.s - Open the simulatorOpen CPUlator
Keep the foreground loop and timer handler from the quarter-second counter. Make the pushbutton interrupt change how fast the LEDs advance. KEY0 pauses or resumes, KEY1 doubles the rate, KEY2 halves it and KEY3 leaves it alone.
Compare the periods
Open interrupt_rate.s in CPUlator for RISC-V DE1-SoC. Find the two shifts in key_event. The starter can slow the counter down but pressing KEY1 has no effect on the period. Correct that branch. Leave the time base and the foreground code unchanged. Compile and load, then select Continue.
Open RISC-V Machine Timer and the red LEDs. Press and release one button per row. Read mtimecmp and time the LEDs over several changes. A shorter period gives more changes per second.
| Sequence from a fresh run | Compare value in ticks | What happened to the LEDs? |
|---|---|---|
| No button | ||
| KEY1 | ||
| KEY1 again | ||
| KEY1 a third time | ||
| KEY2 | ||
| KEY3 | ||
| KEY0, wait one second, then KEY0 |
Choose Compile and Load to restore the initial period in data memory, then press KEY2 three times and record the slowest compare value you can reach. Explain the two limits and why pausing the display count does not change the stored period.
Adapted from FPGAcademy Computer Organization, Lab 5, Part III. LabsLand wrote the assembly and activities. MIT notice
