Fastest way to read 12 analog channels

Status
Not open for further replies.

memaroo

Member
Hi

I love my Teensy 3.6 I can't wait for Teensy 4. :)

I'm trying to read a lot of analog channels. 12 for now, but maybe more. Most examples use the ADC library and continuous mode or DRM to get fast analog speeds. But they never use more than 4 channels. I know the hardware is sort of configured for 4 simultaneous reads, but what if we need more?

What's the fastest way to read 12 channels?

Right now i'm using the code below. It can read about 12x channels at ~10k samples a second. If I reduce the resolution to 8bits, then it goes to ~15k samples a second.

This is actually an ok sampling speed for my project, but when I add the rest of my project code then the total performance is too slow. If there is a way to read all 12 channels through some kind of interrupt or hardware function that would be best. I could easily live with 12x 1k samples per second if I had the majority of the time back on the main thread.

Code:
void setup() {
  Serial.begin(115200);
  Serial.println("started");
  
  for (int i=0; i < 12; ++i)
    analogRead(0);
    
  analogReadResolution(12);
}


long fpsTime = 0;
long fpsCounter = 0;
const unsigned long cUS = 1000000;

void loop() {
  unsigned long currentTime = micros();
  ++fpsCounter;

  if (currentTime - fpsTime > cUS)
  {
    Serial.println(fpsCounter);
    fpsCounter = 0;
    fpsTime = currentTime;
  }

  float analogSignals[12];
  for (int i = 0; i < 12; ++i)
    analogSignals[i] = analogRead(i);
}

Options:
CPU Speed: 180Mhz
Optimization: Fastest + Pure Code + LTO
Arduino 1.8.8
Teensyduino 1.45
 
Status
Not open for further replies.
Back
Top