因此,我使用LTC 2366,3 MSPS模数转换器,并使用下面给出的代码,能够实现大约380ksps的采样率。
#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, "%d\n", (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完全相同的代码时,我仍然获得了大约380ksps的采样率。怎么会这样?首先,为什么3MSPS的ADC只给我380KSPS,而不是2MSPS?其次,当我将ADC更改为更快约70%的东西时,我得到了相同的采样率,为什么?这就是Pi的极限吗?有没有办法改善这一点,以获得至少1个MSPS?
谢谢
发布于 2018-05-10 04:45:36
我测试了一点Raspberry Pi SPI,发现spi有一些开销。在我的例子中,我尝试了pyspi,其中一个字节似乎至少需要15us,两个字之间需要75us (参见these captures)。这比你测量的要慢,所以对你来说很好!
增加SPI时钟会改变交换的长度,但不会改变开销。因此,关键时间不会改变,因为开销是限制因素。380ksps意味着2.6us的字节,这可能很接近你的开销?
提高模数转换器速度的更简单的方法是使用并行模数转换器而不是串行模数转换器-它有可能增加overall speed to 20Msps+。
https://stackoverflow.com/questions/49480893
复制相似问题