The previous eleven episodes wired CVE2 to memory, Ethernet and a camera. This one turns it inward: let the core generate the signal, sample it, do the arithmetic, and report the answer over a single UART line. A DDS builds a 1 kHz sine in fabric, 1,024 samples are captured at 100 kHz, a 32-tap Q14 FIR and a 1,024-point block-floating-point FFT run on the samples, and the firmware recomputes the same maths on the same data as a cross-check. It is a closed loop inside the board — no signal generator, no scope, no monitor on the desk.
5728ca9d…>>14, agree point by point (maxdiff=0). For the FFT it covers two things only — shape (cosine similarity 0.9999 across 64 bins) and peak position (bin 10 on both sides). Absolute magnitude still carries a scaling factor (hardware / software ≈ 0.46–0.52), because the hardware path uses block-floating-point scaling with an approximate magnitude estimate while the firmware sums a fixed-point cosine table. No unified calibration was done, and that is written here instead of being hidden.The chain was checked in the order “register window alive → capture actually runs → FIR numbers right → spectrum lands where it must”. Every figure below comes from one power-on UART capture.
| Check | Requirement | Measured |
|---|---|---|
| 1 · Register window | read 0x4006_0000, expect a known ID | ID=4609 (0x1201) |
| 2 · DDS test tone | 1 kHz at 100 kHz sampling | fs=100000 Hz f0=1000 Hz; W0..W31 follow a 100-sample sine, peak 16,376 |
| 3 · Capture | 1,024 points, CAP_DONE raised | capture completes; the same samples feed both the hardware chain and the recompute |
| 4 · Hardware FIR | 32 taps, equal to software point by point | FIR lat=5 clk maxdiff=0 @0 · all 32 points equal |
| 5 · Hardware FFT | 1,024-point BFP, peak in the 1 kHz bin | hw_cycles=7342 exp=8; HWP peak bin=10 mag=7619072 (theory bin 10, theory amplitude 8.39 M) |
| 6 · Exceptions | no trap | TRAP=0 done |
The waveform peaks at 16,376 rather than the full 16,383, a 98 LSB (0.6%) deviation caused by the DDS keeping only 12 of its 32 phase bits. It is the phase accumulator's word length, not a sampling or FIR error.
The full 2,379 B log is in the file list (logs/ep12_serial_verified.log). Below, only the head, tail and a few of the 32 FIR rows survive.
EP12 digital scope / FIR+FFT bench
ID=4609
fs=100000 Hz f0=1000 Hz
FIR 0 0 0 0
FIR 1 0 0 0
FIR 2 1 1 0
...
FIR 15 -87 -87 0
FIR 16 124 124 0
...
FIR 30 12240 12240 0
FIR 31 12895 12895 0
FIR lat=5 clk maxdiff=0 @0
W 0 0
W 1 1008
...
W 25 16376
...
W 31 15208
FFT done, cycles=7353 hw_cycles=7342 exp=8
S k swmag hwmag
S 9 2879072 1431040
S 10 14933012 7619072
S 11 4832843 2470400
...
S 63 97766 50688
HWP peak bin=10 mag=7619072
TRAP=0 doneA FIR row is FIR index hardware software difference — the last column is zero for all 32 rows. W rows are captured samples; W 25 = 16376 is the peak and the waveform returns to the origin 100 samples later, matching 1 kHz. S rows are S bin software-magnitude hardware-magnitude, largest around bin 10.
The first stage on hardware was uglier: 21 bytes of garbage on the UART and a CPU stuck waiting for capture. Once those were fixed and the log became readable, the FIR columns stayed byte-for-byte identical across four different RTL builds, with maxdiff pinned at 28,037. Changing RTL without changing the output means the change never touched the path that produces the output.
The root cause was one write enable:
// wrong: fir_wr is 10 bits wide, so "fir_wr < 1024" is always true
wire fir_we = fir_v && (fir_wr < N);
// right: gate on a busy flag, stop after N points
wire fir_we = fir_v && fir_busy;fir_wr holds 0–1023, so fir_wr < 1024 never goes false. After capture finished the pointer kept walking, wrapped, and the buffer was overwritten round after round. The firmware was therefore not reading the first 32 transient outputs at all — it was reading one steady-state round from much later. That explains everything: why the numbers looked like a sine, why they were in a plausible range, and why changing the shift chain or the memory implementation changed nothing.
The expensive lesson: first ask whether the thing you edited sits on the data path, then argue about numeric precision. The first three edits (write port from fir_sum[35:4] to fir_out, signed shift, xpm to a plain array) were all correct, but the output was never being read, so none of them showed.
| Stage | Change | maxdiff | What it showed |
|---|---|---|---|
| start | write port on fir_sum[35:4], logical shift | 28,037 | wrong scale, values looked like a random sine |
| write enable | fir_busy gate, stop after 1,024 points | 1,071 | real first 32 points at last, but shifted by one sample |
| pipeline align | software index i-j → i-1-j | 16 | hardware carries one extra pipeline stage; confirmed by a Python offset sweep |
| truncation align | per-tap >>14 → full-precision sum, one shift | 0 | all 32 points equal |
cap_arm was level-sensitive (clearing the write pointer and busy flag inside else if (cap_arm)) while the firmware holds the ARM bit high, so the capture sat at its start state forever and the CPU spun on CAP_DONE. Replaced by a rising-edge pulse.initial loaded only the instruction RAM; the data RAM was filled with 32'h13. The linker script puts all string constants in .rodata inside that same RAM, so each puts_() emitted one 0x13 byte and only numbers survived. Fixed by loading the same hex into dmem as well.fir_sum[35:4], four bits further right than the Q14 convention.fir_sum >> 14 is a logical shift in SystemVerilog, so negatives jumped to the 225 range; changed to $signed(fir_sum) >>> 14. Confirmed first in an isolated xsim run of the FIR chain on a 100-point sine: Y 6 33554425 before, Y 6 -7 after.0x051EB852 is 0.02×232 while the comment said 1 kHz, so the FFT peak sat in bin 20. After 0x028F5C29 it moved to bin 10.>>10 instead of the Q14 >>14.xfft is configured for block floating point and the outputs are scaled down by 2exp. A new CSR (0x4006_0034, address nibble 4'hD) returns the latched exponent, the firmware prints exp= and multiplies back with <<bexp.y[n]=Σc[j]x[n-1-j]; the software index follows with i-1-j.phys_opt_design -aggressive_hold_fix after route_design brings it to +0.003 ns.At 50 MHz the FSDIV=499 divider produces the 100 kHz sampling tick. The DDS keeps a 32-bit phase accumulator and uses only the top 12 bits to index a sine table, which is where the 0.6% phase-truncation error comes from. Each captured sample goes two ways: into the 1,024-point capture buffer (read by software) and into the 32-stage FIR delay line.
The FIR uses the symmetric structure — xr[k]+xr[31-k] paired first to halve the multipliers, then 16 Q14 coefficients, a four-level adder tree and one final >>14 — and writes its own 1,024-point buffer. Latency is 5 clocks, and the firmware reads that value back from 0x4006_001C instead of hard-coding it.
For the spectrum the capture buffer feeds xfft (radix_2_burst_io, nonrealtime, natural-order output, block-floating-point scaling). When the core raises done, the firmware reads each magnitude and latches the exponent. 1,024 points take 7,342 clocks.
# build (Vivado 2025.2 on the build host)
cd /media/alinx/nvme4t/fpga-love/pi_ar035_f1_1_cve2_ep12
vivado -mode batch -source build_ep12.tcl -log build_ep12.log
# program
vivado -mode batch -source program_ep12.tcl
# firmware: main.c is packed into BRAM through $readmemh, so edit means rebuild
cd sw && make -s
# serial capture: start cat before programming, or the first screen is lost
stty -F /dev/ttyUSB1 115200 cs8 -cstopb -parenb raw -echo
nohup timeout 70 cat /dev/ttyUSB1 > /tmp/ep12.log 2>/dev/null < /dev/null &
vivado -mode batch -source program_ep12.tcl
sleep 6 && cat /tmp/ep12.logTwo pitfalls worth repeating: the port only works at 115200 (230400 and 57600 both return zero bytes), and do not finish with pkill -f "cat /dev/ttyUSB1" — it takes your own SSH session down with it. The firmware hex must be loaded into both imem and dmem; instruction memory alone makes every string read 0x13.
26 files, about 2.0 MB: the final bitstream, routed timing and utilisation reports, build / programming / serial logs (including the two intermediate captures that show maxdiff going 1,071 → 16 → 0), RTL, XDC, Tcl, firmware sources with ELF / HEX / disassembly, the three-panel measurement figure, structured metrics and the defect write-up.
Daily Briefing · Weekly Digest · Monthly Deep Dive