使用Arduino Due,很难通过外部12位ADC(LTC2365)实现1 Msps

时间:2017-11-23 21:14:01

标签: arduino

我有一个带SPI引脚的LTC2365 / 1 Msps 12位ADC。不知怎的,我用这个ADC只能达到200 Ksps,而不是使用Arduino Due接近1 Msps。我想知道是否有人可以帮我解决这个问题。我尝试了很多方法,但无法弄清楚。

ADC的数据表: http://cds.linear.com/docs/en/datasheet/23656fb.pdf

以下是我用于Arduino的代码:

#include <SPI.h>
const int spi_ss = 10;      // set SPI SS Pin
uint8_t byte_0, byte_1;    // First and second bytes read
uint16_t spi_bytes;       // final 12 bit shited value
long int starttime,endtime;
long int count=0;

void setup() {
  SerialUSB.begin(2000000);          // begin serial and set speed
  pinMode(spi_ss, OUTPUT);     // Set SPI slave select pin as output
  digitalWriteDirect(spi_ss, HIGH);  // Make sure spi_ss is held high
  SPI.begin();
  SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
  loop2();
  SPI.endTransaction();
}

void loop2() {
   starttime=millis();
   endtime=starttime;
   while((endtime-starttime)<=1000) {
      // write the LTC CS pin low to initiate ADC sample and data transmit
      digitalWriteDirect(spi_ss, LOW);
      byte_0 = spi_read(0x00); // read firt 8 bits
      byte_1 = spi_read(0x00); // read second 8 bits
      digitalWriteDirect(spi_ss, HIGH);
      // wite LTC CS pin high to stop LTC from transmitting zeros.
      spi_bytes = ( ( (byte_0 <<6) ) + (byte_1 >>2) );
      SerialUSB.println(spi_bytes);
      count=count+1;
      endtime=millis(); 
   }
   //samples per second
   SerialUSB.println(count);  
}

static inline uint8_t spi_read(uint8_t b) {
  return SPI.transfer(b);
}

inline void digitalWriteDirect(int pin, boolean val) {
  if(val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
  else g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;
}

0 个答案:

没有答案