Lab 5

Count timer interrupts on the red LEDs

Debugger setup

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

  1. Get the sourceDownload interrupt_count.s
  2. Open the simulatorOpen CPUlator

Drive a binary counter from the machine timer. The foreground loop only displays a word from memory. In the background, one source of interrupts advances that word and another lets you stop or restart it.

Set up the sources

Open interrupt_count.s in CPUlator for RISC-V DE1-SoC. Locate setup_keys, setup_timer and the two comparisons with mcause. Calculate the compare value for a quarter of a second using a 100 MHz timer. Compile and load, step once, then continue. Time at least four LED changes. Read the ten LEDs as one binary word, with bit 0 on the right.

Test the run flag

Press and release button 0. What happens to the LEDs two seconds later? Find the instruction that should toggle the one-bit run flag and correct its immediate operand. Recompile and repeat. Try a different button to resume.

Observation LED word or measured interval
Five successive LED words
Time from the first to the fifth word
Two readings about one second apart while paused
First change after resuming

Explain why the timer still needs acknowledging while the LED word is held. Describe what would happen if the program waited for a button inside the timer handler.

Adapted from FPGAcademy Computer Organization, Lab 5, Part II. LabsLand wrote the assembly and activities. MIT notice

Run a signed maximum on a physical Nios V board