Hello everyone,
I have been working on this board for several months now, and regarding the FPGA its all ok! My issue now is with SAMD; I need to sample a signal (2khz) at 4kHz (250us). However when I tried to read an analog pin at this frequency I only get about 530us (1.9kHz).
I need to increase at least twice the sample rate I am getting now.
The Arduino SAMD21 core file "wiring.c" sets the sampling time control register (SAMPCTRL) to its maximum 63 (0x3F in hex). This adds 64 (SAMPCTRL + 1) half ADC clock cycles to your conversion. A conversion typically taking 426us at 12-bit resolution.
Provided source resistance seen by your ADC input isn't really high, the SAMPCTRL register can ususally safely be set to 0. However this register is write-protected, therefore it's necessary to first disable the ADC:
ADC->CTRLA.bit.ENABLE = 0; // Disable the ADC
while(ADC->STATUS.bit.SYNCBUSY); // Wait for synchronization
ADC->SAMPCTRL.reg = 0x00; // Reduce the sample time by (63 + 1) * (512 / 48MHz) / 2
ADC->CTRLA.bit.ENABLE = 1; // Enable the ADC
while(ADC->STATUS.bit.SYNCBUSY); // Wait for synchronization
This reduces your conversion time to around 91us for a default 512 ADC clock prescaler.