Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Are pin A16 and A17 suitable ADC with fft

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Location
    Utrecht
    Posts
    3

    Are pin A16 and A17 suitable ADC with fft

    Hi,

    At the moment I am trying to get an analog mic to connect to a Teensy 3.5. I'd like to use pin A16 or A17 because these are free on the PCB where the teensy is plugged in to.
    For the mic I use a MAX9812 amp in between which so most of the sound will be on a voltage level between 0 and 1.2v.

    The code I am using is working an a Teensy 3.2 on pin A3 but also not in pin A17.

    So the main question is, is it possible to attach a mic to A16 or A17 to perform fft?

    This is the code I'm using:

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    
    #define MIC_ANALOG A17
    
    #define MIC_GAIN  10  // multiplier for the specific mic
    // GUItool: begin automatically generated code
    
    // Actions
    AudioAnalyzePeak         peak1;          //xy=495,162
    AudioAnalyzeFFT256       fft256_1;       //xy=496,230
    AudioAnalyzeRMS          rms1;           //xy=505,109
    
    // Analog mic
    AudioInputAnalog         adc1(MIC_ANALOG);       //default for adc1 is A2       3.3v
    AudioConnection          patchCord1(adc1, fft256_1);
    AudioConnection          patchCord2(adc1, rms1);
    AudioConnection          patchCord3(adc1, peak1);
    
    // An array to hold the 16 frequency bands
    long output_interval = 2000;
    float fft_level[16];
    int loopcounter =0;
    float rms =0;
    float peak = 0;
    long mill_counter;
    
    // frequency bin spreading
    int fft_bin[17] = {2,3,4,6,8,10,13,16,20,24,29,34,40,47,54,62,70};
    
    const String sensDivider = ", ";
    
    
    
    
    
    //*********************************************************************************** SETUP
    void setup()
    {
    
      // Audio connections require memory to work.
      AudioMemory(12);
    
      // Configure the window algorithm to use
      fft256_1.windowFunction(AudioWindowHanning256);
      fft256_1.averageTogether(255);
    }
    
    //*********************************************************************************** FFT256
    
    void read_fft256()
    {
      if (fft256_1.available())
      {
        // each time new FFT data is available, fft_bin it into 16 channels
        // Note- response doesn't seem flat so each is normalized <experimenting!
        // Note- these calculations go very fast!!
    
        // Band are 172Hz wide
    
        fft_level[0] +=  fft256_1.read(fft_bin[0],fft_bin[1]-1) * 1 * MIC_GAIN;
        fft_level[1] +=  fft256_1.read(fft_bin[1],fft_bin[2]-1) * 1 * MIC_GAIN;
        fft_level[2] +=  fft256_1.read(fft_bin[2],fft_bin[3]-1) * 1 * MIC_GAIN;
        fft_level[3] +=  fft256_1.read(fft_bin[3],fft_bin[4]-1) * 1 * MIC_GAIN;
        fft_level[4] +=  fft256_1.read(fft_bin[4],fft_bin[5]-1) * 1 * MIC_GAIN;
        fft_level[5] +=  fft256_1.read(fft_bin[5],fft_bin[6]-1) * 1 * MIC_GAIN;
        fft_level[6] +=  fft256_1.read(fft_bin[6],fft_bin[7]-1) * 1 * MIC_GAIN;
        fft_level[7] +=  fft256_1.read(fft_bin[7],fft_bin[8]-1) * 1 * MIC_GAIN;
        fft_level[8] +=  fft256_1.read(fft_bin[8],fft_bin[9]-1) * 1 * MIC_GAIN;
        fft_level[9] +=  fft256_1.read(fft_bin[9],fft_bin[10]-1) * 1 * MIC_GAIN;
        fft_level[10] += fft256_1.read(fft_bin[10],fft_bin[11]-1) * 1 * MIC_GAIN;
        fft_level[11] += fft256_1.read(fft_bin[11],fft_bin[12]-1) * 1 * MIC_GAIN;
        fft_level[12] += fft256_1.read(fft_bin[12],fft_bin[13]-1) * 1 * MIC_GAIN;
        fft_level[13] += fft256_1.read(fft_bin[13],fft_bin[14]-1) * 1 * MIC_GAIN;
        fft_level[14] += fft256_1.read(fft_bin[14],fft_bin[15]-1) * 1 * MIC_GAIN;
        fft_level[15] += fft256_1.read(fft_bin[15],fft_bin[16]-1) * 1 * MIC_GAIN;
        loopcounter += 1;
      }
      // else
      // {
      //   Serial.println("FFT not available");
      // }
    }
    
    //*********************************************************************************** Counter
    
    bool output_audio()
    {
      if (millis() > mill_counter + output_interval)
      {
        Serial.print("fft_0=");  Serial.print(fft_level[0]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_1=");     Serial.print(fft_level[1]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_2=");     Serial.print(fft_level[2]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_3=");     Serial.print(fft_level[3]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_4=");     Serial.print(fft_level[4]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_5=");     Serial.print(fft_level[5]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_6=");     Serial.print(fft_level[6]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_7=");     Serial.print(fft_level[7]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_8=");     Serial.print(fft_level[8]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_9=");     Serial.print(fft_level[9]/loopcounter);     Serial.print(sensDivider);
        Serial.print("fft_10=");    Serial.print(fft_level[10]/loopcounter);    Serial.print(sensDivider);
        Serial.print("fft_11=");    Serial.print(fft_level[11]/loopcounter);    Serial.print(sensDivider);
        Serial.print("fft_12=");    Serial.print(fft_level[12]/loopcounter);    Serial.print(sensDivider);
        Serial.print("fft_13=");    Serial.print(fft_level[13]/loopcounter);    Serial.print(sensDivider);
        Serial.print("fft_14=");    Serial.print(fft_level[14]/loopcounter);    Serial.print(sensDivider);
        Serial.print("fft_15=");    Serial.print(fft_level[15]/loopcounter);    Serial.print(sensDivider);
        Serial.print("RMS=");       Serial.print(rms/loopcounter);  Serial.print(sensDivider);
        Serial.print("Peak=");      Serial.print (peak1.readPeakToPeak()); Serial.print(sensDivider);
        Serial.print("Loopcounter=");Serial.println(loopcounter);
    
        for (size_t i = 0; i < 16; i++)
          {
              fft_level[i]=0;
          }
    
        mill_counter=millis();
        loopcounter=0;
        rms =0;
        return true;
      }
    }
    
    //*********************************************************************************** RMS
    
    void read_rms()
    {
      if (rms1.available())
      {
        rms += rms1.read();
      }
    }
    
    //*********************************************************************************** LOOP
    void loop()
    {
    read_fft256();
    read_rms();
    output_audio();
    }
    Who can help me figuring out if this is possible or what I am doing wrong

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,083
    A little above my pay grade, but audio lib wants to have an ADC pin on ADC0 and the other on ADC1 (A2 and A3 can satisfy that, but i don't think A16 and A17 are on distinct ADC controllers) See https://forum.pjrc.com/threads/25532...for-Teensy-3-1 for ADC pin mappings to ADC controller, also i assume T3.5 reference manual also shows ADC pin mappings.

    https://github.com/PaulStoffregen/Au...input_adcs.cpp

  3. #3
    Junior Member
    Join Date
    Jun 2019
    Location
    Utrecht
    Posts
    3
    Thanks for the explanation!
    When I read the tread you talk about (https://forum.pjrc.com/threads/25532...for-Teensy-3-1) I read the I I can use any Analog pin with ADC. On the pin I'd like to use A17 I can only use ADC1 which I use in the code.

    Is there something I do miss?

  4. #4
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,083
    My first reply was faulty, I thought you were trying to use AudioInputAnalogStereo() with two pins -- which required one pin on ADC0 and the other on ADC1. Your question was about just one pin AudioInputAnalog(). If you look at the lib's input_adc.cpp, you will see that it is hardwired to use only ADC0, so neither A16 nor A17 will work. From the T3.5 images at https://forum.pjrc.com/threads/25532...for-Teensy-3-1, you can see that ADC0 pins include A0-A11, A14, A15, and A21.

    Attachment 11814
    Last edited by manitou; 07-09-2019 at 02:01 PM.

  5. #5
    Junior Member
    Join Date
    Jun 2019
    Location
    Utrecht
    Posts
    3
    Ah thats the cause! So only ADC1 can do AudioInputAnalog.
    Thanks for the quick and clear explenation!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •