如何使用带有Raspberry Pi的ADC实现高采样速度



因此,我使用的是LTC 2366,3 MSPS ADC并使用以下代码,能够达到约380 ksps的采样率。

#include <stdio.h>
#include <time.h>
#include <bcm2835.h>
int main(int argc, char**argv) {
    FILE *f_0 = fopen("adc_test.dat", "w");
    clock_t start, end;
    double time_taken;
    if (!bcm2835_init()) {
        return 1;
    }
    bcm2835_spi_begin();
    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
    bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
    bcm2835_spi_setClockDivider(32);
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);
    int i;
    char buf_[0] = {0x01, (0x08|0)<<4, 0x00}; // really doesn't matter what this is
    char readBuf_0[2];
    start = clock();
    for (i=0; i<380000; i++) {
        bcm2835_spi_transfernb(buf_0, readBuf_0, 2);
        fprintf(f_0, "%dn", (readBuf_0[0]<<6) + (readBuf_0[1]>>2));
    }
    end = clock();
    time_taken = ((double)(end-start)/CLOCKS_PER_SEC);
    printf("%f", (double)(time_taken));
    printf(" seconds n");
    bcm2835_spi_end();
    bcm2835_close();
    return 0;
}

每次返回大约1秒钟。

当我与LTC 2315完全相同的代码使用时,我仍然得到大约380 ksps的采样率。怎么会?首先,为什么3个MSP ADC只给我380 ksps而不是2个MSP?其次,当我将ADC更改为快70%的速度时,我得到了相同的采样率,为什么?那是PI的极限吗?有什么方法可以改善至少1 MSP?

谢谢

我已经测试了一些Raspberry Pi Spi,并发现SPI有一些开销。就我而言,我尝试了Pyspi,其中一个字节似乎至少要走15us,而在两个单词之间进行了75US(请参阅这些捕获(。这比您的测量要慢,对您有好处!

增加SPI时钟会更改交换的长度,而不会更改开销。因此,关键时间不会改变,因为开销是限制因素。380ksps的意思是2.6U,字节可能很靠近您的开销?

提高ADC速度的更简单的方法是使用平行ADC而不是串行 - 它有可能将总体速度提高到20msps 。

最新更新