A bit relevant data about the project
I'm working on a project that includes sampling a 10 MHz analogue signal at around 60 Msps on an ADS4222 (2 12 bit channels). The clock is generated using the ICE40UP5K's internal PLL (jitter doesn't matter that much for the chosen application) and an external TXCO. Data sampling on the FPGA is triggered using the ADS's output clock and stores data into a FIFO structure. All data readings following the write operation sequentially read the stored data. The SPI protocol is currently very simple to reduce the timing footprint. SPI write messages trigger the conversion, while SPI reads simply read the data one by one. First bit in the message specifies the operation.
This is the verilog source:
- core.v (connects all the components, instantiates the PLL core)
- ram.v (RAM and FIFO implementation)
- spi.v (async SPI core - counter is 5-bit)
The problem
When I sample the data, the FIFO counter counts fine (it stops sampling after the expected time), but no matter the source, whether it's a counter for debugging purposes or the actual ADC data, it doesn't appear to actually sample the correct data. Now if I set it to a constant, it seems to sample it into the FIFO just fine - when reading the data via SPI, I always get the same SPI bit stream as expected. This leads me to believe that there is something wrong with timing - whether it's on the read or write side of things since static data seems to work fine.
The 24 bit samples are interpreted as 2x12 signed integers. If I have it set up to read from a counter (should be sequential numbers) I get something like this:
If limited to 4 samples (read in pairs, so data appears to be changing mid readout?):
Short readout:
-1868,-1869,176,52,-1866,-1867,176,54 If I use larger sample buffers (let's say the full length of 4096) I get what appears to be random samples filled with a bunch of zeroes:
A longer readout:
What I confirmed is working
- The async SPI core is working: if I load registry data and read it on the connected MCU, I get correct readings.
- Parallel data lines are wired correctly: sampling the current reading in a registry at the time a new SPI message starts successfully sends a sample pair via SPI directly - when I sample a sine wave I get the corresponding bathtub histogram
- The ADS conversion done clock is wired correctly: If I time the "busy" line on an oscilloscope I get roughly the time of 4096 clock cycles
- The configuration works correctly when simulated in ModelSim, so I'm assuming it's something with timing (simulated with data depth of 4 measurements):
A simulated sampling operation:
A simulated readout operation via SPI:
The sample timing should also be correct, at least in theory, according to the TI ADS42xx family's datasheet (figure 7-1): 
- I'm not near the EBR ram max speed either as per the ICE40 family datasheet

I tried playing around with this structure a lot in the past few weeks and had no luck, so I'm wondering if anyone had similar issues. I'm new to FPGAs in general so I'm sure it could be that I missed something completely generic and stupid, so I decided to ask in this community if anyone is willing to share their experience.
Thank you in advance!

