Lab 9

C · Local Linux terminal

The display says 100 Hz. What does D0 say?

Your computer

Embedded Systems · Linux interrupts. You are building a test signal for an oscilloscope. Four switches select its frequency, ten LEDs mirror the switches, and the display shows the requested frequency in hertz. The display reads 100, but the instrument sees a different frequency. Use the edges to find the fault.

Measure before you edit

Unzip the activity and work from its top-level directory. You need a C compiler. The register bench advances a modeled 100 MHz timer directly to its next interrupt. It prints the level of JP1 pin D0 after each interrupt. The first row is the initial level.

cc -std=c11 -O2 -Wall -Wextra -Werror starter/generator.c resources/bench.c -o wave
./wave 0x240 8

With SW9–SW6 set to 1001, which frequency do you request? Find the first two rising edges in the output. Subtract their timestamps. Each tick lasts 10 ns. Calculate the frequency in hertz and compare it with the requested value.

Two modeled D0 signals share a 0 to 40 ms axis. Trace A has two cycles and trace B has four.

These are register-bench traces for the same switch setting. Which trace matches your program? Mark a half-period and a full period on that trace. Explain why counting every change as one cycle would hide the fault.

Change the timer reload

Open starter/generator.c. Follow one timeout through generator_interrupt. Find the instruction that clears the timeout flag and the write that changes D0. How many times must this handler run before the output has made a complete cycle?

Edit period_register. If an interval takes N input clocks, the reload register stores N − 1. Round the interval to the nearest whole clock. Rebuild and complete the table from your CSV output. One register tick is 0.00000001 s.

Switch word Requested Hz First two rising timestamps Measured Hz after repair LEDR word
0x000 10
0x240 100
0x26d 100
0x3c0 160

Compare the middle two rows. Which outputs change when you flip switches below SW6? The HEX column packs four displays into four bytes, with HEX0 at the right. It should stay the same for those two rows.

Put the same interrupt handler in Linux

For this section use a disposable Linux 6.18 VM with a compiler, matching kernel headers, and permission to load local modules. The downloads include a platform driver and a register fixture. The fixture raises interrupts through the Linux IRQ subsystem while the timer and GPIO registers live in RAM. The terminal measurements above are in modeled FPGA time.

cp starter/generator.c resources/selected.c
make -C "/lib/modules/$(uname -r)/build" M="$PWD/resources" COURSE_BENCH=1 modules
sudo insmod resources/course_wave.ko
sudo insmod resources/irq_fixture.ko intervals_per_cycle=2 original_d0=1
sudo rmmod irq_fixture
sudo rmmod course_wave
sudo dmesg | grep 'course-wave fixture' | tail -1

With the repair, expect edges=112 result=0. The test changes the switch word while the module is running, dispatches an interrupt with no timeout pending and checks the outputs again after the device detaches. Find the part of the driver that stops an interrupt from writing to a detached device. If fixture insertion fails, read its kernel log and unload course_wave before rebuilding. A VM that restricts unsigned modules can still run the terminal bench.

Submit your timer expression, the four measured rows and one observation that would distinguish a bad display decoder from a bad timer. A physical frequency measurement would require a scope on JP1 D0 and a common ground. The standard remote FPGA upload session gives you a different FPGA image and no Linux module shell.

FPGAcademy exercise · Exercise notice · LabsLand source license