Need ~100kHz ADC (total) from 3 sources, trying to get MCP3008 working with SPI

Hi, I was told to try posting this here...

I need to sample three audio signals, each roughly 34k samples/second, so I want to sample ADC at around 100kHz. I started by using the Due's built-in ADC, which seemed like it was fast enough, but I was getting bad results. From what I could tell, this was because of switching between analog inputs too quickly. I'm open to other solutions, but here's what I'm doing now:

Now I have a MCP3008 ADC chip and am trying to get it working with the Arduino SPI library. I got it working with this library GitHub - nodesign/MCP3008: MCP3008 - Analog to digital converter Arduino library which bit bangs it. I'm under the impression the SPI library would be faster, does this sound right? The issue I'm having is that SPI.transfer() is only returning 1's, not any useful results, and I cannot figure out why.

Here's a bit of my latest code from trying to debug this. I've tried using the Due's extended library, adding delays all over the place, setting the SPI clock as low as I can, etc., but none of it seems to be working. Every time I try all I get back is a lot of 1's and nothing else.

If anyone could help with this I would really appreciate it, I'm out of ideas on this. I'm also open to suggestions on better ways to get fast ADC from multiple (3) sources. Thanks!

Wiring:

Vdd -> 3.3V
Vref -> 3.3V
AGND -> GND
CLK -> 13
Dout -> 12
Din -> 11
CS -> 10
DGND -> GND

CH0 -> 1V (for testing, should return adc value of ~307)

#include <SPI.h>

#define CS_PIN 10
#define CLOCK_PIN 13
#define MOSI_PIN 11
#define MISO_PIN 12

void setup() {
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  Serial.begin(9600);
  Serial.println("BEGIN");
}

void loop() {
  digitalWrite(CS_PIN, LOW);
  int commandout = 0;
  commandout |= 0x18; //  # start bit + single-ended bit
  commandout <<= 3; //    # we only need to send 5 bits here
  byte result1 = SPI.transfer(commandout);
  byte result2 = SPI.transfer(0x00);
  byte result3 = SPI.transfer(0x00);
  Serial.println(commandout);
  Serial.println(result1, BIN);
  Serial.println(result2, BIN);
  Serial.println(result3, BIN);
  Serial.println("done");
  digitalWrite(CS_PIN, HIGH);
}

Just for testing I would add a delay in loop() because you may be spamming the poor ADC with commands every few mS or even uS.

commandout <<= 3; //    # we only need to send 5 bits here

The upper 5 bits of that command byte I assume? I've not looked at the data sheet for this chip.


Rob

limzz:
Hi, I was told to try posting this here...

I need to sample three audio signals, each roughly 34k samples/second, so I want to sample ADC at around 100kHz. I started by using the Due's built-in ADC, which seemed like it was fast enough, but I was getting bad results. From what I could tell, this was because of switching between analog inputs too quickly. I'm open to other solutions, but here's what I'm doing now:

Which version of the Arduino software did you use? There were known show-stopper
ADC bugs in some versions - have you tried v1.5.6 ?